Chapter 6 Natural Language Processing 1 NLP Language

  • Slides: 31
Download presentation
Chapter 6 Natural Language Processing 1

Chapter 6 Natural Language Processing 1

NLP Language translation / multilingual translation n Language understanding n Figure 14. 5 p.

NLP Language translation / multilingual translation n Language understanding n Figure 14. 5 p. 365 Interaction among component n Figure 14. 6 p. 366 A speech Waveform n 2 344 -471 AI & ES Chapter 6 NLP

NLP Problems n n n 3 Figure 15. 1 P. 378 English sentences are

NLP Problems n n n 3 Figure 15. 1 P. 378 English sentences are incomplete descriptions of the information that are intended to convey. The same expression means different things in different context. No natural language program can be complete because of new words, expression, and meaning can be generated quite freely. There are lots of ways to say the same thing. 344 -471 AI & ES Chapter 6 NLP

NLP Problems 1) Processing written text n n using lexical, syntactic, and semantic knowledge

NLP Problems 1) Processing written text n n using lexical, syntactic, and semantic knowledge of the language require the real world information 2) Processing spoken language using all information needed above plus additional knowledge about phonology n handle ambiguities in speech n 4 344 -471 AI & ES Chapter 6 NLP

Step in NLP 1) Morphological Analysis 2) Syntactic Analysis 3) Semantic Analysis 4) Discourse

Step in NLP 1) Morphological Analysis 2) Syntactic Analysis 3) Semantic Analysis 4) Discourse Integration 5) Pragmatic Analysis boundaries between these five phrases are often fuzzy. n 5 344 -471 AI & ES Chapter 6 NLP

1. Morphological Analysis n n n Individual words are analyzed into components Nonword tokens

1. Morphological Analysis n n n Individual words are analyzed into components Nonword tokens such as punctuation are separated from the words I want to print Bill’s. int file extension proper noun possessive suffix 6 344 -471 AI & ES Chapter 6 NLP

2. Syntactic Analysis n n 7 linear sequence of words are transformed into structures

2. Syntactic Analysis n n 7 linear sequence of words are transformed into structures show words relate to each other English syntactic analyzer If do not pass the syntactic analyzer reject e. g. (Boy the go to store the) 344 -471 AI & ES Chapter 6 NLP

2. Syntactic Analysis n Example of syntactic analysis Figure 15. 2 p. 382 RM

2. Syntactic Analysis n Example of syntactic analysis Figure 15. 2 p. 382 RM 2, RM 5 n A knowledge base Fragment Figure 15. 3 p. 383 User 073, F 1, Printing, File_Structure, Waiting Mental Event/ Physical Event Animate/Event n Partial meaning for a sentence Figure 15. 4 p. 384 8 344 -471 AI & ES Chapter 6 NLP

Syntax 9 344 -471 AI & ES Chapter 6 NLP

Syntax 9 344 -471 AI & ES Chapter 6 NLP

Parse Tree 10 344 -471 AI & ES Chapter 6 NLP

Parse Tree 10 344 -471 AI & ES Chapter 6 NLP

Apply rule 11 344 -471 AI & ES Chapter 6 NLP

Apply rule 11 344 -471 AI & ES Chapter 6 NLP

3. Semantic Analysis the structures created by the syntactic analyzer are assign meanings n

3. Semantic Analysis the structures created by the syntactic analyzer are assign meanings n mapping between the syntactic structure and objects in the task domain n If no mapping reject (colorless green ideas sleep furiously) n 1) It must map individual words into appropriate objects in the knowledge base or database. n 2) It must create the correct structures to correspond to the meanings of the individual words combine with each other. n 12 344 -471 AI & ES Chapter 6 NLP

4. Discourse Integration n the meaning of the individual sentence may depend on the

4. Discourse Integration n the meaning of the individual sentence may depend on the sentences that precede it and may influence the meanings of the sentences that follow it. (Ex. John want it. ) “It” depends on the previous sentence. Current user who type word “I” is n n 13 User 068 = Susan_Black We get F 1 with filename in /wsmith/ directory 344 -471 AI & ES Chapter 6 NLP

5. Pragmatic Analysis n n The structure representing what was said is reinterpreted to

5. Pragmatic Analysis n n The structure representing what was said is reinterpreted to determine what was actually meant. (Ex. Do you know what time it is? ) we should understand what to do. . Understand to decide what to do as a result n Representing the intended meaning n 14 Figure 15. 5 P. 385 344 -471 AI & ES Chapter 6 NLP

Internal Representative 15 344 -471 AI & ES Chapter 6 NLP

Internal Representative 15 344 -471 AI & ES Chapter 6 NLP

Syntactic Processing n Top-down Parsing n n Bottom-up Parsing n 17 Begin with start

Syntactic Processing n Top-down Parsing n n Bottom-up Parsing n 17 Begin with start symbol and apply the grammar rules forward until the symbols at the terminals of the tree correspond to the components of the sentence being parsed. Begin with the sentence to be parsed and apply the grammar rules backward until a single tree whose terminals are the words of the sentence and whose top node is the start symbol has been produced. 344 -471 AI & ES Chapter 6 NLP

Transition Network 18 344 -471 AI & ES Chapter 6 NLP

Transition Network 18 344 -471 AI & ES Chapter 6 NLP

ATN : Augmented Transition Network n similar to finite state machine Figure 15. 8

ATN : Augmented Transition Network n similar to finite state machine Figure 15. 8 p. 392 An ATN network Figure 15. 9 p. 3923 An ATN Grammar in List Form n sentence “The long file has printed. ” S NP Q 1 AUX NP Det Q 6 Adj (S DCL Q 3 V Q 4 (F) halt Q 6 N Q 7 (F) (NP (FILE (LONG) DEFINITE)) HAS 19 (VP PRINTED)) 344 -471 AI & ES Chapter 6 NLP

Turbo Prolog 32

Turbo Prolog 32

TURBO PROLOG ftp: //172. 28. 80. 6/older/Dos. Program/TPROLOG Alt + Enter = Big Screen

TURBO PROLOG ftp: //172. 28. 80. 6/older/Dos. Program/TPROLOG Alt + Enter = Big Screen F 1 : Help F 2 : Save F 3 : Load F 6 : Next/Switch F 8 : Previous Goal F 9 : Compile F 10 : Step (For trace) / End Alt + T : Trace ON/OFF Set up window size edit Use arrow key to adjust the size 33 344 -471 AI & ES Chapter 6 NLP

TURBO PROLOG Use the example from the EXAMPLE directory to try to program. Start

TURBO PROLOG Use the example from the EXAMPLE directory to try to program. Start with EX 03 EX 01. PRO predicates likes(symbol, symbol) clauses likes(ellen, tennis). likes(john, football). likes(tom, baseball). FACTS likes(eric, swimming) likes(mark, tennis). 34 likes(bill, Activity) if likes(mark, Activity) : - likes(tom, Activity). likes(ellen, Activity). 344 -471 AI & ES RULES Chapter 6 NLP

PROLOG. HELP ARITHMETIC Arithmetic operators: +, -, *, /, mod, div Relational operators: >,

PROLOG. HELP ARITHMETIC Arithmetic operators: +, -, *, /, mod, div Relational operators: >, <, =, >=, <>, >< Functions: sin, cos, tan, arctan, log, exp, sqrt, round, trunc, abs EX: 1 + 2 = 2 + 1, X = 5/2, X = 5 mod 2, 35 344 -471 AI & ES 5 <> 9 Chapter 6 NLP

PREDEFINED DOMAINS char 1 byte characters integer 2 byte integer numbers real 8 byte

PREDEFINED DOMAINS char 1 byte characters integer 2 byte integer numbers real 8 byte floating point numbers symbol strings inserted in the internal symbol table string sequences of chars "hello worldn" 36 344 -471 AI & ES Chapter 6 NLP

SUMMARY OF PROGRAM SECTIONS CONSTANTS const 1 = definition const 2 = definition [GLOBAL]

SUMMARY OF PROGRAM SECTIONS CONSTANTS const 1 = definition const 2 = definition [GLOBAL] DOMAINS dom [, dom] = [reference] declaration 1; declaration 2 listdom = dom* dom = <basisdom> [GLOBAL] DATABASE [ - <databasename> ] [determ] pred 1(. . ) pred 2(. . . ) GLOBAL PREDICATES [determ|nondeterm] pred 1(. . ) -(i, i, o, . . )(i, o, i, . . ) [ language c|pascal|fortran ] [ as "name" ] pred 2(. . . . ) PREDICATES [determ|nondeterm] pred 1(. . ) pred 2(. . . . ) CLAUSES p(. . . . ): -p 1(. . . ), p 2(. . ), . . . . include "filename" 37 Include a file during compilation. 344 -471 AI & ES Chapter 6 NLP

MISCELLANEOUS random(Real. Variable) (real) - (o) random(Max. Value, Random. Int) (integer, integer) - (i,

MISCELLANEOUS random(Real. Variable) (real) - (o) random(Max. Value, Random. Int) (integer, integer) - (i, o) sound(Duration, Frequency) (integer, integer) - (i, i) beep date(Year, Month, Day) (integer, integer) - (o, o, o) (i, i, i) time(Hours, Minutes, Seconds, Hundredths) (integer, integer) - (o, o, o, o) (i, i, i, i) trace(on/off) (string) - (i) (o) 38 344 -471 AI & ES Chapter 6 NLP

ERROR & BREAK CONTROL trap (Predicate. Call, Exit. Code, Predicate To. Call. On. Error)

ERROR & BREAK CONTROL trap (Predicate. Call, Exit. Code, Predicate To. Call. On. Error) exit (Exit. Code) (integer) - (i) if exit to DOS then the DOS errorlevel task processing variable will contain the value given to the exit predicate. break (on/off) (string) - (i) (o) 39 344 -471 AI & ES Chapter 6 NLP

EDITOR 40 display(String) (string) - (i) edit(Input. String, Output. String) (string, string) - (i,

EDITOR 40 display(String) (string) - (i) edit(Input. String, Output. String) (string, string) - (i, o) edit(Input. String, Output. String, Headstr 2, Ms g, Pos, Helpfilename, Edit. Mode, Indent, Insert, Text. Mode, Ret. Pos, Ret. Statu s) (string, string, integer, str ing, integer, integer, int eger) - (i, o, i, i, i, o, o) If the user saves the text from the editor, Head. Str 2 will be used as the file name. editmsg(Input. String, Output. String, Headstr 2, Msg, Pos, Helpfilename, Ret. Status) (string, string, integer, str ing, integer) - (i, o, i, i, i, o) 344 -471 AI & ES Chapter 6 NLP

WINDOW SYSTEM makewindow(Window. No, Scr. Att, Framestr, Ro w, Column, Height, Width) (integer, string,

WINDOW SYSTEM makewindow(Window. No, Scr. Att, Framestr, Ro w, Column, Height, Width) (integer, string, integer, integer) shiftwindow(Window. No) (integer) - (i) (o) gotowindow(Window. No) (integer) - (i) resizewindow(Start. Row, No. Of. Rows, Start. Col, No. Of. Col s) (integer, integer) - (i, i, i, i) colorsetup(Main_Frame) (integer) - (i) 41 344 -471 AI & ES Chapter 6 NLP

INPUT readln(String. Variable) (string) - (o) readint(Intg. Variable) (integer) - (o) readreal(Real. Variable) (real)

INPUT readln(String. Variable) (string) - (o) readint(Intg. Variable) (integer) - (o) readreal(Real. Variable) (real) - (o) readchar(Char. Variable) (char) - (o) keypressed unreadchar(Char. To. Be. Pushed. Back) (Char) - (i) readterm( Domain, Variable ) (Domain. Name, Domain) - (i, _) 42 344 -471 AI & ES Chapter 6 NLP

OUTPUT write( Variable|Constant * ) nl writef( Format. String, Variable|Constant* ) In the format

OUTPUT write( Variable|Constant * ) nl writef( Format. String, Variable|Constant* ) In the format string the following options are known after a percentage sign: %d Normal decimal number. (chars and integers) %u As an unsigned integer. (chars and integers) %R As a database reference number. (database reference numbers) %X As a long hexadecimal number. (strings, database reference numb). %x As a hexadecimal number. (chars and integers). %s Strings. (symbols and strings). %c As a char. (chars and integers). %g Reals in shortest posible format (default for reals) %e Reals in exponetial notation %f Reals in fixed notation %lf Only for C compatibility (fixed reals) 43 n - newline t - tabulator nnn - character with code nnn 344 -471 AI & ES Chapter 6 NLP

The End 44 344 -471 AI & ES Chapter 6 NLP

The End 44 344 -471 AI & ES Chapter 6 NLP