41
1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

Embed Size (px)

Citation preview

Page 1: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

1

Natural Language Processing

Lecture 5 : Syntax :The analysis of sentence structure

Page 2: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

2

Definition of Syntax

• Syntax is the study of the rules governing the way words are combined to form sentences in a language. *garden the *Children are *Work in

• This class: what syntactic structure is and what the rules that determine syntactic structure are like.

Page 3: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

3

Syntax

• Properties of syntactic knowledge: Humans can understand & produce an infinite

number of sentences they never heard before “Some purple gnats are starting to tango on microwave”

Our grammar can understand and produce long sentences “Bill said that he thought that the esteemed leader of the

house had it in mind to tell the unfortunate vice president that the calls that he made from the office in the White House that he thought was private…..”

Determine the grammatical relations in a sentence Mary hired Bill. Vs. Bill hired Mary

Page 4: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

4

Definition of Grammar

A formal grammar consists of:• a finite set of production rules (left-hand side  right-

hand side) where each side consists of a sequence of the following symbols:

• a finite set of non terminal symbols (indicating that some production rule can yet be applied)

• a finite set of terminal symbols  (indicating that no production rule can be applied)

• a start symbol (a distinguished non terminal symbol)• A formal grammar defines (or generates) a formal

language, which is a (usually infinite) set of finite-length sequences of symbols (i.e. strings) that may be constructed by applying production rules

Page 5: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

5

Definition of Grammar

• A rule may be applied to a sequence of symbols by replacing an occurrence of the symbols on the left-hand side of the rule with those that appear on the right-hand side.

• A sequence of rule applications is called a derivation. Such a grammar defines the formal language: all words consisting solely of terminal symbols which can be reached by a derivation from the start symbol.

• Non terminals are often represented by uppercase letters, terminals by lowercase letters, and the start symbol by S .

Page 6: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

6

Definition of Grammar

•  For example, the grammar with terminals {a,b} , non terminals  {S,A,B}, production rules

 

• and start symbol S , defines the language of all words of the form   (i.e.  n copies of a  followed by  copies of b )

Page 7: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

7

Definition of Grammar

Page 8: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

8

Generative Grammar

• Noam Chomsky 1950s • Generative = a very explicit

system of rules specifying what combinations of basic elements result in well-formed sentences.

• Defines the syntactic structure of a language.

Page 9: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

9

Generative Grammar

• “all and only”= all grammatical sentences and only grammatical sentences

• Finite rules infinite number of well-formed sentences

• Productivity of language Phrase structure rules Transformational rules

Page 10: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

10

Grammar Hierarchy

• Type-3 grammars (regular grammars) generate the regular languages. Such a grammar restricts its rules to a single non terminal on the left-hand side and a right-hand side consisting of a single terminal, possibly followed by a single non terminal (right regular)

• Type-2 grammars (context-free grammars) generate the context-free languages. These are defined by rules of the form   with  A a non terminal and   a string of terminals and non terminals.

• Type-1 grammars (context-sensitive grammars) generate the context-sensitive languages. These grammars have rules of the form  with  A a non terminal and      strings of terminals and non terminals. The strings   and   may be empty, but   must be nonempty.

Page 11: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

11

Grammar Hierarchy

• Type-0 grammars (unrestricted grammars) include all formal grammars.

Page 12: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

12

Grammar Hierarchy

Page 13: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

13

Phrase structure rules

• Some words seem to belong together: {The crazy man} {is jumping off the bridge}

• Groups of words that belong together are called constituents

• The component that determines the properties of the constituent is the head, and the constituent can be referred to as a phrase: e.g. noun phrase

Page 14: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

14

Phrase Structure Rules

• If we look at phrases, some patterns emerge:Det N

• the instructor = NPDet N

• a friend = NPDet N

• some homework = NPDet N

• two classes = NP

Page 15: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

15

Phrase Structure Rules

• some more patterns:V Det N

• call the instructor= VPV Det N

• meet a friend = VPV Det N

• do some homework = VPV Det N

• skip two classes = VP

Page 16: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

16

PSR

• and yet more patterns:Prep Det N

• with the instructor= PPPrep Det N

• from a friend = PPPrep Det N

• with some homework = PPPrep Det N

• after two classes = PP

Page 17: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

17

PSR

• Rules for determining the structure of phrases

• Generate a lot of sentences from a small number of rules.

• The structure of a phrase will consist of one or more constituents in a certain order.

• What does a NP consist of? “noun phrases have a Det and a N”

NP Det N

Page 18: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

18

Lexical Rules

• We need lexical rules to specify which words can be used when we rewrite constituents such as N. PN {Mary, George} N {girl, boy, dog} Art Pro

Page 19: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

19

PSR

• V Det N V Det N V Det Nrun a marathon eat the food read the book

• V Prep Det N V Prep Det Ngo to the store talk with a teacher

V Det N Prep Det Ntake your sister to the library

• “Verb phrases have a V, (sometimes) an NP, and (sometimes) a PP”

• VP -> V (NP) (PP)

Page 20: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

20

The main phrase structure rules

1. S NP VP

2. NP {Det N, Pro, PN}

3. VP V (NP) (PP) (Adv)

4. PP P NP

5. AP A (PP)

Page 21: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

21

Phrase Structure Rules & tree diagrams

• NP (Det) N • PP P NP

The boy (NP)

The

NDet

boy

the boy in the yard

NP

The

NDet

boy

PP

in

NPP

the

Det N

yard

Page 22: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

22

Phrase Structure Rules

• VP V (NP) (PP)• S NP VP

took the money (VP)

took

NPV

took the money from the bank

VP

took

NPV PP

from

NPP

the

Det N

bank

the

Det N

money

the

Det N

money

Page 23: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

23

Example (1)The old tree swayed in the

wind

old

V PP

in

NPP

the

Det N

windThe

N

swayed

S

NP VP

Det Adj

tree

Page 24: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

24

Example (2)The children put the toy in the

box

V PP

in

NPP

the

Det N

boxThe

N

put

S

NP VP

Det

children

NP

the

Det N

toy

Page 25: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

25

Example 3

Page 26: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

26

Back to Generative Grammar

• How superficially different sentences are closely related?

• How superficially similar sentences are different?

Page 27: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

27

Deep and surface structure

• The deep structure is an abstract level of structural organization in which all the elements determining structural interpretation are represented. Sentences that have alternative interpretations Sentences that have different surface forms

but have the same underlying meaning.

• Surface structure= how the sentence is actually represented

Page 28: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

28

Deep and surface structure

• How superficially different sentences are closely related? Charlie broke the window. The window was broken by Charlie Charlie who broke the window. Was the window broken by Charlie?

Difference in their surface structure = difference in syntactic forms

BUT they have the same ‘deep’ or underlying structure

Page 29: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

29

Structural ambiguity

• How superficially similar sentences are different? (multiple meanings)

• E.g. Annie whacked the man with an umbrella

• Same surface structure but different deep structure The boy saw the man with a telescope

• The question is: What is the scope of "with the telescope"? Does it modify only "the man" or does it modify "saw the man"?

Page 30: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

30

Structural Ambiguity (1)

The boy saw the man with the telescope

V PP

with

NPP

the

Det N

telescopeThe

N

saw

S

NP VP

Det

boy

NP

the

Det N

man

Meaning: Using the telescope, the boy saw the man

Page 31: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

31

Structural Ambiguity (2)

The boy saw the man with the telescope

V

PP

with

NPP

the

Det N

telescopeThe

N

saw

S

NP VP

Det

boy

NP

the

Det N

man

Meaning: The boy saw the man. The man had a telescope.

Page 32: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

32

Recursion

• Rules can be applied more than once in generating sentences

• E.g. repeat prepositional phrase more than once The gun was on the table near the window in the

bedroom in the pink house• Put sentences inside sentences

This is the cat that ate the rat that ate the cheese that was sold by the man that lived in the city that was on the river…

• No end to recursion- produce longer complex sentences

Page 33: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

33

Back to recursion

• [Mary helped George]. (A sentence)• [Cathy knew] that [Mary helped

George].(a sentence within a sentence)

• [John believed] that [Cathy knew] that [Mary helped George].

• The word that introduces the complement phrase

Page 34: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

34

Complement Phrases

• Cathy knew that Mary helped George• That = complementizer (C)

introducing complement phrase (CP)• The CP comes after the VP• S NP VP• VP V CP• CP C S

Page 35: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

35

Complement Phrases

Page 36: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

36

Transformational Rules

• Phrase structure rules represent ‘deep’ structure- always generate structures with fixed word order.

• Mary saw George recently Recently Mary saw George

• Transformational rules= take a specific part and attach it in another place

• You will help Cathy• Will you help Cathy?

Page 37: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

37

Transformational Rules

Page 38: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

38

Exercises

• Rewrite the following sentences with Phrase Structure Rules.  Hint: Locate your principal NP and VP before beginning.

a)  Miriam swims. b)  The dog is barking. c)  Peter told the truth. d)  The wicked witch spilled the potion. e)  The runner with the best time won the prize.

Page 39: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

39

Exercises

• Draw a labeled tree diagram for the following English phrases. (Hint: what part of speech is the leader for the phrase?)

a.  ancient pyramids b.  in the early evening c.  Drove a car

Page 40: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

40

Exercises

• Draw phrase structure trees for the following sentences: The puppy found the child The ice melted The hot sun melted the ice. The house on the hill collapsed in the

wind. The boat sailed up the river. A girl laughed at the monkey.

Page 41: 1 Natural Language Processing Lecture 5 : Syntax :The analysis of sentence structure

41

• Draw two phrase structure trees representing the two meanings of the sentence:

The magician touched the child with the wand.

Exercises