1 CSC 594 Topics in AI – Applied Natural Language Processing Fall 2009/2010 4. Grammar and Parsing.

Slides:



Advertisements
Similar presentations
 Christel Kemke 2007/08 COMP 4060 Natural Language Processing Feature Structures and Unification.
Advertisements

BİL711 Natural Language Processing1 Problems with CFGs We know that CFGs cannot handle certain things which are available in natural languages. In particular,
Mrach 1, 2009Dr. Muhammed Al-Mulhem1 ICS482 Formal Grammars Chapter 12 Muhammed Al-Mulhem March 1, 2009.
Syntactic analysis using Context Free Grammars. Analysis of language Morphological analysis – Chairs, Part Of Speech (POS) tagging – The/DT man/NN left/VBD.
Lecture 1, 7/21/2005Natural Language Processing1 CS60057 Speech &Natural Language Processing Autumn 2007 Lecture August 2007.
Natural Language Processing - Parsing 1 - Language, Syntax, Parsing Problems in Parsing Ambiguity, Attachment / Binding Bottom vs. Top Down Parsing.
Artificial Intelligence 2004 Natural Language Processing - Syntax and Parsing - Language, Syntax, Parsing Problems in Parsing Ambiguity, Attachment.
Intelligent Systems (AI-2) Computer Science cpsc422, Lecture 27
Albert Gatt LIN3022 Natural Language Processing Lecture 8.
Features and Unification
Introduction to Syntax, with Part-of-Speech Tagging Owen Rambow September 17 & 19.
Syntax and Context-Free Grammars CMSC 723: Computational Linguistics I ― Session #6 Jimmy Lin The iSchool University of Maryland Wednesday, October 7,
1 CONTEXT-FREE GRAMMARS. NLE 2 Syntactic analysis (Parsing) S NPVP ATNNSVBD NP AT NNthechildrenate thecake.
Machine Learning in Natural Language Processing Noriko Tomuro November 16, 2006.
1 CSC 594 Topics in AI – Applied Natural Language Processing Fall 2009/ Outline of English Syntax.
Artificial Intelligence 2004 Natural Language Processing - Syntax and Parsing - Language Syntax Parsing.
Parsing SLP Chapter 13. 7/2/2015 Speech and Language Processing - Jurafsky and Martin 2 Outline  Parsing with CFGs  Bottom-up, top-down  CKY parsing.
CPSC 503 Computational Linguistics
CS 4705 Lecture 11 Feature Structures and Unification Parsing.
Models of Generative Grammar Smriti Singh. Generative Grammar  A Generative Grammar is a set of formal rules that can generate an infinite set of sentences.
1 Basic Parsing with Context Free Grammars Chapter 13 September/October 2012 Lecture 6.
11 CS 388: Natural Language Processing: Syntactic Parsing Raymond J. Mooney University of Texas at Austin.
Context Free Grammars Reading: Chap 12-13, Jurafsky & Martin This slide set was adapted from J. Martin, U. Colorado Instructor: Paul Tarau, based on Rada.
School of something FACULTY OF OTHER School of Computing FACULTY OF ENGINEERING COMP3310 Natural Language Processing Eric Atwell, Language Research Group.
1 Features and Unification Chapter 15 October 2012 Lecture #10.
Context Free Grammars Reading: Chap 12-13, Jurafsky & Martin This slide set was adapted from J. Martin and Rada Mihalcea.
Speech and Language Processing Lecture 12—02/24/2015 Susan W. Brown.
Session 13 Context-Free Grammars and Language Syntax Introduction to Speech and Natural Language Processing (KOM422 ) Credits: 3(3-0)
BİL711 Natural Language Processing1 Statistical Parse Disambiguation Problem: –How do we disambiguate among a set of parses of a given sentence? –We want.
Probabilistic Parsing Reading: Chap 14, Jurafsky & Martin This slide set was adapted from J. Martin, U. Colorado Instructor: Paul Tarau, based on Rada.
1 Syntax Sudeshna Sarkar 25 Aug Sentence-Types Declaratives: A plane left S -> NP VP Imperatives: Leave! S -> VP Yes-No Questions: Did the plane.
1 CPE 480 Natural Language Processing Lecture 5: Parser Asst. Prof. Nuttanart Facundes, Ph.D.
CS 4705 Parsing More Efficiently and Accurately. Review Top-Down vs. Bottom-Up Parsers Left-corner table provides more efficient look- ahead Left recursion.
10/3/2015CPSC503 Winter CPSC 503 Computational Linguistics Lecture 8 Giuseppe Carenini.
1 Statistical Parsing Chapter 14 October 2012 Lecture #9.
10/12/2015CPSC503 Winter CPSC 503 Computational Linguistics Lecture 10 Giuseppe Carenini.
Parsing I: Earley Parser CMSC Natural Language Processing May 1, 2003.
Context Free Grammars Reading: Chap 9, Jurafsky & Martin This slide set was adapted from J. Martin, U. Colorado Instructor: Rada Mihalcea.
11 Chapter 14 Part 1 Statistical Parsing Based on slides by Ray Mooney.
6/2/2016CPSC503 Winter CPSC 503 Computational Linguistics Lecture 9 Giuseppe Carenini.
1 LIN6932 Spring 2007 LIN6932 Topics in Computational Linguistics Lecture 6: Grammar and Parsing (I) February 15, 2007 Hana Filip.
Lecture 1, 7/21/2005Natural Language Processing1 CS60057 Speech &Natural Language Processing Autumn 2007 Lecture August 2007.
Albert Gatt Corpora and Statistical Methods Lecture 11.
Linguistic Essentials
Parsing with Context-Free Grammars for ASR Julia Hirschberg CS 4706 Slides with contributions from Owen Rambow, Kathy McKeown, Dan Jurafsky and James Martin.
CPE 480 Natural Language Processing Lecture 4: Syntax Adapted from Owen Rambow’s slides for CSc Fall 2006.
Rules, Movement, Ambiguity
CSA2050 Introduction to Computational Linguistics Parsing I.
Natural Language - General
PARSING 2 David Kauchak CS159 – Spring 2011 some slides adapted from Ray Mooney.
NLP. Introduction to NLP Motivation –A lot of the work is repeated –Caching intermediate results improves the complexity Dynamic programming –Building.
CPSC 503 Computational Linguistics
CS 4705 Lecture 10 The Earley Algorithm. Review Top-Down vs. Bottom-Up Parsers –Both generate too many useless trees –Combine the two to avoid over-generation:
CS 4705 Lecture 7 Parsing with Context-Free Grammars.
Natural Language Processing Lecture 15—10/15/2015 Jim Martin.
CPSC 422, Lecture 27Slide 1 Intelligent Systems (AI-2) Computer Science cpsc422, Lecture 27 Nov, 16, 2015.
1 Introduction to Computational Linguistics Eleni Miltsakaki AUTH Spring 2006-Lecture 2.
Natural Language Processing Lecture 14—10/13/2015 Jim Martin.
1/22/2016CPSC503 Winter CPSC 503 Computational Linguistics Lecture 8 Giuseppe Carenini.
GRAMMARS David Kauchak CS457 – Spring 2011 some slides adapted from Ray Mooney.
PARSING David Kauchak CS159 – Fall Admin Assignment 3 Quiz #1  High: 36  Average: 33 (92%)  Median: 33.5 (93%)
Speech and Language Processing Formal Grammars Chapter 12.
SI485i : NLP Set 7 Syntax and Parsing. 2 Syntax Grammar, or syntax: The kind of implicit knowledge of your native language that you had mastered by the.
Natural Language Processing Vasile Rus
Speech and Language Processing
Lecture 13: Grammar and Parsing (I) November 9, 2004 Dan Jurafsky
CSC 594 Topics in AI – Natural Language Processing
CSCI 5832 Natural Language Processing
Natural Language - General
CSCI 5832 Natural Language Processing
Presentation transcript:

1 CSC 594 Topics in AI – Applied Natural Language Processing Fall 2009/ Grammar and Parsing

2 Lexical Categories: Parts-of-Speech (POS) 8 (ish) traditional parts of speech –Noun, verb, adjective, preposition, adverb, article, interjection, pronoun, conjunction, etc. Nnounchair, bandwidth, pacing Vverbstudy, debate, munch ADJadjectivepurple, tall, ridiculous ADVadverbunfortunately, slowly Pprepositionof, by, to PROpronounI, me, mine DETdeterminerthe, a, that, those

3 Language Structure and Meaning We want to know how meaning is mapped onto what language structures. Commonly in English in ways like this: [THING The dog ] is [PLACE in the garden ] [THING The dog ] is [PROPERTY fierce ] [ACTION [THING The dog ] is chasing [THING the cat ]] [STATE [THING The dog ] was sitting [PLACE in the garden ] [TIME yesterday ]] [ACTION [THING We ] ran [PATH out into the water ]] [ACTION [THING The dog ] barked [PROPERTY/MANNER loudly ]] [ACTION [THING The dog ] barked [PROPERTY/AMOUNT nonstop for five hours ]] Source: Andrew McCallum, UMass Amherst

4 Constituency Sentences have parts, some of which appear to have subparts. These groupings of words that go together we will call constituents. I hit the man with a cleaver I hit [the man with a cleaver] I hit [the man] with a cleaver You could not go to her party You [could not] go to her party You could [not go] to her party Source: Andrew McCallum, UMass Amherst

5 Constituent Phrases For constituents, we usually name them as phrases based on the word that heads the constituent: –Noun phrase – e.g. [the man], [the man [with a cleaver]] –Verb phrase – e.g. [hit the man], [hit the man with a cleaver] –Adjective phrase – e.g. [extremely significant] –Prepositional phrase – e.g. [with a cleaver], [in my room]

6 Grammar A formal specification of how a constituent should be made of and combined with other constituents (to form a larger constituent). Unlike programming languages (which are formal languages), natural languages are born without formal specifications. So, grammars for natural languages are empirically derived by observation, which is also subjective.  There are many different grammars for a given language.

7 Grammars and Sentence Structure The most common way of representing the structure of a sentence is as a tree – a syntax tree. “John ate the cake” S NPV “John”“ate” “the cake”

8 Context-Free Grammar (CFG) The most common way of specifying natural language grammars (because most natural languages are context-free in the generative capacity). Formally, a CFG consists of:

9 Grammaticality A CFG defines a formal language = the set of all sentences (strings of words) that can be derived by the grammar. Sentences in this set said to be grammatical. Sentences outside this set said to be ungrammatical. Source: Andrew McCallum, UMass Amherst

10 An Example CFG G = where N = {S, NP, NOM, VP, Det, Noun, Verb, Aux} ∑ = {that, this, a, the, man, book, flight, meal, include, read, does} S = S R = { S → NP VP Det → that | this | a | the S → Aux NP VP Noun → book | flight | meal | man S → VP Verb → book | include | read NP → Det NOM Aux → does NOM → Noun NOM → Noun NOM VP → Verb VP → Verb NP } Source: Andrew McCallum, UMass Amherst

11 Source: Andrew McCallum, UMass Amherst Parse tree (By top-down derivation)

12 Chomsky Hierarchy Source: Andrew McCallum, UMass Amherst

13 Recursive Rules, Syntactic Ambiguities S NP “John” “cake” VP V NP “ate” “the” DetN  NP PP Grammar NP VP NP S cake”" N the"" Det ate"" V John"" NP V NP VP VP PP VP         NDet NP  N  Prep NP PP  with" Prep PP Prep NP “with” N “chopsticks” chopsticks”N  " " VP S NP “John” “cake” VP V NP “ate” “the” DetN PP Prep NP “with” N “chopsticks” NP PP attachment ambiguity “John ate the cake with chopsticks”

14 Agreement Agreement is a constraint that holds between constituents to make the sentence grammatical. For example, in English, determiners and the head nouns in NPs have to agree in their number. –This flight –(*) This flights –Those flights –(*) Those flight Another example: the head nouns in the subject NPs must agree with the person of the main verb (if 3 rd person singular, present tense). –He thinks.. –(*) He think

15 Problem Our earlier NP rules are clearly deficient since they don’t capture the agreement constraints –NP  Det Nom Accepts, and assigns correct structures, to grammatical examples (this flight) But its also happy with incorrect examples (*these flight) –Such a rule is said to overgenerate  causes ambiguity

16 Verb Subcategorization English VPs consist of a head verb along with 0 or more following constituents which we’ll call arguments. –Find: Please find [a flight to NY] NP –Give: Give [me] NP [a cheaper fare] NP –Help: Can you help [me] NP [with a flight] PP –Prefer: I prefer [to leave earlier] TO-VP –Told: I was told [United has a flight] S –(*) John sneezed the book –(*) I prefer United has a flight –(*) Give with a flight Source: Jurafsky & Martin “Speech and Language Processing”

17 Possible CFG Solution Possible solution for agreement. Can use the same trick for all the verb/VP classes. SgS -> SgNP SgVP PlS -> PlNp PlVP SgNP -> SgDet SgNom PlNP -> PlDet PlNom PlVP -> PlV NP SgVP ->SgV Np … Source: Jurafsky & Martin “Speech and Language Processing”

18 CFG Solution for Agreement It works and stays within the power of CFGs But its ugly And it doesn’t scale all that well because of the interaction among the various constraints explodes the number of rules in our grammar. Source: Jurafsky & Martin “Speech and Language Processing”

19 The Point CFGs appear to be just about what we need to account for a lot of basic syntactic structure in English. But there are problems –That can be dealt with adequately, although not elegantly, by staying within the CFG framework. There are simpler, more elegant, solutions that take us out of the CFG framework (beyond its formal power) –Lexical Functional Grammar (LFG) –Head-driven Phrase Structure Grammar (HPSG) –Construction grammar –X-Tree Adjoining Grammar (XTAG) –Unification Grammar –etc. Source: Jurafsky & Martin “Speech and Language Processing”

20 Treebanks Treebanks are corpora in which each sentence has been paired with a parse tree. These are generally created –By first parsing the collection with an automatic parser –And then having human annotators correct each parse as necessary. This generally requires detailed annotation guidelines that provide a POS tagset, a grammar and instructions for how to deal with particular grammatical constructions. Source: Jurafsky & Martin “Speech and Language Processing”

21 Penn Treebank Penn TreeBank is a widely used treebank.  Most well known is the Wall Street Journal section of the Penn TreeBank.  1 M words from the Wall Street Journal. Source: Jurafsky & Martin “Speech and Language Processing”

22 Treebank Grammars Treebanks implicitly define a grammar for the language covered in the treebank. Not complete, but if you have decent size corpus, you’ll have a grammar with decent coverage. Grammar rules tend to be ‘flat’ – to avoid recursive rules. For example, the Penn Treebank has 4500 different rules for VPs. Among them... Source: Jurafsky & Martin “Speech and Language Processing”

23 Heads in Trees Finding heads in treebank trees is a task that arises frequently in many applications. –Particularly important in statistical parsing We can visualize this task by annotating the nodes of a parse tree with the heads of each corresponding node. Source: Jurafsky & Martin “Speech and Language Processing”

24 Lexically Decorated Tree Source: Jurafsky & Martin “Speech and Language Processing”

25 Head Finding The standard way to do head finding is to use a simple set of tree traversal rules specific to each non-terminal in the grammar. Source: Jurafsky & Martin “Speech and Language Processing”

26 Dependency Grammars In CFG-style phrase-structure grammars the main focus is on constituents. But it turns out you can get a lot done with just binary relations among the words in an utterance. In a dependency grammar framework, a parse is a tree where –the nodes stand for the words in an utterance –The links between the words represent dependency relations between pairs of words. Relations may be typed (labeled), or not. Source: Jurafsky & Martin “Speech and Language Processing”

27 Dependency Relations Source: Jurafsky & Martin “Speech and Language Processing”

28 Dependency Tree “They hid the letter on the shelf” Source: Jurafsky & Martin “Speech and Language Processing”

29 Dependency Parsing The dependency approach has a number of advantages over full phrase-structure parsing. –Deals well with free word order languages where the constituent structure is quite fluid –Parsing is much faster than CFG-bases parsers –Dependency structure often captures the syntactic relations needed by later applications CFG-based approaches often extract this same information from trees anyway. Source: Jurafsky & Martin “Speech and Language Processing”

30 Syntactic Parsing Grammar R0: R1: R2: R3: R4: R5: R6: R7: cake"" N the"" Det ate"" V John"" NP V VG NPVG VP N Det NP VP NP S         S VP V NP “John”“ate” “the” DetN “cake” The process of deriving the phrase structure of a sentence is called “parsing”. The process of deriving the phrase structure of a sentence is called “parsing”. The structure (often represented by a Context Free parse tree) is based on the grammar. The structure (often represented by a Context Free parse tree) is based on the grammar.

31 Parsing Algorithms Top-down Parsing -- (top-down) derivationTop-down Parsing -- (top-down) derivation Bottom-up ParsingBottom-up Parsing Chart ParsingChart Parsing Earley’s Algorithm – most efficient, O(n 3 )Earley’s Algorithm – most efficient, O(n 3 ) Left-corner Parsing – optimization of Earley’sLeft-corner Parsing – optimization of Earley’s and lots more…and lots more…

32 (Bottom-up) Chart Parsing “John ate the cake” (2) shift 2 (1) shift 1 “John” (7) shift 2 (9) reduce (10) reduce (5) shift 2 (3) shift 1 “ate”(6) shift 1 “the”(8) shift 1 “cake” (4) shift 2 (11) reduce Grammar

33 Earley’s Algorithm “John ate the cake” Grammar (2) scanner “John” (4) predictor (5) scanner “ate” (7) predictor (8) scanner “the” (9) scanner “cake” (10) completor (11) completor (1) predictor (3) predictor (6) completor (12) completor

34 Demo using my CF parser

35 Probabilistic Parsing For ambiguous sentences, we’d like to know which parse tree is more likely than others.For ambiguous sentences, we’d like to know which parse tree is more likely than others. So we must assign probability to each parse tree … but how?So we must assign probability to each parse tree … but how? A probability of a parse tree t is where r is a rule used in t.A probability of a parse tree t is where r is a rule used in t. and p(r) is obtained from a (annotated) corpus.

36 Partial Parsing Parsing fails when the coverage of the grammar is not complete – but it’s almost impossible to write out all legal syntax (without accepting ungrammatical sentences).Parsing fails when the coverage of the grammar is not complete – but it’s almost impossible to write out all legal syntax (without accepting ungrammatical sentences). We’d like to at least get pieces even when full parsing fails.We’d like to at least get pieces even when full parsing fails. Why not abandon full parsing and aim for partial parsing from the start…Why not abandon full parsing and aim for partial parsing from the start…

37 Semantic Analysis (1) Derive the meaning of a sentence. Derive the meaning of a sentence. Often applied on the result of syntactic analysis. Often applied on the result of syntactic analysis. “John ate the cake.” NP V NP NP V NP ((actionINGEST) ; syntactic verb (actorJOHN-01) ; syntactic subj (objectFOOD)) ; syntactic obj ((actionINGEST) ; syntactic verb (actorJOHN-01) ; syntactic subj (objectFOOD)) ; syntactic obj To do semantic analysis, we need a (semantic) dictionary (e.g. WordNet, To do semantic analysis, we need a (semantic) dictionary (e.g. WordNet,

38 Semantic Analysis (2) Semantics is a double-edged sword… Semantics is a double-edged sword… –Can resolve syntactic ambiguity “I saw a man on the hill with a telescope” “I saw a man on the hill with a telescope” “I saw a man on the hill with a hat” “I saw a man on the hill with a hat” –But introduces semantic ambiguity “She walked towards the bank” “She walked towards the bank” But in human sentence processing, we seem to resolve both types of ambiguities simultaneously (and in linear time)… But in human sentence processing, we seem to resolve both types of ambiguities simultaneously (and in linear time)…

39 Demo using my Unification parser