NLP Syntax1 Syntax The Structure of language Dave Inman.
-
date post
19-Dec-2015 -
Category
Documents
-
view
232 -
download
1
Transcript of NLP Syntax1 Syntax The Structure of language Dave Inman.
NLP Syntax 2
1. Outline
Why is the structure of language (syntax) important?
What knowledge is required to understand natural language?
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
NLP Syntax 3
2. Why is the structure of language (syntax) important?
Consider an alternative (ELIZA)that uses no structure
http://www-ai.ijs.si/eliza-cgi-bin/eliza_script
See if you can work out1.What it does well2.What is does badly3.What kinds of patterns it looks for in your input
NLP Syntax 4
2.1. 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.
Very flexibleAccepts non grammatical utterances for example. X computers Y => Do computers interest you?X mother Y => Tell me more about your family?
This is easy to programA couple of pages of Prolog code for example.
NLP Syntax 5
2.1. Pattern matching as an alternative (eg. Eliza)
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.
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
Conclusion : We need both syntax & semantics to understand natural language.
NLP Syntax 6
2.2. 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.
NLP Syntax 7
2.3. 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.
NLP Syntax 8
2.4. 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 ellipsis (missing parts of a sentence) does not allow us to understand the second sentence.
But syntax allows us to see what is missing.
NLP Syntax 9
2.5. 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
NLP Syntax 10
3. What knowledge is required to understand natural language?
SyntaxWhat is the difference between…Flying planes ARE dangerousFlying planes IS dangerous
SemanticsMeaning of words / phrases/ sentences/ whole texts. The sentence “She ran to the bank”is ambiguous. Compare: She owed him £50 so.....she ran to the bank.Her son fell over by the river so...she ran to the bank.
NLP Syntax 11
3. What knowledge is required to understand natural language?
PragmaticsHow language is used. The sentence: Can you open the door…could be: A polite requestA question
Which is it more likely to be? Why?
NLP Syntax 12
3. Errors to show knowledge needed for NLP
Signs in a restaurant
The manager has personally passed all the water served here.
Our wines leave you nothing to hope for.
Closing down thanks to all our customers.
We highly recommend the restaurant tart.
NLP Syntax 13
3. Errors to show knowledge needed for NLP
Signs in a hotel You are invited to take advantage of the
chambermaid.
Please to bathe inside the tub.
Please leave your values at the front desk.
If this is your first visit to the U.S.S.R. you are welcome to it.
Customers should note that any complaints about rudeness in the staff will be dealt with very severely.
NLP Syntax 14
3. Errors to show knowledge needed for NLP
Signs in a dry cleaners Drop your trousers here for best results.
If we have failed you in any way we shall be happy to do it again.
Gent’s trousers slashed.
Ladies: leave your clothes here and spend the afternoon having a good time.
NLP Syntax 15
3. Errors to show knowledge needed for NLP
Various Signs We take your bags and send them in all directions
(airline).
Correctly English in 100 days (book).
Don’t handle the fruit. Ask for Debbie (UK greengrocer).
Why not rent out a movie for a dull evening (video shop).
NLP Syntax 17
4. How do we represent syntax?
4.2. List
Sue hit John [ s, [np, [proper_noun, Sue] ] , [vp, [v, hit], [np, [proper_noun, John] ]
NLP Syntax 18
5. What does an example grammar for English look like?
5.1. Re-write rules
sentence -> noun phrase , verb phrase noun phrase -> noun noun phrase -> determiner , noun verb phrase -> verb , noun phrase
NLP Syntax 19
5. What does an example grammar for English look like?
5.2. Transition networks
Not so popular now, but used in the past with ATN parsers for example. They show how to traverse a sentence with allowable structures:
NLP Syntax 23
7. What strategies exist for trying to find the structure in natural language?
7.1. Top Down vs. Bottom Up
Bottom - Up John, hit, the, catprpn, hit, the, catprpn, v, the, catprpn, v, det, catprpn, v, det, nnp, v, det, nnp, v, npnp, vpsBetter if many alternative rules for a phraseWorse if many alternative terminal symbols for each word
Top - Downss -> np, vps -> prpn, vps -> John, v, nps -> John, hit, nps -> John, hit, det,ns -> John, hit, the,ns -> John, hit, the,cat
Better if many alternative terminal symbols for each wordWorse if many alternative rules for a phrase
NLP Syntax 24
7. What strategies exist for trying to find the structure in natural language?
7.2. Depth First vs. Breadth First
Depth First Try rules one at a time and back track if you get stuck Easier to programLess memory requiredGood if parse tree is deep
Breadth First Try all rules at the same time Can be fasterOrder of rules is not importantGood if tree is flat
NLP Syntax 25
7. What strategies exist for trying to find the structure in natural language?
7.3. 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.
NLP Syntax 26
7. What strategies exist for trying to find the structure in natural language?
7.4. A simple Prolog parser's strategy
Top DownProlog tries to satisfy the query "Is this a sentence?" and works top down in a search for resolution of this query. Depth firstProlog's in built search strategy is depth first, so a simple parser uses this.L->RThe 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.
NLP Syntax 27
8. 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.
NLP Syntax 28
8. 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),append(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]).