Top Banner
Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011
96

Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Finite-State Automata

Shallow Processing Techniques for NLPLing570

October 5, 2011

Page 2: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

RoadmapFinite-state automata variants

Non-deterministic Finite-State Automata (NFA)

Probabilistic Finite-State Automata (PFSA)

Finite-State Transducers (FST)Intro

CARMEL

Page 3: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

FSAs FormallyA Finite-State Automaton (FSA) is a 5-tuple:

A set of states Q { q0,q1,q2,q3,q4}

A finite alphabet Σ {b,a,!}A state state q0

A set of accepting states {q4}

A transition function Q x Σ Q

Page 4: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Non-deterministic Finite-State Automata

Deterministic FSA:Given current state x input, at most one legal

transition

Page 5: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Non-deterministic Finite-State Automata

Deterministic FSA:Given current state x input, at most one legal

transition

Sources of non-determinism in NFA

Page 6: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Non-deterministic Finite-State Automata

Deterministic FSA:Given current state x input, at most one legal

transition

Sources of non-determinism in NFAMore than one transition for qi x a

Page 7: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Non-deterministic Finite-State Automata

Deterministic FSA:Given current state x input, at most one legal

transition

Sources of non-determinism in NFAMore than one transition for qi x a

ε-transitionsTransitions that consume no input

Page 8: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Non-deterministic Finite-State Automata

Deterministic FSA: Given current state x input, at most one legal transition

Sources of non-determinism in NFA More than one transition for qi x a

ε-transitionsTransitions that consume no input

Multiple start states

Transitions: Q x (Σ U ε) 2S

Page 9: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Sheeptalk NFAMultiple choice:

Page 10: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Sheeptalk NFAMultiple choice:

ε-transitions

Page 11: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

NFA & DFAWhat is the relationship b/t NFAs and DFAs?

Page 12: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

NFA & DFAWhat is the relationship b/t NFAs and DFAs?

NFAs and DFAs are equivalentAccept same languages

Page 13: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

NFA & DFAWhat is the relationship b/t NFAs and DFAs?

NFAs and DFAs are equivalentAccept same languages

Standard transformation from NFA to DFA:Create new state for each equivalence class in NFA

Page 14: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

NFA & DFAWhat is the relationship b/t NFAs and DFAs?

NFAs and DFAs are equivalentAccept same languages

Standard transformation from NFA to DFA:Create new state for each equivalence class in NFA If NFA has N states, up to 2N states in DFA

Page 15: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

NFA & DFAWhat is the relationship b/t NFAs and DFAs?

NFAs and DFAs are equivalentAccept same languages

Standard transformation from NFA to DFA:Create new state for each equivalence class in NFA If NFA has N states, up to 2N states in DFA

Why use both?

Page 16: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Managing Non-Determinism

Approaches to non-determinism

Page 17: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Managing Non-Determinism

Approaches to non-determinismBackup/backtracking:

At choice points, mark state, inputIf fail, return and try alternative

Page 18: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Managing Non-Determinism

Approaches to non-determinismBackup/backtracking:

At choice points, mark state, inputIf fail, return and try alternative

Look-ahead:Look ahead to see which choice to take

Page 19: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Managing Non-Determinism

Approaches to non-determinismBackup/backtracking:

At choice points, mark state, inputIf fail, return and try alternative

Look-ahead:Look ahead to see which choice to take

Parallelism:At choice points, consider all paths in parallel

Basically the NFA DFA conversion process

Page 20: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Recognition in NFAsTwo standard approaches:

Page 21: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Recognition in NFAsTwo standard approaches:

Transformation:Convert NFA DFAPerform standard DFA recognition

Page 22: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Recognition in NFAsTwo standard approaches:

Transformation:Convert NFA DFAPerform standard DFA recognition

Search:Explicitly model recognition as state-space searchPerform backtracking as necessary

Page 23: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Recognition in NFAFor strings in the language:

Page 24: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Recognition in NFAFor strings in the language:

There exists some state sequence leading to a final state

Page 25: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Recognition in NFAFor strings in the language:

There exists some state sequence leading to a final state

Not all paths necessarily lead to an accept state

For strings not in the language:

Page 26: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Recognition in NFAFor strings in the language:

There exists some state sequence leading to a final state

Not all paths necessarily lead to an accept state

For strings not in the language:No paths lead to an accept state

Page 27: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

NFA Recognition as SearchSearch problem:

Page 28: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

NFA Recognition as SearchSearch problem:

Start search-state(start node, beginning of input)

Page 29: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

NFA Recognition as SearchSearch problem:

Start search-state(start node, beginning of input)

Goal test(final node, end of input)

Page 30: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

NFA Recognition as SearchSearch problem:

Start search-state(start node, beginning of input)

Goal test(final node, end of input)

Successor function Transitions

Page 31: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

NFA Recognition as SearchSearch problem:

Start search-state(start node, beginning of input)

Goal test(final node, end of input)

Successor function Transitions

Path cost

Page 32: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

NFA Recognition as SearchSearch problem:

Start search-state(start node, beginning of input)

Goal test(final node, end of input)

Successor function Transitions

Path cost

Use standard search algorithmse.g. Depth-first, breadth first, A*

Page 33: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.
Page 34: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Example

Page 35: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Example

Page 36: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Example

Page 37: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Example

Page 38: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Example

Page 39: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Example

Page 40: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Example

Page 41: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Example

Page 42: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.
Page 43: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Breadth-first Search

Page 44: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Equivalences and Operations

FSAs equivalent to Regular Languages (Regex, etc)Can be shown by inductionDemonstrate primitive regex ops imitated by

automata

Page 45: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Equivalences and Operations

FSAs equivalent to Regular Languages (Regex, etc)Can be shown by inductionDemonstrate primitive regex ops imitated by

automata

Page 46: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Equivalences and Operations

FSAs equivalent to Regular Languages (Regex, etc)Can be shown by inductionDemonstrate primitive regex ops imitated by

automata

Page 47: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Equivalences and Operations

FSAs equivalent to Regular Languages (Regex, etc)Can be shown by inductionDemonstrate primitive regex ops imitated by

automata

Page 48: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Equivalences and Operations

FSAs equivalent to Regular Languages (Regex, etc)Can be shown by inductionDemonstrate primitive regex ops imitated by

automata

E.g. Concatenation

Page 49: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Equivalences and Operations

FSAs equivalent to Regular Languages (Regex, etc)Can be shown by inductionDemonstrate primitive regex ops imitated by

automata

E.g. Concatenation

Page 50: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Equivalences and Operations

Closure:

Union:

Page 51: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Equivalences and Operations

Closure:

Union:

Page 52: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Equivalences and Operations

Closure:

Union:

Page 53: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Finite-State ToolsToolkits:

AT&T Finite-State Toolkit:http://www.research.att.com/~fsmtools/fsm

NLTK: www.nltk.orgCARMEL (ISI): /NLP_TOOLS/ml_tools/FST/carmel

Page 54: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Finite-State ToolsToolkits:

AT&T Finite-State Toolkit:http://www.research.att.com/~fsmtools/fsm

NLTK: www.nltk.orgCARMEL (ISI): /NLP_TOOLS/ml_tools/FST/carmel

Functions:Convert Regex to FSAConvert FSA to RegexConvert NFA to DFAPerform operations: concatenation, disjunction, *, etc

Page 55: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Probabilistic Finite-State Automata (PFA)

Page 56: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA DefinitionA Probabilistic Finite-State Automaton is a 7-

tuple:A set of states QAn alphabet ΣA set of transitions: δsubset Q x Σ x Q

Page 57: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA DefinitionA Probabilistic Finite-State Automaton is a 7-

tuple:A set of states QAn alphabet ΣA set of transitions: δsubset Q x Σ x Q Initial state probabilities: Q R+

Page 58: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA DefinitionA Probabilistic Finite-State Automaton is a 7-

tuple:A set of states QAn alphabet ΣA set of transitions: δsubset Q x Σ x Q Initial state probabilities: Q R+

Transition probabilities: δ R+

Page 59: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA DefinitionA Probabilistic Finite-State Automaton is a 7-

tuple:A set of states QAn alphabet ΣA set of transitions: δsubset Q x Σ x Q Initial state probabilities: Q R+

Transition probabilities: δ R+

Final state probabilities: Q R+

Page 60: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA DefinitionA Probabilistic Finite-State Automaton is a 7-

tuple:A set of states QAn alphabet ΣA set of transitions: δsubset Q x Σ x Q Initial state probabilities: Q R+

Transition probabilities: δ R+

Final state probabilities: Q R+

s.t.

Page 61: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA DefinitionA Probabilistic Finite-State Automaton is a 7-

tuple:A set of states QAn alphabet ΣA set of transitions: δsubset Q x Σ x Q Initial state probabilities: Q R+

Transition probabilities: δ R+

Final state probabilities: Q R+

s.t.

Page 62: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA ExampleExample

Example due to F. Xia

Page 63: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA ExampleExample

I(q0)=1

I(q1)=0

Example due to F. Xia

Page 64: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA ExampleExample

I(q0)=1

I(q1)=0

F(q0)=0

F(q1)=0.2

Example due to F. Xia

Page 65: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA ExampleExample

I(q0)=1

I(q1)=0

F(q0)=0

F(q1)=0.2

P(q0,a,q1)=1; P(q1,b,q1) =0.8

Example due to F. Xia

Page 66: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA ExampleExample

I(q0)=1

I(q1)=0

F(q0)=0

F(q1)=0.2

P(q0,a,q1)=1; P(q1,b,q1) =0.8

P(abn)

Example due to F. Xia

Page 67: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA ExampleExample

I(q0)=1

I(q1)=0

F(q0)=0

F(q1)=0.2

P(q0,a,q1)=1; P(q1,b,q1) =0.8

P(abn) = I(q0)*P(q0,a,q1)*P(q1,b,q1)n*F(q1)

Example due to F. Xia

Page 68: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA ExampleExample

I(q0)=1

I(q1)=0

F(q0)=0

F(q1)=0.2

P(q0,a,q1)=1; P(q1,b,q1) =0.8

P(abn) = I(q0)*P(q0,a,q1)*P(q1,b,q1)n*F(q1)

= 0.8n*0.2

Example due to F. Xia

Page 69: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA ExampleExample

I(q0)=1

I(q1)=0

F(q0)=0

F(q1)=0.2

P(q0,a,q1)=1; P(q1,b,q1) =0.8

P(abn) = I(q0)*P(q0,a,q1)*P(q1,b,q1)n*F(q1)

= 0.8n*0.2

Example due to F. Xia

Page 70: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFAPFA augments NFAs with probabilities on arcs

Page 71: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFAPFA augments NFAs with probabilities on arcs

Probability of a path through PFA is product of transition probabilities (and initial/final state probs)

Page 72: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFAPFA augments NFAs with probabilities on arcs

Probability of a path through PFA is product of transition probabilities (and initial/final state probs)

Probability of a string is the sum of accepting paths.

Page 73: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFAPFA augments NFAs with probabilities on arcs

Probability of a path through PFA is product of transition probabilities (and initial/final state probs)

Probability of a string is the sum of accepting paths.

Tech. issue: Numerical underflow:

Page 74: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

PFA PFA augments NFAs with probabilities on arcs

Probability of a path through PFA is product of transition probabilities (and initial/final state probs)

Probability of a string is the sum of accepting paths.

Tech. issue: Numerical underflow: Replace product of probs with sum of log probs

Tasks: Given an input, find most probable state sequence Given an input, find its probability etc (We’ll do these when we generalize to HMMs)

Page 75: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Weighted FSASimilar to PFA

Arcs associated with weight (not probability)

Page 76: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Finite-State Transducers

Page 77: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

FSTsFinite automaton that maps between two strings

Automaton with two labels/arcinput:output

Page 78: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

FST ApplicationsTokenization

Segmentation

Morphological analysis

Transliteration

Translation

Speech recognition

Spoken language understanding

Page 79: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Approaches to FSTsFST as recognizer:

Takes pair of input:output stringsAccepts if in language, o.w. rejects

Page 80: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Approaches to FSTsFST as recognizer:

Takes pair of input:output stringsAccepts if in language, o.w. rejects

FST as generator:Outputs pairs of strings in languages

Page 81: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Approaches to FSTsFST as recognizer:

Takes pair of input:output stringsAccepts if in language, o.w. rejects

FST as generator:Outputs pairs of strings in languages

FST as translator:Reads an input string and prints output string

Page 82: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Approaches to FSTsFST as recognizer:

Takes pair of input:output stringsAccepts if in language, o.w. rejects

FST as generator:Outputs pairs of strings in languages

FST as translator:Reads an input string and prints output string

FST as set relator:Computes relations between sets

Page 83: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

FSTs, Formally

Page 84: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

FSTs & Regular RelationsFSAs: equivalent to regular languages

Page 85: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

FSTs & Regular RelationsFSAs: equivalent to regular languages

FSTs: equivalent to regular relationsSets of pairs of strings

Page 86: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

FSTs & Regular RelationsFSAs: equivalent to regular languages

FSTs: equivalent to regular relationsSets of pairs of strings

Regular relations:For all (x,y) in Σ1 x Σ2, {(x,y)} is a regular relation

The empty set is a regular relation If R1,R2 are regular relations,

R1R2 , R1 U R2 and R1* are regular relations

Page 87: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Regular Relation Operations

Regular relations are closed under: Inversion: Switching input and output labels

If T maps from I to O, T-1 maps from O to !

Page 88: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Regular Relation Operations

Regular relations are closed under: Inversion: Switching input and output labels

If T maps from I to O, T-1 maps from O to !

Composition:If T1 is a transducer from I1 to O2 and T2 is a

transducer from O2 to O3, then T1 T2 is a transducer from I1 to O3

Page 89: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Regular Relation Operations

Regular relations are closed under: Inversion: Switching input and output labels

If T maps from I to O, T-1 maps from O to !

Composition:If T1 is a transducer from I1 to O2 and T2 is a

transducer from O2 to O3, then T1 T2 is a transducer from I1 to O3

Page 90: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

CARMEL

Page 91: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Defining an FSA/FSTfinal-state

(from-state (to-state “input-sym” “outputsym”? weight?)*)

(from-state (to-state “input-sym” “outputsym”? weight?)*)

…..

First line is final state

Lines define state transitions input-sym (in quotes) required output-sym, weight optional

*e* is the representation for ε

patas:/NLP_TOOLS/ml_tools/fsm/carmel/latest/bin/carmel

Page 92: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

FSA Exampleq4

(q0 (q1 “b”))

(q1 (q2 “a”))

(q2 (q3 “a”))

(q3 (q2 *e*))

(q3 (q4 “!”))

Page 93: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

FST Exampleq1

(q0 (q0 “a” “A”))

(q0 (q1 “b” “b”))

(q1 (q1 “b” “B”))

Page 94: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

WFST ExampleS

(S (S “they” “PRO” 1.0))

(S (S “can” “AUX” 0.99))

(S (S “can” “VERB” 0.01))

(S (S “fish” “NOUN” 0.7))

(S (S “fish” “VERB” 0.3))

Page 95: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

Basic Functionscarmel –k N mywfst

Prints top N most probable paths through mywfst

carmel –Ok N mywsft Print top N most probable outputs from mywfst

carmel fst1 fst2 Composes fst1 and fst2

cat input_file | carmel –sli mywfst Converts 1st line of input_file to fst & composes (left) -b flag: batch processes & prints best path

Page 96: Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.

HW #2Finite-State Automata

Goals:Build Finite-State Automata to represent Regex

Employ modern FST package to build FSA acceptor

Implement FSA acceptor yourselves