DIT411/TIN175, Artificial Intelligence
Peter Ljunglöf
26 January, 2018
Natural language
Formal language
print(1 + 2)
✅print(+ 1 2.
❌Some examples of NLP tasks:
Sentiment analysis
Named entity recognition
http://www.europeana-newspapers.eu/named-entity-recognition-for-digitised-newspapers
Rules vs Statistics
Does anyone use rule-based systems today?
Words have different lexical categories:
We can combine them into phrasal categories:
A grammar is a set of rules that describe which combinations are possible
A Context-Free Grammar is a 4-tuple \(G = (V, \Sigma, R, S)\) where:
Common syntactic sugar:
\(X \rightarrow \alpha \;|\; \beta \;|\; \gamma\) is the same as \(X \rightarrow \alpha\), \(X \rightarrow \beta\), \(X \rightarrow \gamma\)
\(X \rightarrow \alpha? \; \beta \; \gamma?\) is the same as \(X \rightarrow \alpha \beta \gamma \;|\; \beta \gamma \;|\; \alpha \beta \;|\; \beta\)
A first attempt at a context-free grammar for Shrdlite:
This example grammar overgenerates:
CFG solution to overgeneration: add more rules
This is how we do it in Shrdlite.
The CFG solution is not feasible for, e.g., German:
German has 2 × 3 × 4 = 24 combinations of Number, Gender and Case.
Definite-Clause Grammars use attributes and unification:
Problem: Given a grammar, find a derivation from S for an input string
Function from string to a list of parse results:
parse(g : Grammar, s : String) : Result[]
Algorithms:
The Nearley CFG formalism lets you specify how the parse results should look like:
“put a green ball beside every large box”
\(\Longrightarrow\)
MoveCommand(
Entity(“any”, SimpleObject(“ball”, null, “green”)),
Location(“beside”,
Entity(“all”, SimpleObject(“box”, “large”, null))))
Most of the sentences we hear seem unambiguous. But almost every utterance contains some kinds of ambiguity. We are just very good at disambiguating!
Different levels of ambiguity:
So far, I’ve talked about grammars and parse results
The next step is semantics (= interpretation)
Shrdlite semantics is propositional logic:
a logical description of how we want the final state to look like
WhiteBall
, BlackBall
, …holding(x)
, inside(x,y)
, leftof(x,y)
, …P ∨ (Q ∧ R)
This works because the world is finite!
Is this ambiguous? “put the white ball in the red box”
How about this? “put the ball in the red box”
This is how Shrdlite goes from text input to a final plan:
text input → (many) parse results
parse result + world → (many) goals
many goals → one goal
)goal → plan
many plans → one plan
)ShrdliteResult
containsinput
string and a parse
resultinterpretation
and plan
are dummy valuesInterpreter
methods should call each otherDNF = Disjunctive Normal Form = a disjunction of conjunctions of literals
(normal form = all logical formulae can be converted into this form)
Example: the formula (p(x) ∧ q) ∨ (¬r(y,z))
is created by:
The semantics of an object description is a collection of
the objects that match the description:
["RedBox", "YellowBox"]
The semantics of an Entity or a Location is just a wrapper
around the semantics of its children:
{relation: "inside", {quantifier: "all", object: ["RedBox", "YellowBox"]}}
DNF inherently captures ambiguity
inside(WhiteBall,RedBox) ∨ inside(WhiteBall,YellowBox) ∨ inside(BlackBall,RedBox) ∨ inside(BlackBall,YellowBox) ∨ inside(BlackBall,BlueBox)
But impossible interperetations should be removed
inside(WhiteBall,BlueBox)
,“put the white ball in a box on the floor”
inside(WhiteBall,YellowBox)
inside(WhiteBall, YellowBox)
The yellow box is already on the floor: 17 actions to complete
inside(WhiteBall, RedBox) ∧ on(RedBox, floor)
The red box can be placed on the floor first: 10 actions to complete
“put the white ball in a box on the floor”
So, what should the final interpretation be?
inside(WhiteBall, YellowBox)
inside(WhiteBall, YellowBox) ∨ (inside(WhiteBall, RedBox) ∧ on(RedBox, floor))
Which object (i.e., which ball) should be placed
where (i.e., beside or in which box, or beside
which table)?
I.e., what should the goal be for each of
the syntactic analyses?
These are the physical laws that the interpreter and planner must check for:
Each test case contains a list of interpretations, each interpretation is a string
(a compact representation of a disjunction of conjunctions)
world: "small",
utterance: "take a blue object"
interpretations: ["holding(BlueTable) | holding(BlueBox)"]
world: "small"
utterance: "put a black ball in a box on the floor"
interpretations: ["inside(BlackBall, YellowBox)",
"ontop(BlackBall, floor)"]
world: "small"
utterance: "put all balls on the floor"
interpretations: ["ontop(WhiteBall, floor) & ontop(BlackBall, floor)"]
world: "small"
utterance: "put a ball on a table"
interpretations: []
world: "small"
utterance: "put a ball in a box on the floor"
interpretations: ["COME-UP-WITH-YOUR-OWN-INTERPRETATION"]