Chapter 4 Natural Language Processing NLP Language translation





































![SUMMARY OF PROGRAM SECTIONS CONSTANTS const 1 = definition const 2 = definition [GLOBAL] SUMMARY OF PROGRAM SECTIONS CONSTANTS const 1 = definition const 2 = definition [GLOBAL]](https://slidetodoc.com/presentation_image_h2/a566b74393dfeed8ca764a570dee4139/image-38.jpg)











- Slides: 49
Chapter 4 Natural Language Processing
NLP • Language translation / multilingual translation • Language understanding – Figure 14. 5 p. 365 Interaction among component – Figure 14. 6 p. 366 A speech Waveform 323 -670 Artificial Intelligence 2 Chapter 4
S NP John VP V saw NP PP PP with a telescope DET N the boy in the park John saw the boy in the park with a telescope. Figure 14. 5: More Interaction among Components 323 -670 Artificial Intelligence 3 Chapter 4
S NP John VP V saw NP DET N PP the boy PP in the park with a dog John saw the boy in the park with a dog. Figure 14. 5: More Interaction among Components 323 -670 Artificial Intelligence 4 Chapter 4
S NP John VP NP V saw DET N the boy PP in the park with a statue John saw the boy in the park with a statue. Figure 14. 5: More Interaction among Components 323 -670 Artificial Intelligence 5 Chapter 4
The cat scares all the birds away. katskars A cat’s cares are few. Figure 14. 6: Local Ambiguity in a Speech Problem 323 -670 Artificial Intelligence 6 Chapter 4
The Problem: English sentences are incomplete descriptions of the information that they are intended to convey: Some dogs are outside. I called Lynda to ask her to the movies. She said she’ d love to go. Some dogs are on the lawn. Three dogs are on the lawn. Rover, Tripp, and Spot are on the lawn. She was home when I called. She answered the phone. I actually asked her. The Good Side: Language allows speakers to be as vague or precise as they like. It also allows speakers to leave out things they believe their hearers already know. 323 -670 Artificial Intelligence 7 Chapter 4
The Problem: The same expression means different things in different contexts: Where’s the water? (in a chemistry lab, it must be pure) Where’s the water? (when you are thirsty, it must be potable) Where’s the water? (dealing with a leaky roof, it can be filthy) The Good Side: Language lets us communicate about an infinite world using a finite (and thus earnable) number of symbols. 323 -670 Artificial Intelligence 8 Chapter 4
The Problem: No natural language program can be complete because new words, expressions, and meanings can be generated Quite freely: I’ll fax it to you. The Good Side: Language can evolve as the experiences that we want to communicate about evolve. 323 -670 Artificial Intelligence 9 Chapter 4
The problem: There are lots of ways to say the same thing: Mary was born on October 11. Mary’s birthday is October 11. The Good Side: When you know a lot, facts imply each other. Language is intended to be used by agents who know a lot. Figure 15. 1: Features of Language That Mark It Both Difficult and Useful 323 -670 Artificial Intelligence 10 Chapter 4
NLP Problems • 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. 323 -670 Artificial Intelligence 11 Chapter 4
NLP Problems 1) Processing written text – 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 – handle ambiguities in speech 323 -670 Artificial Intelligence 12 Chapter 4
Step in NLP 1) 2) 3) 4) 5) Morphological Analysis Syntactic Analysis Semantic Analysis Discourse Integration Pragmatic Analysis – boundaries between these five phrases are often fuzzy. 323 -670 Artificial Intelligence 13 Chapter 4
1. Morphological Analysis • 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 323 -670 Artificial Intelligence 14 Chapter 4
2. Syntactic Analysis • 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) 323 -670 Artificial Intelligence 15 Chapter 4
2. Syntactic Analysis • Example of syntactic analysis Figure 15. 2 p. 382 RM 2, RM 5 • A knowledge base Fragment Figure 15. 3 p. 383 User 073, F 1, Printing, File_Structure, Waiting Mental Event/ Physical Event Animate/Event • Partial meaning for a sentence Figure 15. 4 p. 384 323 -670 Artificial Intelligence 16 Chapter 4
Syntax 323 -670 Artificial Intelligence The dog bites the man. 17 Chapter 4
Apply rule 323 -670 Artificial Intelligence 18 Chapter 4
Parse Tree 323 -670 Artificial Intelligence The man bits the dog. 19 Chapter 4
The dog likes a man. Parse Tree 323 -670 Artificial Intelligence 20 Chapter 4
Internal Representative 323 -670 Artificial Intelligence 21 Chapter 4
Syntactic Processing (2) • Top-down Parsing – 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. • Bottom-up Parsing – 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. 323 -670 Artificial Intelligence 23 Chapter 4
Transition Network The man bits the dog. 323 -670 Artificial Intelligence 24 Chapter 4
ATN : Augmented Transition Network • similar to finite state machine Figure 15. 8 p. 392 An ATN network Figure 15. 9 p. 393 An ATN Grammar in List Form • sentence “The long file has printed. ” S NP Q 1 AUX NP Det Q 6 Adj (S DCL 323 -670 Artificial Intelligence Q 3 V Q 4 (F) halt Q 6 N Q 7 (F) (NP (FILE (LONG) DEFINITE)) HAS 25 (VP PRINTED)) p. 394 Chapter 4
3. Semantic Analysis • the structures created by the syntactic analyzer are assign meanings • mapping between the syntactic structure and objects in the task domain • If no mapping reject (colorless green ideas sleep furiously) • 1) It must map individual words into appropriate objects in the knowledge base or database. • 2) It must create the correct structures to correspond to the meanings of the individual words combine with each other. 323 -670 Artificial Intelligence 27 Chapter 4
323 -670 Artificial Intelligence 33 Chapter 4
323 -670 Artificial Intelligence 34 Chapter 4
������������������������� 323 -670 Artificial Intelligence 36 Chapter 4 lpr /wsmith/stuff. init
4. Discourse Integration • 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 – User 068 = Susan_Black • We get F 1 with filename in /wsmith/ directory 323 -670 Artificial Intelligence 42 Chapter 4
5. Pragmatic Analysis • 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 • Representing the intended meaning – Figure 15. 5 P. 385 323 -670 Artificial Intelligence 43 Chapter 4
Turbo Prolog
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 323 -670 Artificial Intelligence 47 Chapter 4
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). likes(bill, Activity) if likes(mark, Activity) : - 323 -670 Artificial Intelligence likes(tom, Activity). likes(ellen, Activity). 48 RULES Chapter 4
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, 323 -670 Artificial Intelligence 49 5 <> 9 Chapter 4
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" 323 -670 Artificial Intelligence 50 Chapter 4
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" 323 -670 Artificial Intelligence Include a file during compilation. 51 Chapter 4
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) 323 -670 Artificial Intelligence 52 Chapter 4
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) 323 -670 Artificial Intelligence 53 Chapter 4
EDITOR display(String) (string) - (i) edit(Input. String, Output. String) (string, string) - (i, o) edit(Input. String, Output. String, Headstr 2, Msg, Pos, He lpfilename, Edit. Mode, Indent, Insert, Text. Mode, Ret. Pos, Ret. Status) (string, string, integer, string, int eger, integer, integer) - (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, string, int eger) - (i, o, i, i, i, o) 323 -670 Artificial Intelligence 54 Chapter 4
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) 323 -670 Artificial Intelligence 55 Chapter 4
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, _) 323 -670 Artificial Intelligence 56 Chapter 4
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) n - newline t - tabulator nnn - character with code nnn 323 -670 Artificial Intelligence 57 Chapter 4
Natural Language Processing using prolog Sentence : - Noun_phrase, Verb_phrase. Noun_phrase : - Det, Noun_phrase : - Noun. Verb_phrase : - Verb, Noun_phrase. Verb_phrase : - verb. EX : The cat eats the fish. A man likes an apple. 323 -670 Artificial Intelligence 58 Chapter 4
EX 13 EX 04. pro NLP. pro domains sentence = s(noun_phrase, verb_phrase) noun_phrase = noun(noun) ; noun_phrase(detrm, noun) noun = string verb_phrase = verb(verb) ; verb_phrase(verb, noun_phrase) verb = string detrm = string predicates s_sentence(string, sentence) s_noun_phrase(string, noun_phrase) s_verb_phrase(string, verb_phrase) d(string) n(string) v(string) goal: start Please enter the sentence > goal Bill eats apple start. 323 -670 Artificial Intelligence 59 Chapter 4
EX 13 EX 04. pro NLP. pro (cont) clauses start : - write("n Please enter a sentence > "), readln(Str), s_sentence(Str, s(_, _)). s_sentence(Str, s(N_Phrase, V_Phrase) ): s_noun_phrase(Str, Rest, N_Phrase), s_verb_phrase(Rest, V_Phrase). s_noun_phrase(Str, Rest, noun_phrase(Detr, Noun)): fronttoken(Str, Detr, Rest 1), d(Detr), fronttoken(Rest 1, Noun, Rest), n(Noun). s_noun_phrase(Str, Rest, noun(Noun)): fronttoken(STR, Noun, Rest), n(Noun). s_verb_phrase(Str, verb_phrase(Verb, N_Phrase)): fronttoken(Str, Verb, Rest 1), v(Verb), s_noun_phrase(Rest 1, "", N_Phrase). s_verb_phrase(Str, verb(Verb)): fronttoken(STR, Verb, ""), v(Verb). 323 -670 Artificial Intelligence 60 Chapter 4
EX 13 EX 04. pro NLP. pro (cont) /* determiner */ d("the"). d("an"). /* nouns */ n(“Bill"). n("dog"). n("cat"). n("fish"). n("ant"). n("apple"). n("man"). n("bus"). /* verbs */ v("is"). v("eats"). v("likes"). v("takes"). 323 -670 Artificial Intelligence The cat likes fish A man takes a bus 61 Chapter 4
The End 323 -670 Artificial Intelligence 62 Chapter 4

















































