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

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

CSC 361NFA vs. DFA1. CSC 361NFA vs. DFA2 NFAs vs. DFAs NFAs can be constructed from DFAs using transitions: Called NFA- Suppose M 1 accepts L 1, M 2 accepts.
Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2005.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Finite-State Transducers Shallow Processing Techniques for NLP Ling570 October 10, 2011.
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 Regular Expressions and Automata September Lecture #2-2.
Introduction to Computability Theory
NFAs Sipser 1.2 (pages 47–54). CS 311 Fall Recall… Last time we showed that the class of regular languages is closed under: –Complement –Union.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Introduction to Computability Theory
CS5371 Theory of Computation
FSA and HMM LING 572 Fei Xia 1/5/06.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
Finite state automaton (FSA)
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
1 Finite state automaton (FSA) LING 570 Fei Xia Week 2: 10/07/09 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
1 Non-Deterministic Automata Regular Expressions.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
Regular Expressions and Automata Chapter 2. Regular Expressions Standard notation for characterizing text sequences Used in all kinds of text processing.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
Finite-State Machines with No Output
Morphological Recognition We take each sub-lexicon of each stem class and we expand each arc (e.g. the reg-noun arc) with all the morphemes that make up.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Chapter 2. Regular Expressions and Automata From: Chapter 2 of An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition,
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
REGULAR LANGUAGES.
Theory of Languages and Automata
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
2. Regular Expressions and Automata 2007 년 3 월 31 일 인공지능 연구실 이경택 Text: Speech and Language Processing Page.33 ~ 56.
CHAPTER 1 Regular Languages
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Natural Language Processing Lecture 4 : Regular Expressions and Automata.
NFA defined. NFA A Non-deterministic Finite-state Automata (NFA) is a language recognizing system similar to a DFA. It supports a level of non-determinism.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Modeling Computation: Finite State Machines without Output
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
1 Language Recognition (11.4) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch
BİL711 Natural Language Processing1 Regular Expressions & FSAs Any regular expression can be realized as a finite state automaton (FSA) There are two kinds.
LECTURE 5 Scanning. SYNTAX ANALYSIS We know from our previous lectures that the process of verifying the syntax of the program is performed in two stages:
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
Lexical analysis Finite Automata
Non Deterministic Automata
Two issues in lexical analysis
Non-Deterministic Finite Automata
Non-Deterministic Finite Automata
Non Deterministic Automata
Finite Automata.
4b Lexical analysis Finite Automata
4b Lexical analysis Finite Automata
Chapter 1 Regular Language
Non Deterministic Automata
Presentation transcript:

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

Roadmap Finite-state automata variants Non-deterministic Finite-State Automata (NFA) Probabilistic Finite-State Automata (PFSA) Finite-State Transducers (FST) Intro CARMEL

FSAs Formally A Finite-State Automaton (FSA) is a 5-tuple: A set of states Q { q 0,q 1,q 2,q 3,q 4 } A finite alphabet Σ {b,a,!} A state state q 0 A set of accepting states {q 4 } A transition function Q x Σ  Q

Non-deterministic Finite-State Automata Deterministic FSA: Given current state x input, at most one legal transition

Non-deterministic Finite-State Automata Deterministic FSA: Given current state x input, at most one legal transition Sources of non-determinism in NFA

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 q i x a

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 q i x a ε-transitions Transitions that consume no input

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 q i x a ε-transitions Transitions that consume no input Multiple start states Transitions: Q x (Σ U ε)  2 S

Sheeptalk NFA Multiple choice:

Sheeptalk NFA Multiple choice: ε-transitions

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

NFA & DFA What is the relationship b/t NFAs and DFAs? NFAs and DFAs are equivalent Accept same languages

NFA & DFA What is the relationship b/t NFAs and DFAs? NFAs and DFAs are equivalent Accept same languages Standard transformation from NFA to DFA: Create new state for each equivalence class in NFA

NFA & DFA What is the relationship b/t NFAs and DFAs? NFAs and DFAs are equivalent Accept same languages Standard transformation from NFA to DFA: Create new state for each equivalence class in NFA If NFA has N states, up to 2 N states in DFA

NFA & DFA What is the relationship b/t NFAs and DFAs? NFAs and DFAs are equivalent Accept same languages Standard transformation from NFA to DFA: Create new state for each equivalence class in NFA If NFA has N states, up to 2 N states in DFA Why use both?

Managing Non-Determinism Approaches to non-determinism

Managing Non-Determinism Approaches to non-determinism Backup/backtracking: At choice points, mark state, input If fail, return and try alternative

Managing Non-Determinism Approaches to non-determinism Backup/backtracking: At choice points, mark state, input If fail, return and try alternative Look-ahead: Look ahead to see which choice to take

Managing Non-Determinism Approaches to non-determinism Backup/backtracking: At choice points, mark state, input If 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

Recognition in NFAs Two standard approaches:

Recognition in NFAs Two standard approaches: Transformation: Convert NFA  DFA Perform standard DFA recognition

Recognition in NFAs Two standard approaches: Transformation: Convert NFA  DFA Perform standard DFA recognition Search: Explicitly model recognition as state-space search Perform backtracking as necessary

Recognition in NFA For strings in the language:

Recognition in NFA For strings in the language: There exists some state sequence leading to a final state

Recognition in NFA For 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:

Recognition in NFA For 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

NFA Recognition as Search Search problem:

NFA Recognition as Search Search problem: Start search-state (start node, beginning of input)

NFA Recognition as Search Search problem: Start search-state (start node, beginning of input) Goal test (final node, end of input)

NFA Recognition as Search Search problem: Start search-state (start node, beginning of input) Goal test (final node, end of input) Successor function Transitions

NFA Recognition as Search Search problem: Start search-state (start node, beginning of input) Goal test (final node, end of input) Successor function Transitions Path cost

NFA Recognition as Search Search problem: Start search-state (start node, beginning of input) Goal test (final node, end of input) Successor function Transitions Path cost Use standard search algorithms e.g. Depth-first, breadth first, A*

Example

Breadth-first Search

Equivalences and Operations FSAs equivalent to Regular Languages (Regex, etc) Can be shown by induction Demonstrate primitive regex ops imitated by automata

Equivalences and Operations FSAs equivalent to Regular Languages (Regex, etc) Can be shown by induction Demonstrate primitive regex ops imitated by automata

Equivalences and Operations FSAs equivalent to Regular Languages (Regex, etc) Can be shown by induction Demonstrate primitive regex ops imitated by automata

Equivalences and Operations FSAs equivalent to Regular Languages (Regex, etc) Can be shown by induction Demonstrate primitive regex ops imitated by automata

Equivalences and Operations FSAs equivalent to Regular Languages (Regex, etc) Can be shown by induction Demonstrate primitive regex ops imitated by automata E.g. Concatenation

Equivalences and Operations FSAs equivalent to Regular Languages (Regex, etc) Can be shown by induction Demonstrate primitive regex ops imitated by automata E.g. Concatenation

Equivalences and Operations Closure: Union:

Equivalences and Operations Closure: Union:

Equivalences and Operations Closure: Union:

Finite-State Tools Toolkits: AT&T Finite-State Toolkit: NLTK: CARMEL (ISI): /NLP_TOOLS/ml_tools/FST/carmel

Finite-State Tools Toolkits: AT&T Finite-State Toolkit: NLTK: CARMEL (ISI): /NLP_TOOLS/ml_tools/FST/carmel Functions: Convert Regex to FSA Convert FSA to Regex Convert NFA to DFA Perform operations: concatenation, disjunction, *, etc

Probabilistic Finite-State Automata (PFA)

PFA Definition A Probabilistic Finite-State Automaton is a 7-tuple: A set of states Q An alphabet Σ A set of transitions: δsubset Q x Σ x Q

PFA Definition A Probabilistic Finite-State Automaton is a 7-tuple: A set of states Q An alphabet Σ A set of transitions: δsubset Q x Σ x Q Initial state probabilities: Q  R +

PFA Definition A Probabilistic Finite-State Automaton is a 7-tuple: A set of states Q An alphabet Σ A set of transitions: δsubset Q x Σ x Q Initial state probabilities: Q  R + Transition probabilities: δ  R +

PFA Definition A Probabilistic Finite-State Automaton is a 7-tuple: A set of states Q An alphabet Σ A set of transitions: δsubset Q x Σ x Q Initial state probabilities: Q  R + Transition probabilities: δ  R + Final state probabilities: Q  R +

PFA Definition A Probabilistic Finite-State Automaton is a 7-tuple: A set of states Q An 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.

PFA Definition A Probabilistic Finite-State Automaton is a 7-tuple: A set of states Q An 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.

PFA Example Example Example due to F. Xia

PFA Example Example I(q 0 )=1 I(q 1 )=0 Example due to F. Xia

PFA Example Example I(q 0 )=1 I(q 1 )=0 F(q 0 )=0 F(q 1 )=0.2 Example due to F. Xia

PFA Example Example I(q 0 )=1 I(q 1 )=0 F(q 0 )=0 F(q 1 )=0.2 P(q 0,a,q 1 )=1; P(q 1,b,q 1 ) =0.8 Example due to F. Xia

PFA Example Example I(q 0 )=1 I(q 1 )=0 F(q 0 )=0 F(q 1 )=0.2 P(q 0,a,q 1 )=1; P(q 1,b,q 1 ) =0.8 P(ab n ) Example due to F. Xia

PFA Example Example I(q 0 )=1 I(q 1 )=0 F(q 0 )=0 F(q 1 )=0.2 P(q 0,a,q 1 )=1; P(q 1,b,q 1 ) =0.8 P(ab n ) = I(q 0 )*P(q 0,a,q 1 )*P(q 1,b,q 1 ) n *F(q 1 ) Example due to F. Xia

PFA Example Example I(q 0 )=1 I(q 1 )=0 F(q 0 )=0 F(q 1 )=0.2 P(q 0,a,q 1 )=1; P(q 1,b,q 1 ) =0.8 P(ab n ) = I(q 0 )*P(q 0,a,q 1 )*P(q 1,b,q 1 ) n *F(q 1 ) = 0.8 n *0.2 Example due to F. Xia

PFA Example Example I(q 0 )=1 I(q 1 )=0 F(q 0 )=0 F(q 1 )=0.2 P(q 0,a,q 1 )=1; P(q 1,b,q 1 ) =0.8 P(ab n ) = I(q 0 )*P(q 0,a,q 1 )*P(q 1,b,q 1 ) n *F(q 1 ) = 0.8 n *0.2 Example due to F. Xia

PFA PFA augments NFAs with probabilities on arcs

PFA PFA augments NFAs with probabilities on arcs Probability of a path through PFA is product of transition probabilities (and initial/final state probs)

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.

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:

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)

Weighted FSA Similar to PFA Arcs associated with weight (not probability)

Finite-State Transducers

FSTs Finite automaton that maps between two strings Automaton with two labels/arc input:output

FST Applications Tokenization Segmentation Morphological analysis Transliteration Translation Speech recognition Spoken language understanding

Approaches to FSTs FST as recognizer: Takes pair of input:output strings Accepts if in language, o.w. rejects

Approaches to FSTs FST as recognizer: Takes pair of input:output strings Accepts if in language, o.w. rejects FST as generator: Outputs pairs of strings in languages

Approaches to FSTs FST as recognizer: Takes pair of input:output strings Accepts 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

Approaches to FSTs FST as recognizer: Takes pair of input:output strings Accepts 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

FSTs, Formally

FSTs & Regular Relations FSAs: equivalent to regular languages

FSTs & Regular Relations FSAs: equivalent to regular languages FSTs: equivalent to regular relations Sets of pairs of strings

FSTs & Regular Relations FSAs: equivalent to regular languages FSTs: equivalent to regular relations Sets 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 R 1,R 2 are regular relations, R 1  R 2, R 1 U R 2 and R 1 * are regular relations

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 !

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 T 1 is a transducer from I 1 to O 2 and T 2 is a transducer from O 2 to O 3, then T 1 T 2 is a transducer from I 1 to O 3

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 T 1 is a transducer from I 1 to O 2 and T 2 is a transducer from O 2 to O 3, then T 1 T 2 is a transducer from I 1 to O 3

CARMEL

Defining an FSA/FST final-state (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

FSA Example q4 (q0 (q1 “b”)) (q1 (q2 “a”)) (q2 (q3 “a”)) (q3 (q2 *e*)) (q3 (q4 “!”))

FST Example q1 (q0 (q0 “a” “A”)) (q0 (q1 “b” “b”)) (q1 (q1 “b” “B”))

WFST Example S (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))

Basic Functions carmel –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 1 st line of input_file to fst & composes (left) -b flag: batch processes & prints best path

HW #2 Finite-State Automata Goals: Build Finite-State Automata to represent Regex Employ modern FST package to build FSA acceptor Implement FSA acceptor yourselves