1 / 13

AI - Weeks 19 Natural Language Processing PART 2

Lee McCluskey, room 2/07 Email lee@hud.ac.uk http://scom.hud.ac.uk/scomtlm/cha2555/. AI - Weeks 19 Natural Language Processing PART 2. NLP: the process. Text (sentence, email, news story..). -- Parsing -- Referencing -- Meaning Extraction and Integration. UNDERSTANDING PROCESS

Download Presentation

AI - Weeks 19 Natural Language Processing PART 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

  4. Natural Language Processing NLP (NLU) : typical process Scanning Parsing Finding referents for pronouns etc Resolving Ambiguities Meaning Extraction Meaning Integration

  5. Natural Language Processing NLP (NLU) : tools to help • Parser- Generators (e.g. YACC, JavaCUP) are tools which input BNF Grammars and output Parsers for computer languages such as programming languages. • Extra information can be added to the Grammar to make the Parser output useful information. • PGs can be used for Natural Language Processing also. Parser Generator Grammar Sentence / program Parser Parse Tree or Syntax Error Report

  6. Natural Language Processing NLP (NLU) : Definite Clause Grammars Prolog has a built in Parser Generator tool called the “Definite clause grammar” See http://en.wikipedia.org/wiki/Definite_clause_grammar http://www.cs.sunysb.edu/~warren/xsbbook/node10.html This interprets grammar rules as “recursive descent” parsers (hence generating a parser immediately from the grammar). DCG - very simple example – here is a BNF grammar: <sentence> --> <noun> <verb> <noun> <noun> --> i | sentences <verb> --> parse

  7. Natural Language Processing NLP (NLU) : Definite Clause Grammars Grammar with this Prolog-looking syntax sentence --> noun, verb, noun. noun --> [i]. noun --> [sentences]. verb --> [parse]. Input this to the Prolog Interpreter gives a listing of: sentence(A, B) :- noun(A, C), verb(C, D), noun(D, B). noun(A, B) :- A = [ i | B]. noun(A, B) :- A = [sentences | B]. verb(A, B) :- A = [ parse | B ]. Try it out with sentence([i,parse,sentences],A).

  8. Natural Language Processing Larger Example – BNF grammar for a bit of English sentence --> noun_phrase verb_phrase noun_phrase --> determiner adjective noun noun_phrase --> adjective noun noun_phrase --> determiner noun noun_phrase --> noun verb_phrase --> verb noun_phrase verb_phrase --> verb preposition noun_phrase determiner --> a | an adjective --> fruit noun --> flies | fruit | time | arrow noun --> banana verb --> like | flies preposition --> like

  9. Natural Language Processing Example in Prolog DCG syntax 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.

  10. 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”

  11. Natural Language Processing Getting More From the Parsing Stage • Other functions we might need – extract information about the parse, and ensure constraints are maintained in various parts of the sentence, eg • - 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

  12. Natural Language Processing NLP (NLU) : Definite Clause Grammars Grammar with this Prolog-looking syntax sentence(s(subject(S),V,object(O))) --> noun(S), verb(V), noun(O). noun(noun(i)) --> [i]. noun(noun(sentence)) --> [sentences]. verb(verb(parse)) --> [parse]. Input this to the Prolog Interpreter gives a listing of: sentence(s(subject(S), V, object(O)), A, B) :- noun(S, A, C), verb(V, C, D), noun(O, D, B). noun(noun(i), A, B) :- A = [ i | B]. noun(noun(sentence), A, B) :- A = [sentences | B]. verb(verb(parse), A, B) :- A = [ parse | B ]. Try it out sentence(Tree, [i,parser,sentences],X). X = [], Tree = s(subject(noun(i)),verb(parser),object(noun(sentence))) ? yes

  13. Natural Language Processing Parsing + Returning a Parse Tree /* syntax bit + No (-singular or plural) + Gender (-Masc, Fem or Inamin.)*/ sentence(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 = [] ?

More Related