1Basic Mathematics - Finite-State Methods in Natural-Language Processing: Basic Mathematics Ronald M. Kaplan and Martin Kay.

Slides:



Advertisements
Similar presentations
Context-Free and Noncontext-Free Languages
Advertisements

Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Kleene's Theorem We have defined the regular languages, using regular expressions, which are convenient to write down and use. We have also defined the.
CSE 311 Foundations of Computing I
CMPS 3223 Theory of Computation
Lecture 24 MAS 714 Hartmut Klauck
Properties of Regular Languages
CSE 311: Foundations of Computing Fall 2013 Lecture 23: Finite state machines and minimization.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
1 Midterm I review Reading: Chapters Test Details In class, Wednesday, Feb. 25, :10pm-4pm Comprehensive Closed book, closed notes.
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Introduction to Computability Theory
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
CS 310 – Fall 2006 Pacific University CS310 Strings, String Operators, and Languages Sections: August 30, 2006.
1 Languages and Finite Automata or how to talk to machines...
1 Decidability continued. 2 Undecidable Problems Halting Problem: Does machine halt on input ? State-entry Problem: Does machine enter state halt on input.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
Normal forms for Context-Free Grammars
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
CSE 311: Foundations of Computing Fall 2014 Lecture 23: State Minimization, NFAs.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
TM Design Universal TM MA/CSSE 474 Theory of Computation.
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
Computability Construct TMs. Decidability. Preview: next class: diagonalization and Halting theorem.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
Kleene’s Theorem Group No. 3 Presented To Mam Amina Presented By Roll No Roll No Roll No Roll No Group No. 3 Presented To Mam.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Copyright © Curt Hill Finite State Automata Again This Time No Output.
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
Mathematical Preliminaries
November 2003CSA4050: Computational Morphology IV 1 CSA405: Advanced Topics in NLP Computational Morphology IV: xfst.
CS 203: Introduction to Formal Languages and Automata
Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Context-Free and Noncontext-Free Languages Chapter 13.
Regular Expressions Fundamental Data Structures and Algorithms Peter Lee March 13, 2003.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
November 2003Computational Morphology III1 CSA405: Advanced Topics in NLP Xerox Notation.
Computability Review homework. Video. Variations. Definitions. Enumerators. Hilbert's Problem. Algorithms. Summary Homework: Give formal definition of.
BİL711 Natural Language Processing1 Regular Expressions & FSAs Any regular expression can be realized as a finite state automaton (FSA) There are two kinds.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Algorithms and Decision Procedures for Regular Languages Chapter 9.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Lecture 15: Theory of Automata:2014 Finite Automata with Output.
1 Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Chapters 11 and 12 Decision Problems and Undecidability.
Languages.
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
PROPERTIES OF REGULAR LANGUAGES
CSE 311 Foundations of Computing I
PDAs Accept Context-Free Languages
CSE 105 theory of computation
Chapter 2 Sets and Functions.
Chapter 2 FINITE AUTOMATA.
Hierarchy of languages
CSE 311 Foundations of Computing I
CS 154, Lecture 3: DFANFA, Regular Expressions.
4. Properties of Regular Languages
Non-Deterministic Finite Automata
Deterministic PDAs - DPDAs
Closure Properties of Context-Free languages
Finite-State Methods in Natural-Language Processing: Basic Mathematics
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSE 105 theory of computation
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSE 105 theory of computation
Presentation transcript:

1Basic Mathematics - Finite-State Methods in Natural-Language Processing: Basic Mathematics Ronald M. Kaplan and Martin Kay

2Basic Mathematics - Correspondence Theorem (Kleene) Every regular language L is accepted by some FSM M(L) a M(L 1 )M(L 2 )     M(L 1 ) M(L 2 )   M(L)

3Basic Mathematics - Determinizing Nondeterministic Deterministic  : Q    2 Q  : Q’    Q’ Q’=2 Q A State is final if any member of the set is final 5 a a 6 7 {5}{6,7} a

4Basic Mathematics - Complete vs. Pruned x viii i i v, x Pruned: Smaller  is a partial function. No dead states Lookup is faster Pruned: Smaller  is a partial function. No dead states Lookup is faster Dead (failure) state 5 i, v, x v, x i, v, x

5Basic Mathematics - Minimization Minimized: No two states have congruent suffix graphs a b a b    Minimal machine is unique (up to renaming of states and arc ordering)

6Basic Mathematics - Proof Strategy for Language Properties To prove  (L 1,... L n ) —Get machines M(L 1 ),... M(L n ) —Transform M(L 1 ),... M(L n )  M —Show L(M) =  (L 1,... L n ) L(M) is the language accepted by M Compute with machine — They are finite!

7Basic Mathematics - L1  L2 is Regular 1 2 a b 1a 2b 2b is final if 2 and b is final  = x x x

8Basic Mathematics - L is Regular Get deterministic, complete M(L) = M = where F’=Q-F L(M)=L? Suppose x not in L x takes M(L) into r  Q-F.  x takes M into r  F’  x  L(M). Suppose x in L x takes M(L) into r  Q.  x takes M into r  Q-F’  x  L(M). If M(L) were not deterministic, a string x could take M(L) into r  F  and  s  F  It would therefore take L(M) into r  F’  and  s  F’

9Basic Mathematics - Regular— If L , L 2, and L are regular languages and R 1, R 2, and R are regular relations, the following relations are regular: R 1  R  R 1 R 2 R* R -1 R   R 2 Id(L) L 1  L 2 Rev(R)... and the following languages Dom(R) Range(R) L/R R/L x/R R/x

10Basic Mathematics - Not Regular R 1  R 2 R

11Basic Mathematics - Intersection is not Regular x:ax:b   :a 

12Basic Mathematics - Data Structures FSM states start sigma properties (epsilon-free, determinisitc...) State final arcs name mark Arc label destination

13Basic Mathematics - A Traversal Function Traverse(FSMs, StartFn, FinalFn, ArcsFn) Start := StartFn(FSMs); States := (Start); STP := (Start); while s := pop(STP) do s.final := FinalFn(s.name); s.arcs := ArcsFn(s.name); return new FSM[states = States, start=start]; GetState(n) if there is an s in States with s.name = n return s ; else s := new State[name=n]; push s, States push s, STP return s

14Basic Mathematics - The Scanner—1 def __iter__(self): """ Iterate through the states of an automaton. """ count=1 start_states=self.get_start_states() for state in start_states: self.states={state.get_name(): count} count+=1 agenda=[state]

15Basic Mathematics - The Scanner—2 while agenda: state, agenda = agenda[0], agenda[1:] transitions=self.get_transitions(state) for t in transitions: dest=t.dest name=dest.get_name() if name not in self.states: self.states[name]=count count+=1 agenda.append(dest) # Put this at the end so that any renaming of # destinations of its transitions will already # have been done. state.remember_transitions(transitions) yield state

16Basic Mathematics - Displaying FSAs... for state in self: disp.write(self.print_name(state), left) if self.get_final_state(state): disp.write(' (final)') disp.nl() for tr in state.recall_transitions(): disp.write(self.decode_symbol(tr.symbol)+' to ' \ +self.print_name(tr.dest), left+2)...

17Basic Mathematics - Copy Traverse(FSMs, StartFn, FinalFn, ArcsFn) Start := StartFn(FSMs); States := (Start); STP := (Start); while s := pop(STP) do s.final := FinalFn(s.name); s.arcs := ArcsFn(s.name); return new[states = States, start=start]; Traverse(FSMs, StartFn, FinalFn, ArcsFn) Start := StartFn(FSMs); States := (Start); STP := (Start); while s := pop(STP) do s.final := FinalFn(s.name); s.arcs := ArcsFn(s.name); return new[states = States, start=start]; StartFn(n) = new State[name=n.start] FinalFn(n) = n.final ArcsFn(n) = {new Arc[label=a.label, destination=GetState(a.destination)] | a in n.arcs} N.B. The name of a state in the copied machine is the state itself in the machine being copied.

18Basic Mathematics - The Paradigm Copy(FSM) = Travers(FSM, ‘CopyStartFn, ‘CopyFinalFn, ‘CopyArcsFn) Inverse(FSM) = Travers(FSM, ‘InverseStartFn, ‘InverseFinalFn, ‘InverseArcsFn) CrossProduct( ) = Travers(, ‘CrossProductStartFn, ‘CrossProductFinalFn, ‘CrossProductArcsFn) Intersection( ) = Travers(, ‘IntersectionStartFn, ‘IntersectionFinalFn, ‘IntersectionArcsFn)

19Basic Mathematics - Inverse Traverse(FSMs, StartFn, FinalFn, ArcsFn) Start := StartFn(FSMs); States := (Start); STP := (Start); while s := pop(STP) do s.final := FinalFn(s.name); s.arcs := ArcsFn(s.name); return new[states = States, start=start]; Traverse(FSMs, StartFn, FinalFn, ArcsFn) Start := StartFn(FSMs); States := (Start); STP := (Start); while s := pop(STP) do s.final := FinalFn(s.name); s.arcs := ArcsFn(s.name); return new[states = States, start=start]; StartFn(n) = new State[name=n.start] FinalFn(n) = n.final ArcsFn(n) = {new Arc[label=y:x, destination=GetState(a.destination)] | a in n.arcs & a.label = x:y}

20Basic Mathematics - Prune Prune(F)=Reverse(Copy(Reverse(F))) N.B. Not  -free Dead states are not reachable in Reverse(F)  They are not included in Copy(Reverse(F))  They are not included in Copy(Reverse(Reverse(F)))

21Basic Mathematics - Intersection StartFn( ) = new State[name= ] FinalFn( ) = s1.final & s2.final ArcsFn( ) = {new Arc[label=L, destination=GetState(<a1.destination, a2.destination>)] | a1 in s1.arcs & a2 in s2.arcs & L=a1.label=a2.label} Traverse(FSMs, StartFn, FinalFn, ArcsFn) Start := StartFn(FSMs); States := (Start); STP := (Start); while s := pop(STP) do s.final := FinalFn(s.name); s.arcs := ArcsFn(s.name); return new[states = States, start=start]; Traverse(FSMs, StartFn, FinalFn, ArcsFn) Start := StartFn(FSMs); States := (Start); STP := (Start); while s := pop(STP) do s.final := FinalFn(s.name); s.arcs := ArcsFn(s.name); return new[states = States, start=start]; N.B. Result is not necessarily pruned because some paths die. FSMs must be  -free.

22Basic Mathematics - Intensional vs. Extensional FSAs

23Basic Mathematics - FSA Methods __iter__ get_final_state(self, state) get_start_states(self, state) iter_transitions(self, state)... def __neg__(self): import complement return complement.complement_fsa(self) def __and__(self, other): return intersection_fsa((self, fsa_args(other))) def __or__(self, other): return union_fsa((self,)+fsa_args(other))

24Basic Mathematics - StartFn( ) = new State[name= ] FinalFn( ) = s1.final & s2.final ArcsFn( ) = {new Arc[label=a1.label:a2.label, destination=GetState(<a1.destination, a2.destination>)] | a1 in s1.arcs & a2 in s2.arcs}  new Arc[label=a1.label: , destination=GetState( )] | a1 in s1.arcs & (s2.final | a2=  }  new Arc[label=  :a2.label, destination=GetState( )] | a1 in (s1.final | a1=  & a2 in s2.arcs} Cross Product

25Basic Mathematics - Intersection (with  ) StartFn( ) = new State[name= ] FinalFn( ) = s1.final & s2.final ArcsFn( ) = {new Arc[label=L, destination=GetState(<a1.destination, a2.destination>)] | a1 in s1.arcs & a2 in s2.arcs & L=a1.label=a2.label}  new Arc[label= , destination=GetState(<s1, a2.destination >)] | a1 in s1.arcs & a2 in s2.arcs & a1.label  & a2.label=  }  new Arc[label= , destination=GetState(<a1.destination, s2 >)] | a1 in s1.arcs & a2 in s2.arcs & a1.label=  & a2.label  }

26Basic Mathematics - StringToFSM StartFn( ) = new State[name= ] FinalFn( ) = string=““ ArcsFn( ) = {new Arc[label=First, destination= ]}

27Basic Mathematics - Composition (draft!) StartFn( ) = new State[name= ] FinalFn( ) = s1.final & s2.final ArcsFn( ) = {new Arc[label=x:y, destination=GetState(<a1.destination, a2.destination>)] | a1 in s1.arcs & a1.label=x:z & a2 in s2.arcs & a2.label=z:y} Traverse(FSMs, StartFn, FinalFn, ArcsFn) Start := StartFn(FSMs); States := (Start); STP := (Start); while s := pop(STP) do s.final := FinalFn(s.name); s.arcs := ArcsFn(s.name); return new[states = States, start=start]; Traverse(FSMs, StartFn, FinalFn, ArcsFn) Start := StartFn(FSMs); States := (Start); STP := (Start); while s := pop(STP) do s.final := FinalFn(s.name); s.arcs := ArcsFn(s.name); return new[states = States, start=start];

28Basic Mathematics - Composition StartFn( ) = new State[name= ] FinalFn( ) = s1.final & s2.final ArcsFn( ) = {new Arc[label=x:y, destination=GetState(<a1.destination, a2.destination>)] | a1 in s1.arcs & a1.label=x:z & a2 in s2.arcs & a2.label=z:y}  {new Arc[label= x: , destination=GetState(<a1.destination, s2>)] | a1 in s1.arcs & a1.label= x:  & a2 in s2.arcs & a2.label=z:y & z≠  }  {new Arc[label=  y, destination=GetState(<s1, a2.destination>)] | a1 in s1.arcs & a1.label= x:z & a2 in s2.arcs & a2.label=  y & z≠  }

29Basic Mathematics - Epsilon-closure Epsilon-closure(state) = closure := {state} ; STP := {state} ; while s := pop(STP) do for d in { a.destination | a in s.arcs & a.label=  & a.detination  closure} do if d  closure then { closure := closure  d; STP := STP  d} return closure EC-Arcs(state) = {a | a in s.arcs & a.label ≠  for some s in Epsilon-closure(state)}

30Basic Mathematics - RemoveEpsilons StartFn(n) = new State[name=n.start] FinalFn(n) = There is s in Epsilon-closure(n) such that s.final ArcsFn(n) = {new Arc[label=a.label, destination=GetState(a.destination)] | a in EC-Arcs(n)}

31Basic Mathematics - Intersection — again StartFn( ) = new State[name= ] FinalFn( ) = s1.final & s2.final ArcsFn( ) = {new Arc[label=L, destination=GetState(<a1.destination, a2.destination>)] | a1 in EC-Arcs(s1) & a2 in EC-Arcs(s2) & L=a1.label=a2.label}

32Basic Mathematics - Determinize StartFn(f) = new State[name={f.start}] FinalFn(n) = There is an s in n such that s.final; ArcsFn(n) = {new Arc[label=L, destination=GetState(D)] | D=  s  n {a.destination | a  EC-Arcs(s) & a.label = L}}

33Basic Mathematics - Complete DeadState:=new State ; DeadState.arcs := {new Arc[label=l, destination = DeadState] | l in  } StartFn(f) = new State[name=f.start] FinalFn(n) = n.final; ArcsFn(n) = {new Arc[label=a.label, destination=GetState(a.destination)] | a in n.arcs}  {new Arc[label=l, destination=DeadState] | There is no a in n.arcs such that a.label=l for l in  }

34Basic Mathematics - Complement Complement(FSM) = Traverse(Determinize(Complete(FSM)), S, F, A) where S (f) = new State[name = f.start] F(n) = ~n.final ArcsFn(n) = {new Arc[label=a.label, destination=GetState(a.destination)] | a in n.arcs}

35Basic Mathematics - Minus Minus(FSM1, FSM2) = Intersect(FSM1, Complement(FSM2))

36Basic Mathematics - Empty Empty(FSM) = New := Copy(FSM) ; There is no s in New.states such that s.final. Otherwise the FSM could contain a final state not reachable from the start state.

37Basic Mathematics - Equivalence L1=L2  L1-L2=L2-L1={}

38Basic Mathematics - Minimization — 1 Give an FSM f and a state s, let suffix(f, s) be the FSM that results from replacing the start state of f with s To minimize an FSM f, conflate all pairs of states s1 and s2 in F iff equivalent(suffix(f, s1), suffix(f, s2)) Exponential because involves determinization

39Basic Mathematics - Minimization — 2 Determinize(Reverse(Determinize(Reverse(f)))) Each suffix s of f is a prefix s’ of Reverse(f) and, in DR(f)=Determinize(Reverse(f)),  (start(DR(f)), s’) is a unique state q. In Reverse(Determinize(Reverse(f))), q is the only state whose suffix set contains s. Since each state in Determinize(Reverse(Determinize(Reverse(f)))) corresponds to a different subset of the states of Reverse(Determinize(Reverse(f))), each has a unique suffix set.

40Basic Mathematics - Minimization — Mark_Partition Mark_partition(class, label, mark) = for state in class do for arc in state.arcs do if arc.label=label then a.destination.mark=mark Annotate with mark all states reachable form the states in class over arcs with label.

41Basic Mathematics - Minimization — Marked? & Final? Marked?(state) = state.mark=1 Return true iff state is marked 1 Return true iff state is final Final?(state) = state.final Make functions for these so that they can be passed as arguments to other functions.

42Basic Mathematics - Minimization — Split Split(class, predicate) = i:=0; new:={}; for state in class do if predicate(state) then i := i+1; p = ( i < |class|/2) ; for state in class do if predicate(state)=p then new := new  delete(state, class) return new Return a new partition containing states removed from partition. The moved states are either those of which predicate is true or those of which it is false, whichever gives the smaller new partition.     States are moved to the smaller class. The old class becomes the larger member of the new pair

43Basic Mathematics - Minimization — 3 Minimize(FSM) = push(active, Split(FSM.states, final?)) ; while p1 := pop(active) do push(inactive, p1); for label in  do Mark_partition(p1, label, 1) for p2 in active  inactive do push(active, Split(p2, Marked?)) Mark_partition(p1, label, 0)

44Basic Mathematics - Membership Member(string, FSM) = ~Empty(Intersect(FSM, StringToFsm(string)))

45Basic Mathematics - Membership for complete, deterministic,  -free FSMs Member(string, FSM) = state := FSM.start; for pos := 1 to length(string) do a := a in state.arcs such that a.label=string[pos] state := a.destination else return false return state.final Linear in length of string

46Basic Mathematics - Membership for pruned, deterministic,  -free FSMs Member(string, FSM) = state := FSM.start; for pos := 1 to length(string) do if there is a in state.arcs such that a.label=string[pos] then state := a.destination else return false return state.final

47Basic Mathematics - Membership for arbitrary FSMs Member(string, FSM) = M(string, 1, FSM.start) M(string, pos, state) = if pos > length(string) then return  s in Epsilon-closure(state) such that s.final for a in EC-Arcs(state.arcs) do if a.label = string[pos] & M(string, pos+1, a.destination) then return true return false Recursive because backtracking

48Basic Mathematics - Pair Membership for arbitrary FSTs PMember(string1, string2, FST) = PM(string1, 1, string2, 1, FST.start) PM(s1, p1, s2, p2, state) = if p1 > length(s1) & p2 > length(s2) then return  s in Epsilon-closure(state) such that s.final for a in EC-Arcs(state.arcs) do if (a.label.1 =  & a.label.2=s2[p2] & PM(s1, p1, s2, p2+1, a.destination) or (a.label.1 = s1[p1] & a.label.2=  & PM(s1, p1+1, s2, p2, a.destination) or (a.label.1 = s1[p1] & a.label.2 = s2[p2] & PM(s1, p1+1, s2, p2+1, a.destination))) then return true return false Closure over  : 

49Basic Mathematics - Empty Empty(ID(StringToFSM(s1))  FSM  ID(StringToFSM(s2)))

50Basic Mathematics - Image and Inverse Image Image(string, FST) = Range(Compose(ID(StringToFSM(String)), FST)) InverseImage(string, FST) = Domain(Compose(FST, ID(StringToFSM(string)))) = Image(string, Inverse(FST))

51Basic Mathematics - Image Image(string, FST) = results={}, Im (string, 1, ““, 1, FST.start) return results Im(s1, p1, s2, p2, state) = if p1 > length(s1) &  s in Epsilon-closure(state) such that s.final then push(results, CopyString(s2, p2)); for a in EC-Arcs(state.arcs) do if a.label.1 =  then s2[p2] := a.label.2; Im(s1, p1, s2, p2+1, a.destination); else if a.label.1 = s1[p1] then if a.label.2=  then Im(s1, p1+1, s2, p2, a.destination) else s2[p2]:=a.label.2; Im(s1, p1+1, s2, p2+1, a.destination)

52Basic Mathematics - Image(string, FST, inverse) = results={}, Im (string, 1, ““, 1, FST.start) return results Im(s1, p1, s2, p2, state) = if p1 > length(s1) &  s in Epsilon-closure(state) such that s.final then push(results, CopyString(s2, p2)); for a in EC-Arcs(state.arcs) do if inverse then inlab:=a.label.2, outlab := a.label.1 else inlab := a.label.1; outlab := a.label.2 if inlab =  outlab =  then Im(s1, p1, s2, p2, a.destination) else if inlab =  then s2[p2] := outlab; Im(s1, p1, s2, p2+1, a.destination); else if inlab = char(s1, p1) then if outlab=  then Im(s1, p1+1, s2, p2, a.destination) else s2[p2]:=outlab; Im(s1, p1+1, s2, p2+1, a.destination) Image and Inverse

53Basic Mathematics - Linear Bounded? Recursive algorithm (Inverse) Image algorithms may not halt if FST is not linear bounded. Composition algorithms halt but may produce cyclic FSMs. Challenge: A recursive algorithm that always halts and produces output in the form of an FSM. Hint: try Traverse.