Presentation is loading. Please wait.

Presentation is loading. Please wait.

Natural Language Processing AI - Weeks 19 Natural Language Processing PART 2 Lee McCluskey, room 2/07

Similar presentations


Presentation on theme: "Natural Language Processing AI - Weeks 19 Natural Language Processing PART 2 Lee McCluskey, room 2/07"— Presentation transcript:

1 Natural Language Processing AI - Weeks 19 Natural Language Processing PART 2 Lee McCluskey, room 2/07 Email lee@hud.ac.uklee@hud.ac.uk http://scom.hud.ac.uk/scomtlm/cha2555/

2 Natural Language Processing NLP: the process Natural Language Generation Translation Summary/ Classification Knowledge Base: representation of meaning UNDERSTANDING PROCESS (“Natural Language Understanding”) Text (sentence, email, news story..) -- Parsing -- Referencing -- Meaning Extraction and Integration

3 Natural Language Processing NLP: the process Knowledge Base: representation of meaning UNDERSTANDING PROCESS (“Natural Language Understanding”) Text “The cat sits on the mat” sentence npvp The cat sits on the mat Fact(type: statement, agent: cat-002, action: sits_on, object: mat-001) Fact(type: statement, agent: Fido, action: is_a, object: cat) Fact(type: statement, agent: Freda, action: loves, object: Fido)

4 Natural Language Processing Parsing sentence --> noun_phrase, verb_phrase. noun_phrase--> determiner, adjective, noun. noun_phrase--> adjective, noun. noun_phrase--> determiner, noun. verb_phrase--> verb, noun_phrase. verb_phrase--> verb, preposition, noun_phrase. determiner --> a. adjective --> fruit. noun --> flies | fruit | time | arrow. noun --> banana. verb --> like | flies. preposition --> like

5 Natural Language Processing Parsing sentence --> noun_phrase, verb_phrase. noun_phrase--> determiner, adjective, noun. noun_phrase--> adjective, noun. noun_phrase--> determiner, noun. verb_phrase--> verb, noun_phrase. verb_phrase--> verb, preposition, noun_phrase. determiner --> a. adjective --> fruit. noun --> flies. noun --> fruit. noun --> time. noun --> arrow. noun --> banana. verb --> like. verb --> flies. preposition --> like.

6 Natural Language Processing Parsing with Prolog Grammar Rules sentence --> noun_phrase, verb_phrase. noun_phrase--> determiner, adjective, noun. noun_phrase--> adjective, noun. noun_phrase--> determiner, noun. verb_phrase--> verb, noun_phrase. verb_phrase--> verb, preposition, noun_phrase. determiner --> [a]. adjective --> [fruit]. noun --> [flies]. noun --> [banana]. noun --> [fruit]. noun --> [time]. noun --> [arrow]. verb --> [like]. verb --> [flies]. preposition --> [like]. This Grammar can now be loaded into Prolog and ACTS LIKE A PARSER.

7 Natural Language Processing Prolog Grammar Rules sentence(A, B) :- noun_phrase(A, C), verb_phrase(C, B). noun_phrase(A, B) :- determiner(A, C), adjective(C, D), noun(D, B). noun_phrase(A, B) :- adjective(A, C), noun(C, B). noun_phrase(A, B) :- determiner(A, C), noun(C, B). verb_phrase(A, B) :- verb(A, C), noun_phrase(C, B). verb_phrase(A, B) :- verb(A, C), preposition(C, D), noun_phrase(D, B). determiner(A,B) :- A = [a|B]. adjective(A,B) :- A = [fruit| B]. noun(A,B) :- A = [flies|B]. noun(A,B) :-A = [banana|B]. noun(A,B) :-A= [fruit|B]. noun(A,B) :-A = [time|B]. noun(A,B) :-A = [arrow|B]. verb(A,B) :-A = [like|B]. verb(A,B) :-A = [flies|B]. preposition(A,B) :- A = [like|B]. This is the Prolog Code that the Grammar Translates to. The variables implement a kind of “stream processing”

8 Natural Language Processing Getting More From the Parsing Stage Other functions we might need.. - Return parse tree - Check consistency of gender - Checking consistency of number sentence(sentence( NP, VP)) --> noun_phrase(NP, No, Gender), verb_phrase(VP, No, Gender). -- build up parse tree as “self describing” term -- when a part of the sentence commits to number or gender, then record it for consistency

9 Natural Language Processing Parsing + Returning a Parse Tree /* syntax bit + No (-singular or plural) + Gender (-Masc, Fem or Inamin.)*/ s entence(sentence( NP, VP)) --> noun_phrase(NP, No, Gender), verb_phrase(VP, No, Gender). noun_phrase(noun_phrase([D,N]), No,Gender) --> d(D, No,Gender), n(N, No,Gender). verb_phrase(verb_phrase([V,N]), No,Gender) --> v(V, No,Gender), noun_phrase(N, _,_). /* no ref to no or gen of object*/ verb_phrase(verb_phrase([V]), No,Gender) --> v(V, No,Gender). d(determiner(the), No,Gender) --> [the]. d(determiner(a), singular,Gender) --> [a]. d(determiner(some), plural,Gender) --> [some]. d(determiner(all), plural,Gender) --> [all]. n(noun(apple), singular, inanimate) --> [apple]. n(noun(apples), plural, inanimate) --> [apples]. n(noun(man), singular, animate) --> [man]. n(noun(men), plural, animate) --> [men]. v(verb(eat), singular, animate) --> [eats]. v(verb(eats), plural, animate) --> [eat]. v(verb(sing), singular, animate) --> [sings]. v(verb(sings), plural, animate) --> [sing]. sentence(X,[the,man,eats,the,apples],Y). X = sentence( noun_phrase([determiner(the),noun(man)]), verb_phrase([verb(eat), noun_phrase([determiner(the),noun(apples)])])), Y = [] ?


Download ppt "Natural Language Processing AI - Weeks 19 Natural Language Processing PART 2 Lee McCluskey, room 2/07"

Similar presentations


Ads by Google