Russell and Norvig, Chapter 22: Agents That Communicate 22.1 Communication as Action - speech acts (utterances), not necessarily auditory - inform "There is a breeze in location 2,3." - query "Is there a pit in location 2,4?" - answer "I do not know if there is a pit in location 2,4." - request or command "I suggest you go to location 2,4." - promise or offer "I will go to location 2,4." - acknowledge "Okay" - share "Breezes make me scared." - agent must know - when to produce a speech act - which speech act to produce - what an external speech act means (syntax and semantics) - why that external speech act was produced (models and beliefs) - language - formal language (e.g., Prolog) - natural language (e.g., English) - strings ("the wumpus is dead") are made up of terminal symbols (the, wumpus, is, dead) - phrase structure: strings are composed of phrases - noun phrase, verb phrase, sentence - i.e., nonterminal symbols - rewrite rules: S --> NP VP - communication: speaker S wants to convey proposition P to hearer H using words W - [Fig22.1, p657] - speaker - intention: S wants H to believe P - generation: S chooses words W - synthesis: S utters words W - hearer - perception: H perceives W' - analysis: H infers W' has meanings P1,...,Pn - disambiguation: H infers S intended to convey Pi - incorporation: H decides to believe Pi (or not) 22.2 Types of Communicating Agents - telepathic agents [Fig22.2, p660] - agents share same internal representation - any agent can use: tell(KB_A,P), ask(KB_A,Q) - where A is any agent - reconciling different symbols used by different agents - reconciling different knowledge bases when bandwidth is limited - communicating agents [Fig22.3, p662] - different internal representations - common external communication language - communication is an action - e.g., wumpus world slave agent [Fig22.4, p663] - accepts commands and produces descriptions 22.3 A Formal Grammar for a Subset of English - formal language does not handle all issues in natural language - e.g., changes in a language over time and location - but, formal languages is a good place to start - language E0 (subset of English) - lexicon (words) [Fig22.5, p665] - open classes: nouns, verbs, adjectives, adverbs - closed classes: pronoun, article, preposition, conjunctions - grammar [Fig22.6, p665] 22.4 Syntactic Analysis (Parsing) - simple bottom-up parser [Fig22.7, p666] - example trace [Fig22.8, p666] 22.5 Definite Clause Grammar (DCG) - so far, using Backus-Naur Form (BNF) - rewrite rules of the form: NonTerm -> {NonTerm|Term}* - context-free (no a^n b^n c^n) - nothing about semantics (meaning) - logic grammar - S -> NP VP becomes NP(s1) & NP(s2) => S(append(s1,s2)) - Noun -> stench | ... becomes (s="stench" V ...) => Noun(s) - definite clause grammar (DCG) - logic grammar restricted to Horn clauses - BNF -> DCG - X -> Y Z ... becomes Y(s1) & Z(s2) & ... => X(Append(s1,s2,...)) - X -> word becomes X(["word"]) - X -> Y | Z | ... becomes Y'(s) V Z'(s) V ... => X(s) - where Y' is the logic translation of Y - extended BNF - nonterminals can be augmented with extra arguments - NP(sem) becomes NP(sem,s) - variables can appear on the right-hand side (antecedents) - variables represent a single symbol in the input string - e.g., Double -> w w becomes (s1 = [w] & s2 = [w]) => Double(Append(s1,s2)) - arbitrary logical tests can appear on the right-hand side - enclosed in curly braces - example from arithmetic Digit(sem) -> (s=[sem]) & sem>=0 & sem=<9 sem {0 <= sem <= 9} => Digit(sem,s) Number(sem) -> Digit(sem) Digit(sem,s) => Number(sem,s) Number(sem) -> Number(sem1) Digit(sem2) Number(sem1,s1) & Digit(sem2,s2) {sem = 10 * sem1 + sem2} & sem is 10 * sem1 + sem2 => Number(sem,Append(s1,s2)) 22.6 Augmenting a Grammar - E0 can generate grammatically incorrect sentences - e.g., "Me smell a wumpus" - need a subjective pronoun (like "I"), not objective ("me") - could replace NP rule with NP_subj and NP_obj [Fig22.9, p669] - but number of rules grows as we duplicate rules - e.g., subject-verb agreement would result in 4 NP rules - use augmentations (grammar E1) [Fig22.10, p670] - NP(case) -> Pronoun(case) | ... Pronoun(Subjective) -> I | ... Pronoun(Objective) -> me | ... - subject-verb agreement can also be handled this way (Ch23) - verb subcategorization - E1 allows "give me the gold", but also "go me the gold" - need to specify what categories can follow a verb - verb subcategorization list of complements - e.g., "give" followed by [NP,NP] or [NP,PP] "go" followed by [PP] - can be enforced by augmenting grammar - VP(subcat) -> VP([NP|subcat]) NP(Objective) | VP([Adjective|subcat]) Adjective | VP([PP|subcat]) PP | Verb(subcat) - S -> NP(Subjective) VP([]) - Verb([NP,NP]) -> give | ... - example parse tree in [Fig22.12, p672] - generation from augmented grammars - depends on number of values augmentations can take on - can be infinite (e.g., a^n b^n c^n) 22.7 Semantic Interpretation - compositional semantics - meaning of phrase determined only by meaning of its subphrases - attaching logical (lambda) expression to a verb - e.g., Verb(lambda(x) lambda(y) Loves(x,y)) -> loves - see [Fig22.15-16, p675] - intermediate (quasi-logical) form - compositional form of logic - avoids problems of sharing arguments across phrases - e.g., "the wumpus is dead" - logic: exists(w) wumpus(w) & ... AND dead(...) - quasi-logic: dead(exists(w) wumpus(w)) - add quantified terms - e.g., exists(w) wumpus(w) is a qualified term above - constructing grammar semantics [Fig22.17, p678] - (1) Decide on logical or quasi-logical forms to generate. - sample sentences and their logical forms - (2) Study one-word modifications (e.g., "every" to "a") - (3) Write down logical types of each category (e.g., noun, verb, ...) - (4) Study one-phrase modifications - e.g., "ate the agent" to "shot the wumpus" - (5) Attach semantic augmentations to grammar rules - simple: NP(sem) -> Pronoun(sem) - function application: S(rel(obj)) -> NP(obj) VP(rel) - concatenation: NP([sem1,sem2]) -> Digit(sem1) Digit(sem2) - complex: VP(L(x) rel1(x) & rel2(EventVar(rel1))) -> VP(rel1) Adverb(rel2) - example parse [Fig22.18, p679] - grammar E2 [Fig22.19, p679] - converting quasi-logic to logic - handle quantified terms Q(x) P(x), Q = exists or forall - for quantified term Q(x) P(x) in quasi-logic form QLF - replace Q(x) P(x) with x - replace QLF with Q(x) P(x) op QLF - op is => when Q is forall - op is & when Q is exists - e.g., QLF dead(exists(w) wumpus(w)) logic: exists(w) wumpus(w) & dead(w) - ambiguity when more than one quantified term - extract left to right usually works - pragmatic interpretation - indexicals: e.g., "I" in "I saw the wumpus" - anaphora: e.g., "it" in "the wumpus is in 3 3" "it is dead" - resolved by disambiguation 22.8 Ambiguity and Disambiguation - types of ambiguity - lexical ambiguity - words with more than one meaning or category - syntactic ambiguity leads to semantic ambiguity - "I smelled the wumpus in 2,2." - referential ambiguity: finding pronoun referents - pragmatic ambiguity - speaker and hearer disagree on context - local ambiguity - local meaning depends on external context - disambiguation - derive possible interpretations as hypotheses - use models and uncertainty reasoning to choose - world model: facts and their probabilities - mental model: other agents and their beliefs - language model: P(string | fact to be communicated) - acoustic model: P(sounds | string to be uttered) - probabilistic context-free grammar (PCFG) - each rule has a probability - probabilities on all rules for one NonTerm sum to 1 - context-free - P(pit) independent of its context "walk into the pit" 22.9 A Communicating Agent - wumpus world slave agent [Fig22.4, p663] - grammar E3 = E2 + commands + acknowledgements - commands (e.g., "shoot north") - implied noun object "Hearer" - acknowledgements (e.g., "ok") - command grammar rules - S(Command(rel(Hearer)) -> VP(rel) S(Statement(rel(obj)) -> NP(obj) VP(rel) - e.g., "shoot north" becomes Command(shoot(Hearer,north)) - acknowledgement grammar rules - S(Acknowledge(sem)) -> Ack(sem) Ack(True) -> "yes" Ack(True) -> "ok" Ack(False) -> "no"