Loading in 5 sec....

LING 388 Language and ComputersPowerPoint Presentation

LING 388 Language and Computers

- By
**uta** - Follow User

- 47 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about ' LING 388 Language and Computers' - uta

**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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Administrivia

- Next Tuesday (11th)
- Veterans’ Day

- Today’s Lecture
- Homework 3 review
- Help with Homework 4

- Next time …
- We start a brand-new topic known as Shallow Parsing
- We’ll begin with Part-of-speech (POS) tagging, stemming …

- We start a brand-new topic known as Shallow Parsing

vp

v

john

died

Exercise 1 Part (B): Encoding the idiom kick the bucket- Add a DCG rule to encode the idiomatic meaning of John kicked the bucket, i.e.

s

?- s(X,[john,kicked,the,bucket],[])

X = s(np(john),vp(v(died)))

- Hint: see how the terminal string the ball was encoded in Lecture 10

np --> [the,ball].

Sample DCG

- s(s(X,Y)) --> np(X), vp(Y).
- np(np(X,Y)) --> det(X,Num), common_noun(Y,Num).
- np(np(X)) --> proper_noun(X).
- vp(vp(X)) --> intransitive_verb(X).
- vp(vp(X,Y)) --> transitive_verb(X), np(Y).
- common_noun(n(man),sg) --> [man].
- common_noun(n(men),sg) --> [men].
- proper_noun(john) --> [john].
- det(det(the),_) --> [the]. det(det(a),sg) --> [a].
- intransitive_verb(v(ran)) --> [ran].
- transitive_verb(v(saw)) --> [saw].

Exercise 4 Part (A): Implementing every and some

- Want parses:
- s(forall(X,man(X)),vp(v(likes),np(john))))
- s(exists(X,men(X)),vp(v(like),np(n(beer))))

- for
- Every man likes John
- Some men like beer

Exercise 4 Part (A): Implementing every and some

- NP rules:
- np(np(X,Y)) --> quantifier(X,Num), common_noun(Y,Num).
- quantifier(q(every),sg) --> [every].
- quantifier(q(some),_) --> [some].
- common_noun(n(man),sg) --> [man].
- common_noun(n(men),pl) --> [men].

- Solution:
- Write one rule specialized for every and another for some

Exercise 4 Part (A): Implementing every and some

- Case 1: every
- np(np(X,Y)) --> quantifier(X,Num), common_noun(Y,Num).
- quantifier(q(every),sg) --> [every].
- common_noun(n(man),sg) --> [man].

- Parsing every man will produce the following series of variable bindings:

np(np(X,Y)) --> quantifier(X,Num), common_noun(Y,Num).

quantifier(q(every),sg)

common_noun(n(man),sg)

every

man

Exercise 4 Part (A): Implementing every and some

- Perform a partial substitution; instantiate every:
- np(np(X,Y)) -->
- quantifier(q(every),Num),
- common_noun(n(N),Num).

- np(np(X,Y)) -->
- Note:
- NP rule is now particular to sequences every N
- I.e. NP rule won’t fire for other NP sequences like:
- some men
- the cat
- John

Exercise 4 Part (A): Implementing every and some

- Substitute forall for np:
- np(forall(X,Y)) -->
- quantifier(q(every),Num),
- common_noun(n(N),Num).

- np(forall(X,Y)) -->
- Finally, add code in {…} to generate Y from N:
- np(forall(X,Y)) -->
- quantifier(q(every),Num),
- common_noun(n(N),Num),
- {Y=..[N,X]}.

- np(forall(X,Y)) -->
- The same implementation strategy works also for some and exists(X,N(X)) …

Key Concepts We can build f(X) where f cannot be determined statically,

- Use partial variable substitution
- … to customize a rule

i.e. at the time we specify the grammar rule

by …

- using Prolog built-in univ (=..), and
- the DCG rule out-call mechanism {…}

Logic and Negation in Prolog

- Filter 1:
- All variables must be bound by an operator

- Implementation:
- \+ (variable(X,F), var(F))
- variable/2 is an np(x) finder
- F bound when lx can be found

- \+ (variable(X,F), var(F))
- Question:
- Why are we implementing a positive condition using negation (\+)?

Logic and Negation in Prolog

s

np

vp

np

lambda

v

np

n

det

x

s

hissed at

x

cat

the

np

vp

- *The cat that John saw hissed at

john

v

np

saw

x

Logic and Negation in Prolog

- Example:
- All tomatoes are red

- Define predicates:
tomato(X)

red(X)

- Condition:
- ?- tomato(X), red(X).
- holds if there exists some X such that X is a tomato and X is red
- Doesn’t check all the tomatoes in the box
- Hence, query does not guarantee that all the tomatoes in the box are red

- ?- tomato(X), red(X).

Logic and Negation in Prolog

- Example:
- All tomatoes are red

- Equivalent condition:
- It cannot be the case that there exists some tomato and that tomato is not red

- Implementation:
- ?- \+ ( tomato(X), \+ red(X)).
- holds if it is not the case that there exists some X such that X is a tomato and X is not red
- Guarantees that all the tomatoes in the box are red

- ?- \+ ( tomato(X), \+ red(X)).

Logic and Negation in Prolog Examples: Prolog variables?

- Basic Quantifier Conversion Rules:
- "x p(x) <=> Ø$x Øp(x)
- Ø$x p(x) <=> "x Øp(x)

- "X tomato(X), red(X)
- <=> Ø$X tomato(X), \+ red(X)

- By default, existentially quantified ($)

Logic and Negation in Prolog

- Filter 1:
- All variables must be bound by an operator

- Conversion:
- There must not exist a variable that is not bound by an operator

- Implementation:
- \+ (variable(X,F), var(F))
- variable/2 is an np(x) finder
- F bound when lx can be found

- \+ (variable(X,F), var(F))

Implementing the Exactly One Condition

- In Exercise 5 …
- Filter 2:
- All operators must bind exactly one variable

- Implementation:
- filter2(X) :- operator(X).

- Predicate:
- operator(X)
- holds if X contains a lx.Y with less than two variables in Y

- operator(X)

- Filter 2:

Implementing the Exactly One Condition

- Operator/1 calls predicate lt2vars/2:
- lt2vars(X,F)
- holds if there are less than two variables in X
- F is bound to one if there is one variable in X

- We’ll need to impose either that:
- F == one or
- \+ var(F)
to the output of lt2vars/2 to implement the condition for exactly one variable

- lt2vars(X,F)

Implementing the Universally Quantified Condition

- Not done yet …
- Filter 2:
- All operators must bind exactly one variable

- Implementation:
- filter2(X) :- operator(X).

- Predicate:
- operator(X)
- holds if X contains a lx.Y with less than two variables in Y
- I.e. if in X $ lx.Y with less than two variables in Y

- operator(X)

- Filter 2:

Implementing the Universally Quantified Condition

- Filter 2:
- All operators must bind exactly one variable

- So we must convert this to an existentially quantified condition
- Equivalently:
- In X, it cannot be the case that operator(X) holds and the number of variables bound is not one

Overlapping/Non-Overlapping Clauses

- Question:
- For tree-walkers, why do we sometimes want overlapping clauses, i.e. have more than one applicable clause, and why sometimes we don’t?

- Example:
- operator/1 is overlapping
- lt2vars/2 is non-overlapping

Case 1: Non-Overlapping Clauses

- lt2vars(np(x),F) :-
- var(F), F = one.

- lt2vars(X,F) :-
- X =.. [_,A1,A2],
- lt2vars(A1,F),
- lt2vars(A2,F).

- lt2vars(X,F) :-
- \+ X = np(x),
- X =.. [_,A],
- lt2vars(A,F).

- lt2vars(X,_) :- atom(X).

- Unary branching structure:

np(x)

matches two clauses

blocks np(x)

Want only one match!

- lt2vars(np(x),F) :-
- var(F), F = one.

- lt2vars(X,F) :-
- X =.. [_,A1,A2],
- lt2vars(A1,F),
- lt2vars(A2,F).

- lt2vars(X,F) :-
- \+ X = np(x),
- X =.. [_,A],
- lt2vars(A,F).

- lt2vars(X,_) :- atom(X).

np(x)

- Need to block the lower clause from applying
- it does not set F, and otherwise
- ?- lt2vars(X,F), var(F).
- will succeed when X has, say, three np(x)s

[Upper clause will reject 3 np(x)s, but lower clause will pass it.]

Case 2: Overlapping Clauses

- operator(lambda(x,Y)):-
- lt2vars(Y,_).

- operator(X) :-
- X =.. [_,A1,_],
- operator(A1).

- operator(X) :-
- X =.. [_,_,A2],
- operator(A2).

- operator(X) :-
- X =.. [F,A],
- operator(A).

- Binary branching structure:

lambda(x,_)

matches three clauses

Want multiple matches!

Case 2: Overlapping Clauses

lambda(x,_)

- operator(lambda(x,Y)):-
- lt2vars(Y,_).

- operator(X) :-
- X =.. [_,A1,_],
- operator(A1).

- operator(X) :-
- X =.. [_,_,A2],
- operator(A2).

- operator(X) :-
- X =.. [F,A],
- operator(A).

- operator/1 is a lx finder
- We want it to be able to find and test all lx structures within a phrase structure
- ?- operator(X). will succeed once for each lx in X

vp

np

Case 2first lx

np

v

mary

np

lambda

hit

x

s

det

n

np

vp

the

man

np

lambda

v

np

n

det

x

s

hissed at

x

cat

the

np

vp

- *Mary hit the man that the cat that John saw Mary hissed at

john

v

np

saw

mary

vp

np

Case 2first lx

np

v

mary

np

lambda

hit

x

s

det

n

np

vp

the

man

np

lambda

v

np

n

det

x

s

hissed at

x

cat

the

np

vp

- *Mary hit the man that the cat that John saw Mary hissed at

john

v

np

saw

mary

Key Concept

- We need to restrict or use overlap as appropriate
- Because of Prolog’s search strategy
- i.e. if a clause fails during a query, Prolog will look for another way to succeed

- Because of Prolog’s search strategy

Download Presentation

Connecting to Server..