Syntax Why is the structure of language (syntax) important? How do we represent syntax? What does an example grammar for English look like? What strategies.

Slides:



Advertisements
Similar presentations
Application: Yacc A parser generator A context-free grammar An LR parser Yacc Yacc input file:... definitions... %... production rules... %... user-defined.
Advertisements

Prolog programming....Dr.Yasser Nada. Chapter 8 Parsing in Prolog Taif University Fall 2010 Dr. Yasser Ahmed nada prolog programming....Dr.Yasser Nada.
Computational language: week 10 Lexical Knowledge Representation concluded Syntax-based computational language Sentence structure: syntax Context free.
Natural Language Processing Syntax. Syntactic structure John likes Mary PN VtVt NP VP S DetPNVtVt NP VP S Every man likes Mary Noun.
Natural Language Processing - Parsing 1 - Language, Syntax, Parsing Problems in Parsing Ambiguity, Attachment / Binding Bottom vs. Top Down Parsing.
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Approaches to Parsing.
1 Grammars and Parsing Allen ’ s Chapters 3, Jurafski & Martin ’ s Chapters 8-9.
GRAMMAR & PARSING (Syntactic Analysis) NLP- WEEK 4.
For Monday Read Chapter 23, sections 3-4 Homework –Chapter 23, exercises 1, 6, 14, 19 –Do them in order. Do NOT read ahead.
Artificial Intelligence 2004 Natural Language Processing - Syntax and Parsing - Language, Syntax, Parsing Problems in Parsing Ambiguity, Attachment.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
PCFG Parsing, Evaluation, & Improvements Ling 571 Deep Processing Techniques for NLP January 24, 2011.
Context-Free Parsing. 2/37 Basic issues Top-down vs. bottom-up Handling ambiguity –Lexical ambiguity –Structural ambiguity Breadth first vs. depth first.
NLP Syntax1 Syntax The Structure of language Dave Inman.
Amirkabir University of Technology Computer Engineering Faculty AILAB Efficient Parsing Ahmad Abdollahzadeh Barfouroush Aban 1381 Natural Language Processing.
1 Introduction to Computational Linguistics Eleni Miltsakaki AUTH Spring 2006-Lecture 4.
Natural Language Query Interface Mostafa Karkache & Bryce Wenninger.
1 CONTEXT-FREE GRAMMARS. NLE 2 Syntactic analysis (Parsing) S NPVP ATNNSVBD NP AT NNthechildrenate thecake.
1 Introduction: syntax and semantics Syntax: a formal description of the structure of programs in a given language. Semantics: a formal description of.
Artificial Intelligence 2004 Natural Language Processing - Syntax and Parsing - Language Syntax Parsing.
LING 364: Introduction to Formal Semantics Lecture 5 January 26th.
LING 388: Language and Computers Sandiway Fong Lecture 13: 10/10.
Context-Free Grammar CSCI-GA.2590 – Lecture 3 Ralph Grishman NYU.
1 Basic Parsing with Context Free Grammars Chapter 13 September/October 2012 Lecture 6.
(2.1) Grammars  Definitions  Grammars  Backus-Naur Form  Derivation – terminology – trees  Grammars and ambiguity  Simple example  Grammar hierarchies.
The syntax of language How do we form sentences? Processing syntax. Language and the brain.
11 CS 388: Natural Language Processing: Syntactic Parsing Raymond J. Mooney University of Texas at Austin.
PARSING David Kauchak CS457 – Fall 2011 some slides adapted from Ray Mooney.
The Language Instinct Talking Heads.
ITEC 380 Organization of programming languages Lecture 2 – Grammar / Language capabilities.
1 CS 385 Fall 2006 Chapter 14 Understanding Natural Language (omit 14.4)
October 2008csa3180: Setence Parsing Algorithms 1 1 CSA350: NLP Algorithms Sentence Parsing I The Parsing Problem Parsing as Search Top Down/Bottom Up.
For Friday Finish chapter 23 Homework: –Chapter 22, exercise 9.
LING 388: Language and Computers Sandiway Fong Lecture 7.
CS : Speech, Natural Language Processing and the Web/Topics in Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 12: Deeper.
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Parsing with Context Free Grammars.
October 2005csa3180: Parsing Algorithms 11 CSA350: NLP Algorithms Sentence Parsing I The Parsing Problem Parsing as Search Top Down/Bottom Up Parsing Strategies.
Parsing I: Earley Parser CMSC Natural Language Processing May 1, 2003.
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
PARSING David Kauchak CS159 – Spring 2011 some slides adapted from Ray Mooney.
11 Chapter 14 Part 1 Statistical Parsing Based on slides by Ray Mooney.
For Wednesday Read chapter 23 Homework: –Chapter 22, exercises 1,4, 7, and 14.
November 2011CLINT-LN CFG1 Computational Linguistics Introduction Context Free Grammars.
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.
Quick Speech Synthesis CMSC Natural Language Processing April 29, 2003.
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:
csa3050: Parsing Algorithms 11 CSA350: NLP Algorithms Parsing Algorithms 1 Top Down Bottom-Up Left Corner.
1 Introduction to Computational Linguistics Eleni Miltsakaki AUTH Spring 2006-Lecture 2.
Natural Language Processing Slides adapted from Pedro Domingos
1 Introduction to Computational Linguistics Eleni Miltsakaki AUTH Fall 2005-Lecture 3.
NATURAL LANGUAGE PROCESSING
NLP. Introduction to NLP #include int main() { int n, reverse = 0; printf("Enter a number to reverse\n"); scanf("%d",&n); while (n != 0) { reverse =
November 2004csa3050: Parsing Algorithms 11 CSA350: NLP Algorithms Parsing Algorithms 1 Top Down Bottom-Up Left Corner.
CS : Language Technology for the Web/Natural Language Processing Pushpak Bhattacharyya CSE Dept., IIT Bombay Parsing Algos.
PARSING David Kauchak CS159 – Fall Admin Assignment 3 Quiz #1  High: 36  Average: 33 (92%)  Median: 33.5 (93%)
Formal grammars A formal grammar is a system for defining the syntax of a language by specifying sequences of symbols or sentences that are considered.
10/31/00 1 Introduction to Cognitive Science Linguistics Component Topic: Formal Grammars: Generating and Parsing Lecturer: Dr Bodomo.
Basic Parsing with Context Free Grammars Chapter 13
SYNTAX.
CS : Speech, NLP and the Web/Topics in AI
CKY Parser 0Book 1 the 2 flight 3 through 4 Houston5 11/16/2018
CS 388: Natural Language Processing: Syntactic Parsing
Natural Language - General
Parsing and More Parsing
CSA2050 Introduction to Computational Linguistics
Parsing I: CFGs & the Earley Parser
David Kauchak CS159 – Spring 2019
Presentation transcript:

Syntax Why is the structure of language (syntax) important? How do we represent syntax? What does an example grammar for English look like? What strategies exist to find the structure in natural language? A Prolog program to recognise English sentences

Pattern matching as an alternative (eg. Eliza) This uses a database of input output pairs. The input part of pair is a template to be matched against the user input The output part of the pair is given as a response. X computers Y => Do computers interest you? X mother Y => Tell me more about your family? But… Nothing is known about structure (syntax) I X you => Why do you X me? Fine for X = like, but not for X = do not know Nothing is known about meaning (semantics) I feel X => I'm sorry you feel X. Fine for X = depressed, but not for X = happy

Syntax shows the role of words in a sentence. John hit Sue vs Sue hit John Here knowing the subject allows us to know what is going on.

Syntax shows how words are related in a sentence. Visiting aunts ARE boring. vs Visiting aunts IS boring. Subject verb agreement allows us to disambiguate here.

Syntax shows how words are related between sentences. (a) Italy was beating England. Germany too. (b) Italy was being beaten by England. Germany too. Here missing parts of a sentence does not allow us to understand the second sentence. But syntax allows us to see what is missing.

But syntax alone is not enough Visiting museums can be boring This is not ambiguous for us, as we know there is no such thing as a "visiting museum", but syntax cannot show this to a computer. Compare with… Visiting aunts can be boring

How do we represent syntax? Parse Tree

How do we represent syntax? List Sue hit John [ s, [np, [proper_noun, Sue] ], [vp, [v, hit], [np, [proper_noun, John] ]

What does an example grammar for English look like? Re-write rules  sentence -> noun phrase, verb phrase  noun phrase -> art, noun  noun phrase -> art, adj, noun  verb phrase -> verb  verb phrase -> verb, noun phrase

Chomsky Hierarchy 0 Unrestricted  A    1 Context-Sensitive| LHS |  | RHS | 2 Context-Free|LHS | = 1 3 Regular|RHS| = 1 or 2, A  a | aB | Ba

What Makes a Good Grammar? Generality Selectivity Understandability

Generality of Grammars Regular {abd, ad, bcd, b, abcd, …} S -> a S1 | b S2 | c S3 | d S1 -> b S2 | c S3 | d S2 -> c S3 | d S3 -> d Context Free {a n b n } S -> ab | a S b Context Sensetive { anbncn} or {abcddabcdd, abab, asease, …}

Matching Constituents * I ate hamburger and on the Stove * I ate a cold hot dog and well burned * I ate hot dog slowly and a hamburger John hitting of Mary alarmed Sue I cannot explain John hitting of Mary Sue was alarmed by John hitting of Mary

Testing Constituents 1) I looked up John’s phone number 2) I looked up John’s chimney * I looked up John’s phone number and in the cupboard I looked up John’s chimney and in his cupboard * up John’s phone number, I looked up john’s chimney, I looked

An example: Parsing sentence: "They are cooking apples."

Parse 1

Parse 2

What strategies exist for trying to find the structure in natural language? Top Down vs. Bottom Up Bottom - Up John, hit, the, cat prpn, hit, the, cat prpn, v, the, cat prpn, v, det, cat prpn, v, det, n np, v, det, n np, v, np np, vp s Better if many alternative rules for a phrase Worse if many alternative terminal symbols for each word Top - Down s s -> np, vp s -> prpn, vp s -> John, v, np s -> John, hit, np s -> John, hit, det,n s -> John, hit, the,n s -> John, hit, the,cat Better if many alternative terminal symbols for each word Worse if many alternative rules for a phrase

Top down parsing 1 The 2 dog 3 cried 4 Step Current stateBackup States comment 1((S) 1)initial position 2((NP VP) 1)Rule 1 3((ART N VP) 1)Rules 2 & 3 ((ART ADJ N VP) 1) 4((N VP) 2)Match Art with the ((ART ADJ N VP) 1) 5((VP) 3)Match N with dog ((ART ADJ N VP) 1) 6((V) 3)Rules 5 & 6 ((V NP) 3) ((ART ADJ N VP) 1) 7Success

Parsing as a search procedure 1. Select the first state from the possibilities list (and remove it from the list). 2. Generate the new states by trying every possible option from the selected state (there may be none if we are on a bad path). 3. Add the states generated in step 2 to the possibilities list

What strategies exist for trying to find the structure in natural language? Depth First vs. Breadth First Depth First Try rules one at a time and back track if you get stuck Easier to program Less memory required Good if parse tree is deep Breadth First Try all rules at the same time Can be faster Order of rules is not important Good if tree is flat

An Example of Top-Down Parsing 1 The 2 old 3 man 4 cried 5

Depth First Search versus Breadth First

What strategies exist for trying to find the structure in natural language? Left - Right vs. Right – Left Left - Right Take words from left to right Take rule constituents from left to right Right - Left Take words from right to left Take rule constituents from right to left Left - Right usually best for a language like English where subject comes before verb ; good for subject - verb agreement; speech & real time input is L->R; closer to human processing. We have trouble with "Have the students given their assignments by their lecturers" for this reason.

What strategies exist for trying to find the structure in natural language? A simple Prolog parser's strategy Top Down Prolog tries to satisfy the query "Is this a sentence?" and works top down in a search for resolution of this query. Depth first Prolog's in built search strategy is depth first, so a simple parser uses this. L->R The grammar rules are taken from left to right, and so are the words of phrases / sentences as Prolog tries to match them against the grammar rules.

What does a Prolog program look like that tries to recognise English sentences? s --> np vp. np --> det n. np --> det adj n. vp --> v np.

What does a Prolog program look like that tries to recognise English sentences? sentence(S) :- noun_phrase(NP), verb_phrase(VP), append(NP,VP,S). noun_phrase(NP) :- determiner(D),noun(N),append(D,N,NP). noun_phrase(NP) :- determiner(D),adj(A),noun(N),append(D,A,AP),appen d(AP,N,NP). verb_phrase(VP) :- verb(V), noun_phrase(NP), append(V,NP,VP). determiner([D]) :- member(D,[the,a,an]). noun([N]) :- member(N,[cat,dog,mat,meat,fish]). adj([A]) :- member(A,[big,fat,red]). verb([V]) :- member(V,[ate,saw,killed,pushed]).