Transducers: Anab Batool Kazmi

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 38

Transducers

Anab Batool Kazmi


Finite State Automata

Finite State
Automata

Automata with
Automata without
Output
Output
(Transducer)

Deterministic Non Deterministic Deterministic Non Deterministic


Finite State Finite State Finite State Finite State
Automata Automata Transducer Transducer
Transducer
• So far, we have only used automata to define languages but more
powerful models allow one to define functions or even relations
between words.
• These automata not only read an input word but they also produce
an output. Such devices are also called transducers.
• Transducers are machines with output.
Finite State Transducer
• A finite-state transducer (FST) is a finite-state machine with two
memory tapes, an input tape and an output tape.
• This contrasts with an ordinary finite-state automaton, which has a
single tape.
• Rather than just traversing(accepting or rejecting) an input string, it
translates the contents of an input string into output string.
• FST is deterministic automata that at each step read one input symbol
a ∈ Σ and write one output symbol b ∈ Γ.
Finite State Transducer
• A transducer is said to transduce (i.e., translate) the contents of its
input tape to its output tape, by accepting a string on its input tape
and generating another string on its output tape.
•  It may do so nondeterministically and it may produce more than one
output for each input string.
• A transducer may also produce no output for a given input string, in
which case it is said to reject the input.
Finite State Transducer
• Acceptor:
If we “read” the symbols from an input tape, then our FSA is an
“acceptor”
• Generator:
if we run the machine non-deterministically, from an initial state to a
final state and following any legal path from state to state, and
“output” the symbols that are on the transition arrows as we go, then
our FSA is a “generator”.
Finite State Transducer
• Non Deterministic Transducer
A finite-state transducer is non-deterministic if there is more than one
possible transition or more than one possible output symbol for a
given pair of a state and an input symbol.
These define relations.
• Deterministic Transducer
A finite state transducer is deterministic, if the output is uniquely
determined by input.
These define functions.
Finite State Transducer
• We put PAIRS of symbols (or symbol strings) on our transition arrows,
viewing one as input and the other as output a/b at the arc means
that in this transition the transducer reads a from the first tape and
writes b onto the second tape.

a/b -
+
Formal Definition of FST
A Finite State Transducer (FST) is a 6-tuple M = (Q, Σ, Γ, δ, s, F)
where
• Q is a finite set of states
• Σ is a finite set of input symbols called alphabet
• Γ is a finite set of output symbols called output alphabet
• δ: Q × Σ → Q × Γ ∗ is the transition function
• s ∈ Q is the start state.
• F ⊆ Q is the final state/s.(may have 0 final state)
Example Transducer
• Q={q1,q2}
• Σ={0,1,2}
• Γ={0,1}
• s={q1}
• F=none
Transition Function δ =
(q1,0,0,q1) (q2,0,0,q1)
(q1,1,0,q1) (q2,1,1,q2)
(q1,2,1,q2) (q2,2,1,q2)
Cont.
• On input 2212011, machine enter the sequence of states
q1,q2,q2,q2,q2,q1,q1,q1 and produces output 1,1,1,1,0,0,0
Contd.
• Give the sequence of states entered and the output produced in each
of the following inputs.
Input States Output
011 q1,q1,q1,q1 0,0,0
211 q1,q2,q2,q2 1,1,1
121 q1,q1,q2,q1 0,1,1
0202 q1,q1,q2,q1,q2 0,1,0,1
Example
Q={q1,q2,q3} Σ={a,b}
Γ={0,1} s={q1}
F=none
Transition Function δ =
(q1,a,1,q2) (q2,a,1,q3)
(q1,b,1,q3) (q2,b,0,q1)
(q3,a,0,q1)
(q3,b,1,q2)
Contd.
• Give the sequence of states entered and the output produced in each
of the following inputs.

Input States Output


b q1,q3 1
bbab q1,q3,q2,q3,q2 1,1,1,1
bbbbbb q1,q3,q2,q1,q3,q2,q1 1,1,0,1,1,0
APPLICATION OF FST
• FSTs are useful in NLP(Natural Language Processing) and speech
recognition because they have nice algebraic properties.
Finite automata
• Finite automata may have outputs corresponding to
each transition. There are two types of finite state
machines that generate output −

• Mealy Machine
• Moore machine
Mealy Machine
• A Mealy Machine is an FSM whose output depends on the present
state as well as the present input.
• It can be described by a 6 tuple (Q, ∑, O, δ, X, q0) where −
• Q is a finite set of states.
• ∑ is a finite set of symbols called the input alphabet.
• O is a finite set of symbols called the output alphabet.
• δ is the input transition function where δ: Q × ∑ → Q
• X is the output transition function where X: Q × O→ Q
• q0 is the initial state from where any input is processed (q0 ∈ Q).
Mealy Machine
• The state table of a Mealy Machine is shown below −
Next State

Present State Input = 0 Input = 1

State Output State Output

→a b x1 c x1

b b x2 d x3

c d x3 c x1

d d x3 d x2
Mealy Machine
• The state diagram of the above Mealy Machine is −
0 /x 2

b 0 /x , 1 / x
/x 1 1 /x 3 2

0
3

a d
1/ 0 /x
x 1
c 3

1 /x 1
Moore Machine
• Moore machine is an FSM whose outputs depend on only the present
state.
• A Moore machine can be described by a 6 tuple (Q, ∑, O, δ, X, q0) where

• Q is a finite set of states.
• ∑ is a finite set of symbols called the input alphabet.
• O is a finite set of symbols called the output alphabet.
• δ is the input transition function where δ: Q × ∑ → Q
• X is the output transition function where X: Q → O
• q0 is the initial state from where any input is processed (q0 ∈ Q).
Moore Machine
• The state table of a Moore Machine is shown below −
Next State
Present state Output
Input = 0 Input = 1

→a b c x2

b b d x1

c c d x2

d d d x3
Moore Machine
• The state diagram of the above Moore Machine is −
0
b /x 0, 1
0
1
1

a /x 2 d /x 3

1 0
c /x 2

1
• Machine that inverts the input.
i.e: if given 1010 outputs 0101

Mealy Machine Moore Machine

1/0 0/1 1 0 0

q0 q0,0 q1,1
1
• Machine to Generate 1’s Complement

Mealy Machine Moore Machine

1/0 0/1 1 0 0

q0 q0,0 q1,1
1
• String = 01100
• Isc = 10011
• +1 = 10100
• String = 11
• 2sc = 01
• Machine to Generate 2’s Compliment

Mealy Machine Moore Machine


0 0
0/0 1 1

0 1
q0
1/1
q1 1/ q0,0 q1,1 q2,0
0
0/
1
Mealy Machine that count # of occurrences of int where ∑= {a,i,n,t}
(a+i+n+t)*int
String=aint
Outut =0001

1
i/0

a/0,n/0,t/0 i/0 a/0

i/0 n/0 t/1 1


-
2 3
1 4
i/0

a/ i/0 2
0,t/
0
n/0

a/ 3
0,n/
0
t/1
a/0,n/
0,t/0
4
Mooray Machine that count # of occurrences on int String=aint

0
1
i

a,n,t i a

i n t 0 1
-
2,0 3,0
1,0 4,1
i

a,t i
0 2

a,n 0 3

t
a,n,t

4
1
Moore Machine to Mealy Machine
• Input − Moore Machine
• Output − Mealy Machine
• Step 1 − Take a blank Mealy Machine transition table format.
• Step 2 − Copy all the Moore Machine transition states into this table
format.
• Step 3 − Check the present states and their corresponding outputs in
the Moore Machine state table; if for a state Qi output is m, copy it
into the output columns of the Mealy Machine state table wherever
Qi appears in the next state.
Moore Machine to Mealy Machine
• Let us consider the following Moore machine −

Next State
Present State Output
a=0 a=1
→a d b 1
b a d 0
c c c 0
d b a 1

Now we apply Algorithm 4 to convert it to Mealy Machine.


Moore Machine to Mealy Machine
Step 1 & 2 −

Next State
Present State
a=0 a=1
State Output State Output

→a d 1 b
b a 1 d
c c 0 c
d b 0 a
Moore Machine to Mealy Machine
Step 3 −

Next State
Present State
a=0 a=1
State Output State Output

=> a d 1 b 0
b a 1 d 1
c c 0 c 0
d b 0 a 1
Mealy Machine to Moore Machine
Algorithm 5
• Input − Mealy Machine
• Output − Moore Machine
• Step 1 − Calculate the number of different outputs for each state (Q i)
that are available in the state table of the Mealy machine.
• Step 2 − If all the outputs of Qi are same, copy state Q i. If it has n
distinct outputs, break Qi into n states as Qin where n = 0, 1, 2.......
• Step 3 − If the output of the initial state is 1, insert a new initial state
at the beginning which gives 0 output.
Mealy Machine to Moore Machine
• Let us consider the following Mealy Machine −
Next State
Present State a=0 a=1
Next State Output Next State Output
→a d 0 b 1
b a 1 d 0
c c 1 c 0
d b 0 a 1

Here, states ‘a’ and ‘d’ give only 1 and 0 outputs respectively, so we retain states ‘a’ and ‘d’.
But states ‘b’ and ‘c’ produce different outputs (1 and 0). So, we divide b into b0,
b1 and c into c0, c1.
Mealy Machine to Moore Machine

Next State
Present State Output
a=0 a=1
→a d b1 1
b0 a d 0
b1 a d 1
c0 C1 C0 0
c1 c1 c0 1
d b0 a 0
Mealy Machine to Moore Machine

Next State
Present State Output
a=0 a=1
→a d b1 1
b0 a d 0
b1 a d 1
c0 c1 C0 0
c1 c1 C0 1
d b0 a 0
• Mealy to Moore Conversion
Mealy Machine Moore Machine
b/1 States a b Output
q00 q4 q3 0
q1 a/1
q01 q4 q3 1
a/0 q1 q00 q1 1
q20 q1 q20 0
b/0 q21 q1 q20 1
q3 q20 q01 0
a/1 b/1 q4 q3 q21 1
q0 q4 q2
b
a
a Q1,
b/0 a/0 a
Q01, 1

b/1 a/0 1
b
a
q3 a Q4, q2.0,
Q00,0
b 1
b
b
0
States a b
q0 q4,1 q3, 0
b a
q1 q0,0 q1,1 b
q2 q1,1 q2,0
q3 q2,0 q0,1
a
q2.1,
q4 q3,0 q2,1 Q3,
0
0
• Mealy to Moore Conversion
Mealy Machine Moore Machine
States 1 0 Output
S0 S10 S0 0
S10 S10 S2 0
S11 S10 S2 1
S2 S11 S0 0

States 1 0
0
S0 S1,0 S0, 0
S1 S1,0 S2,0
S2 S1,1 S0,0

0 1
0
1
S0,0 S10,0 S2,0
0
1
1
S11,1

You might also like