CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available...
-
Upload
hannah-hubbard -
Category
Documents
-
view
212 -
download
0
Transcript of CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available...
![Page 1: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/1.jpg)
1 CSE573 Autumn 1997
03/06/98 Natural Language Processing
• Administrative
– Example code available in code\ps4\sample directory
– Last topic: Decision Tree Learning• Reading: 5.1, 5.4
• Last time– basic parser operation (connection between input stream, lexicon, grammar)
– interpreting parser output
• This time– finish the grammar
– semantic interpretation
![Page 2: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/2.jpg)
2 CSE573 Autumn 1997
The Grammar So Far
(S (TYPE LIFT)) -> (VP (TYPE LIFT)) (OBJ ...)(S (TYPE DROP)) -> (VP (TYPE DROP)) (OBJ ...)(S (TYPE MOVE)) -> (VP (TYPE MOVE)) (DESTINATION ...)
(OBJ (SHAPE (? S)) (COLOR (? C)) (REF (? REF)))) -> (DET (REF (? REF)) (VOWEL (? V))) (COLOR (ROOT (? C)) (VOWEL (? V))) (SHAPE (ROOT (? S))) (LOCATION (TYPE (? LOC-TYPE)))
(OBJ (SHAPE (? S)) (COLOR NIL) (REF (? REF)))) -> (DET (REF (? REF)) (VOWEL (? V))) (SHAPE (ROOT (? S))) (LOCATION (TYPE (? LOC-TYPE)))
((LOCATION (TYPE ABSOLUTE) (INDEX (? I)) -> (PREP (ROOT AT)) (POSITION (INDEX (? I))))((LOCATION (TYPE RELATIVE)) -> (PROXIMITY))((LOCATION (TYPE EMPTY)) ->)
![Page 3: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/3.jpg)
3 CSE573 Autumn 1997
A Quick Cut at PROXIMITY and DESTINATION
![Page 4: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/4.jpg)
4 CSE573 Autumn 1997
“Semantic Interpretation” (interpret.lsp)
• The basic idea: extract the command name and object attributes from the parse tree to facilitate precondition verification and action execution
(defstruct command action object destination)
(defstruct location (abs-position NIL) (rel-direction NIL) (rel-object NIL))
(defstruct object ref color shape place)
Parse the SENTENCE subtree
Parse the LOCATION subtree
Parse the OBJECT subtree
![Page 5: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/5.jpg)
5 CSE573 Autumn 1997
Extraction Primitives
(defun extract-feature (tree feature) (second (assoc feature (cdr tree))))
(defun extract-subtree (tree nonterminal) (let ((subtrees (mapcar 'second (remove-if-not #'(lambda (comp) (numberp (first comp))) (cdr tree))))) (find nonterminal subtrees :key 'car)))
(S (TYPE LIFT) (1 (VP (TYPE LIFT)
(1 (VERB-H (ROOT PICK))) (2 (PREP-H (ROOT UP)))))
(2 (OBJ (REF DEFINITE) (COLOR GREEN) (SHAPE SPHERE) (1 (ART (REF DEFINITE) (ROOT THE) (NUM S))) (2 (OPT-ADJ (ROOT GREEN) (1 (ADJ (ROOT GREEN))))) (3 (NOUN (ROOT SPHERE) (NUM S))) (4 (OPT-LOCATION (TYPE ABSOLUTE) (1 (PREP (ROOT AT))) (2 (POSITION (INDEX 3)
(1 (NOUN (ROOT POSITION))) (2 (NUMBER (ROOT 3))))))))))
![Page 6: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/6.jpg)
6 CSE573 Autumn 1997
Constructing a command structure
(S (TYPE LIFT) (1 (VP (TYPE LIFT)
(1 (VERB-H (ROOT PICK))) (2 (PREP-H (ROOT UP)))))
(2 (OBJ (REF DEFINITE) (COLOR GREEN) (SHAPE SPHERE) (1 (ART (REF DEFINITE) (ROOT THE) (NUM S))) (2 (OPT-ADJ (ROOT GREEN) (1 (ADJ (ROOT GREEN))))) (3 (NOUN (ROOT SPHERE) (NUM S))) (4 (OPT-LOCATION (TYPE ABSOLUTE) (1 (PREP (ROOT AT))) (2 (POSITION (INDEX 3)
(1 (NOUN (ROOT POSITION))) (2 (NUMBER (ROOT 3))))))))))
(defstruct command action object destination)
NIL
![Page 7: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/7.jpg)
7 CSE573 Autumn 1997
Constructing an object structure
(OBJ (REF DEFINITE) (COLOR GREEN) (SHAPE SPHERE) (1 (ART (REF DEFINITE) (ROOT THE) (NUM S))) (2 (OPT-ADJ (ROOT GREEN) (1 (ADJ (ROOT GREEN))))) (3 (NOUN (ROOT SPHERE) (NUM S)))
(4 (LOCATION (TYPE ABSOLUTE) (1 (PREP (ROOT AT))) (2 (POSITION (INDEX 3)
(1 (NOUN (ROOT POSITION))) (2 (NUMBER (ROOT 3))))))))))
(defstruct object ref color shape place)
![Page 8: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/8.jpg)
8 CSE573 Autumn 1997
Constructing a location structure
(OPT-LOCATION (TYPE ABSOLUTE) (1 (PREP (ROOT AT))) (2 (POSITION (INDEX 3) (1 (NOUN (ROOT POSITION))) (2 (NUMBER (ROOT 3))))))))))
(defstruct location (abs-position NIL) (rel-direction NIL) (rel-object NIL))
![Page 9: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/9.jpg)
9 CSE573 Autumn 1997
Interface with the World
• ;;;********************************************************• ;;; This is our model of the "real world".• ;;;• ;;; Initialization: • ;;; (WORLD-INITIALIZE) sets the world to the state • ;;; discussed in class• ;;;• ;;; Sensing• ;;; (WORLD-MIN-POSITION)• ;;; returns the smallest legal position index• ;;; (WORLD-MAX-POSITION)• ;;; returns the largest legal position index• ;;; (WORLD-SENSE-POSITION n) • ;;; returns a list of objects at • ;;; that position. Index is 0-relative, and the list • ;;; shows the topmost object first. • ;;; (WORLD-SENSE-GRIPPER-CONTENTS)• ;;; returns either NIL (gripper empty) or a feature list as above• ;;; (WORLD-SENSE-GRIPPER-POSITION)• ;;; returns a position• ;;;• ;;; Objects• ;;; Every object returned by one of the sensing operations responds to• ;;; (WOBJECT-COLOR wobject) => color• ;;; (WOBJECT-SHAPE wobject) => shape• ;;;• ;;; Actions• ;;; (WORLD-EXECUTE-COMMAND command-name &optional position) => NOTHING• ;;; command-name is either :LIFT or :DROP or :MOVE• ;;; the :MOVE command takes a position argument, the others do not.• ;;; Note well: there is no indication from the world if the command • ;;; is executed in error!• ;;;
![Page 10: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/10.jpg)
10 CSE573 Autumn 1997
Verifying and Executing
(defun verify-and-execute-command (command) (case (command-action command) ((LIFT) (when (verify-lift (command-object command)) (world-execute-command :LIFT))) ((DROP) (when (verify-drop (command-object command)) (world-execute-command :DROP))) ((MOVE) (let ((positions (verify-move (command-destination command)))) (when positions (world-execute-command :MOVE (first positions))))) (OTHERWISE (error "Unrecognized command ~a" (command-action command)))))
;;;****************************************************
(defun verify-lift (object) (let* ((gripper-position (world-sense-gripper-position)) (gripper-contents (world-sense-gripper-contents)) (top-block (first (world-sense-position gripper-position)))) (cond ((not (null gripper-contents)) (format t "~%Execution error on LIFT: gripper not empty.~%") NIL) ((null top-block) (format t "~%Execution error on LIFT: no object to lift.~%") NIL) ((not (objects-agree object top-block gripper-position)) (format t "~%Execution error on LIFT: invalid object description~%") NIL) (T T))))
![Page 11: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/11.jpg)
11 CSE573 Autumn 1997
Comparing parsed and sensed objects
(defun objects-agree (parsed-object sensed-object sensed-object-position) (and (or (null (object-color parsed-object)) (eq (object-color parsed-object) (wobject-color sensed-object))) (or (null (object-shape parsed-object)) (eq (object-shape parsed-object) 'BLOCK) (eq (object-shape parsed-object) (wobject-shape sensed-object))) (or (null sensed-object-position) (member sensed-object-position (possible-object-positions parsed-object)))))
;;; The argument is an object description, and can contain a relative;;; LOCATION clause. Return all positions that are consistent with ;;; both the relative clause *and* with the object's shape and color.
(defun possible-object-positions (object) (let* ((dest-positions (possible-destination-positions (object-place object))) (obj-positions (find-objects (object-color object) (object-shape object)))) (intersection obj-positions dest-positions)))
;;;******************************************************;;; Return a list of positions this LOCATION;;; structure could possibly refer to. If it is empty, ;;; return the list of all positions.
(defun possible-destination-positions (location) (cond ((location-abs-position location) (list (location-abs-position location))) ((location-rel-direction location) (apply-direction (location-rel-direction location) (possible-object-positions (location-rel-object location)))) (T (all-possible-positions))))
![Page 12: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/12.jpg)
12 CSE573 Autumn 1997
Shifting Positions
;;; Given a list of positions, apply the DIRECTION which ;;; is either LEFT (shift each to -1), RIGHT (shift each to +1);;; NEXT (shift to both +1 and -1), TO (do not shift). In ;;; each case make sure the shift doesn't produce an invalid ;;; position.
(defun apply-direction (direction positions) (cond ((null positions) '()) (T (let* ((next-position (first positions))
(new-positions (case direction
((TO) (list next-position))((LEFT) (if (valid-position-p (- next-position 1)) (list (- next-position 1)) '()))((RIGHT) (if (valid-position-p (+ next-position 1)) (list (+ next-position 1) ) '()))((NEXT) (cond ((and (valid-position-p (- next-position 1))
(valid-position-p (+ next-position 1))) (list (- next-position 1) (+ next-position 1))) ((valid-position-p (- next-position 1)) (list (- next-position 1))) ((valid-position-p (+ next-position 1)) (list (+ next-position 1))) (T '()))))))
(append new-positions (apply-direction direction (cdr positions)))))))
![Page 13: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/13.jpg)
13 CSE573 Autumn 1997
System Summary
Parser Knows about language syntax: Grammar & Lexicon
Interpreter Knows about parse tree, internal representation
Verifier Knows about actions, preconditions
World Internal world state
Sensing and effectingfilter “false” sentences
Internal “semantic” representation
Parse treefilter ungrammatical sentencs
Sentence
![Page 14: CSE573 Autumn 1997 1 03/06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.](https://reader036.fdocuments.net/reader036/viewer/2022083008/56649f575503460f94c7bc6f/html5/thumbnails/14.jpg)
14 CSE573 Autumn 1997
Final thoughts about NLP
• It’s hard!• We’ve only just scratched the surface
– syntactic ambiguity
– deeper semantics
– understanding language in context