56
Natural Language Processing Pushdown Automata & Recursive Transition Networks Vladimir Kulyukin vkedco.blogspot.com

NLP (Fall 2013): Recursive & Augmented Transition Networks

Embed Size (px)

Citation preview

Page 1: NLP (Fall 2013): Recursive & Augmented Transition Networks

Natural Language Processing

Pushdown Automata

&

Recursive Transition Networks

Vladimir Kulyukin

vkedco.blogspot.com

Page 2: NLP (Fall 2013): Recursive & Augmented Transition Networks

Outline

Pushdown Automata (aka Stack Machines)

Recursive Transition Networks

Page 3: NLP (Fall 2013): Recursive & Augmented Transition Networks

Pushdown Automata (PDA)

(aka Stack Machines)

Page 4: NLP (Fall 2013): Recursive & Augmented Transition Networks

Finite

Control

Input Tape

Stack

PDA

Page 5: NLP (Fall 2013): Recursive & Augmented Transition Networks

read pop push

a c abc

If the current input symbol is a and the symbol on top of the stack is

c, pop c off the stack, push abc onto the stack, and advance to the

next symbol (move right). Reading a symbol means seeing it in the

input and advancing to the next symbol.

Stack Machine Move

Page 6: NLP (Fall 2013): Recursive & Augmented Transition Networks

read pop push

a c b

a c

d

Input Tape Stack

Stack Machine Move Example 01

Page 7: NLP (Fall 2013): Recursive & Augmented Transition Networks

a c

d

Read a & Move

one cell right

Input Tape Stack

read pop push

a c b

Stack Machine Move Example 01: READ

Page 8: NLP (Fall 2013): Recursive & Augmented Transition Networks

read pop push

a c b

a

d

POP c OFF Sack

Input Tape Stack

Stack Machine Move Example 01: POP

Page 9: NLP (Fall 2013): Recursive & Augmented Transition Networks

a b

d

PUSH b ONTO Stack

Input Tape Stack

read pop push

a c b

Stack Machine Move Example 01: PUSH

Page 10: NLP (Fall 2013): Recursive & Augmented Transition Networks

Pushdown Automata

&

Non-Determinism

Page 11: NLP (Fall 2013): Recursive & Augmented Transition Networks

A stack machine is like NFA, because it

may have multiple sequences of moves on

the same input

A stack machine accepts iff the input has

been read and the stack is empty

Stack Machine Non-Deterministic Acceptance

Page 12: NLP (Fall 2013): Recursive & Augmented Transition Networks

read pop push

ε S ab

a S ef

a S ε

Stack Machine Example 02

Page 13: NLP (Fall 2013): Recursive & Augmented Transition Networks

Suppose the input is a

The initial stack contains S

We have three possible move sequences:

Sequence 1: no input is read, pop S, push ab

Sequence 2: read a, pop S, push ef

Sequence 3: read a, pop S, push ε

Stack Machine Example 02

Page 14: NLP (Fall 2013): Recursive & Augmented Transition Networks

Stack Machine Construction

Page 15: NLP (Fall 2013): Recursive & Augmented Transition Networks

Construct a stack machine for {anbn}

Problem

Page 16: NLP (Fall 2013): Recursive & Augmented Transition Networks

If a is read, pop off S, push 1, and push S

In the middle of the string, pop off S

If b is read, pop 1 off the stack

If the stack is empty, that means we have read

some number of a’s (pushing) followed by the same

number of b’s (popping)

Basic Insight

Page 17: NLP (Fall 2013): Recursive & Augmented Transition Networks

read pop push

a S S1

ε S ε

b 1 ε

Stack Machine Table

Page 18: NLP (Fall 2013): Recursive & Augmented Transition Networks

a S a a b b b

Read a; Pop S; Push 1; Push S; Move Right

Processing Sample Input

Page 19: NLP (Fall 2013): Recursive & Augmented Transition Networks

a S

1 a a b b b

Read a; Pop S; Push 1; Push S; Move Right

Processing Sample Input

Page 20: NLP (Fall 2013): Recursive & Augmented Transition Networks

a

S

1

1 a a b b b

Read a; Pop S; Push 1; Push S; Move Right

Processing Sample Input

Page 21: NLP (Fall 2013): Recursive & Augmented Transition Networks

a

S

1

1

1 a a b b b

1. PDA has reached the break point so

it needs to start popping

2. Read ε; Pop S; Push ε; Stay on b

Processing Sample Input

Page 22: NLP (Fall 2013): Recursive & Augmented Transition Networks

a

1

1

1 a a b b b

Read b; Pop 1; Push ε; Move Right

Processing Sample Input

Page 23: NLP (Fall 2013): Recursive & Augmented Transition Networks

a

1

1 a a b b b

Read b; Pop 1; Push ε; Move Right

Processing Sample Input

Page 24: NLP (Fall 2013): Recursive & Augmented Transition Networks

a

1 a a b b b

Read b; Pop 1; Push ε; Move Right

Processing Sample Input

Page 25: NLP (Fall 2013): Recursive & Augmented Transition Networks

a a a b b b

End of Input Tape is Reached;

Stack is Empty;

Input is Accepted by Empty Stack

Processing Sample Input

Page 26: NLP (Fall 2013): Recursive & Augmented Transition Networks

(x, y) where x ϵ Σ* is the unread part of the input

and y ϵ Γ* is the contents of the stack, where the leftmost character of y is on top of the stack.

Instantaneous Description

Page 27: NLP (Fall 2013): Recursive & Augmented Transition Networks

→ is a relation on instantaneous descriptions

such that

1. (ax, Bz) → (x, yz) iff y is in δ(a, B)

2. (x, Bz) → (x, yz) iff y is in δ(ε, B)

One-Step Derivation

Page 28: NLP (Fall 2013): Recursive & Augmented Transition Networks

→* is a relation on instantaneous descriptions

such that if A & B are two instantaneous

descriptions, then A →* B iff there is sequence

of zero or more → transitions that start at A

and end at B

Multi-Step Derivation

Page 29: NLP (Fall 2013): Recursive & Augmented Transition Networks

L(M) = {x is in Σ* | (x, S) →* (ε, ε)}

Acceptance by Empty Stack

Page 30: NLP (Fall 2013): Recursive & Augmented Transition Networks

Conversion of FA to PDA

Page 31: NLP (Fall 2013): Recursive & Augmented Transition Networks

We can construct an FA for a regular language

We can construct a regular grammar from an NFA

Regular grammars are context-free grammars

It is no surprise that we can construct stack machines

from finite automata

FAs to SMs

Page 32: NLP (Fall 2013): Recursive & Augmented Transition Networks

q0 q1

q2 q3

0

1

0

1

1

1

0

0

FAs to SMs

Page 33: NLP (Fall 2013): Recursive & Augmented Transition Networks

3

2

33

23

12

02

31

21

10

00

,

,

,1

,0

,1

,0

,1

,0

,1

,0

q

q

qq

qq

qq

qq

qq

qq

qq

qq read pop push

0 q0 q0

1 q0 q1

0 q1 q2

1 q1 q3

0 q2 q0

1 q2 q1

0 q3 q2

1 q3 q3

ε q2 ε

ε q3 ε

FAs to SMs

Page 34: NLP (Fall 2013): Recursive & Augmented Transition Networks

Conversion of CFGs to PDA

Page 35: NLP (Fall 2013): Recursive & Augmented Transition Networks

., ,a allfor .2

;|v, , allfor 1.

:follows as defined

is where,,, :Sketch Proof

.such that machinestack

a is thereCFG, a is ,,, If :Theorem

aa

PxvxVv

S,VM

MLGLM

PSV G

Conversion Theorem

Page 36: NLP (Fall 2013): Recursive & Augmented Transition Networks

Let us convert this CFG to SM:

S → aSa

S → bSb

S → ε

Example

Page 37: NLP (Fall 2013): Recursive & Augmented Transition Networks

read pop push

ε S aSa

ε S bSb

ε S ε

a a ε

b b ε

Example

Page 38: NLP (Fall 2013): Recursive & Augmented Transition Networks

Recursive Transition Networks

Page 39: NLP (Fall 2013): Recursive & Augmented Transition Networks

Recursive Transition Networks

A Recursive Transition Network (RTN) is a

directed graph with labeled states and arcs

Arc labels are state names (variables) and

terminal symbols

There is a unique state called start state and

a set of states called final states

Page 40: NLP (Fall 2013): Recursive & Augmented Transition Networks

RTN Arc Execution

The arc execution is as follows: suppose there is an arc

from A to B labeled L

If the arc is followed, then B is pushed onto the

pushdown stack and control jumps to state L without

advancing the input tape pointer if L is non-terminal or

with advancing the input tape pointer if L is terminal

When a final state of some network is reached, the

pushdown stack containing the name of that network may

be popped

When the stack is empty and the end of the input is

reached, the RTN accepts the input

Page 41: NLP (Fall 2013): Recursive & Augmented Transition Networks

RTN Example

Page 42: NLP (Fall 2013): Recursive & Augmented Transition Networks

Recursive Transition Network: Subnetwork S

S

Q1

Q2

Q3 Q4/1 Q5/1

NP

AUX

V

AUX

V NP

PP

1. S is start state

2. Q4/1 and Q5/1 are final states

NP

Page 43: NLP (Fall 2013): Recursive & Augmented Transition Networks

Categories & Terminals

DET a | the

N robot | bot | room

V work | clean | run

ADJ small | large

AUX can | does

PREP in | at

NPR RG | R2D2 | BOT_103

Page 44: NLP (Fall 2013): Recursive & Augmented Transition Networks

Categories & Terminals

DET a | the

N robot | bot | room

V work | clean | run

ADJ small | large

AUX can | does

PREP in | at

NPR RG | R2D2 | BOT_103

Page 45: NLP (Fall 2013): Recursive & Augmented Transition Networks

Categories & Terminals

DET a | the

N robot | bot | room

V work | clean | run

ADJ small | large

AUX can | does

PREP in | at

NPR RG | R2D2 | BOT_103

Page 46: NLP (Fall 2013): Recursive & Augmented Transition Networks

Recursive Transition Network: Subnetwork NP

NP Q7/1

DET N (Noun)

PP

Q6

Q8/1

NPR (Proper Name)

ADJ

1. NP is start state

2. Q7/1 and Q8/1 are

final states

Page 47: NLP (Fall 2013): Recursive & Augmented Transition Networks

Recursive Transition Network: Subnetwork PP

PP Q10/1

Prep NP

Q9

1. PP is start state

2. Q10/1 is final state

Page 48: NLP (Fall 2013): Recursive & Augmented Transition Networks

Categories & Terminals

DET a | the

N robot | bot | room

V work | clean | run

ADJ small | large

AUX can | does

PREP in | at

NPR RG | R2D2 | BOT_103

Page 49: NLP (Fall 2013): Recursive & Augmented Transition Networks

RTN Input Processing

Suppose input is “|can the small bot run” (|

is input pointer)

RTN starts in state S

RTN non-deterministically decides to execute

the AUX arc, because the category of “can” is

AUX

So, “can” is scanned, input pointer is

advanced to “the” and RTN goes to state Q2

Page 50: NLP (Fall 2013): Recursive & Augmented Transition Networks

RTN Input Processing

Current input is “can |the small bot run”

In state Q2, RTN can execute only the NP arc

So, Q3 is pushed onto the stack (to remember

which state it needs to come back to), input

pointer is not advanced, and RTN goes to state

NP

Page 51: NLP (Fall 2013): Recursive & Augmented Transition Networks

RTN Input Processing

Current input is “can |the small bot run”

In state NP, RTN non-deterministically

chooses to execute the DET arc, because the

category of “the” is DET

So, “the” is scanned, input pointer is

advanced to “small” and RTN goes to state Q6

Page 52: NLP (Fall 2013): Recursive & Augmented Transition Networks

RTN Input Processing

Current input is “can the |small bot run”

In state Q6, RTN non-deterministically

chooses to execute the ADJ arc, because the

category of “small” is ADJ

So, “small” is scanned, input pointer is

advanced to “bot” and RTN goes back to state

Q6

Page 53: NLP (Fall 2013): Recursive & Augmented Transition Networks

RTN Input Processing

Current input is “can the small |bot run”

In state Q6, RTN non-deterministically

chooses to execute the N arc, because the

category of “bot” is N

So, “bot” is scanned, input pointer is

advanced to “run” and RTN reaches a final

state Q7/1

RTN goes back to the stack, pops Q3 off the

stack, and goes to Q3

Page 54: NLP (Fall 2013): Recursive & Augmented Transition Networks

RTN Input Processing

Current input is “can the small bot |run”

In state Q3, RTN executes the V arc, because

the category of “run” is V

So, “run” is scanned, input pointer is

advanced to the end of the input, and RTN

reaches a final state Q4/1

Page 55: NLP (Fall 2013): Recursive & Augmented Transition Networks

RTN Input Processing

Current input is “can the small bot run|”

In state Q4/1, RTN accepts the input,

because

1. the stack is empty (cannot be popped);

2. the end of the input is reached;

3. Q4/1 is a final state

Page 56: NLP (Fall 2013): Recursive & Augmented Transition Networks

References & Reading Suggestions

Woods, W. A. (1970). Transition Network Grammars

for Natural Language Analysis. Communication of the

ACM, Vol 13, Number 10, October 1970

Moll, Arbib, and Kfoury. An Introduction to Formal

Language Theory