API

Simple API

class fst.Acceptor

Bases: object

Acceptor(syms=None, semiring=’tropical’) -> acceptor from the desired semiring

class fst.LogAcceptor(syms=None)

Bases: fst.LogTransducer

add_arc(src, tgt, label, weight=None)

fst.add_arc(int source, int dest, label, weight=None): add an arc source->dest labeled with label and weighted with weight

class fst.LogTransducer(isyms=None, osyms=None)

Bases: fst._fst.LogVectorFst

add_arc(src, tgt, ilabel, olabel, weight=None)

fst.add_arc(int source, int dest, ilabel, olabel, weight=None): add an arc source->dest labeled with labels ilabel:olabel and weighted with weight

class fst.StdAcceptor(syms=None)

Bases: fst.StdTransducer

add_arc(src, tgt, label, weight=None)

fst.add_arc(int source, int dest, label, weight=None): add an arc source->dest labeled with label and weighted with weight

class fst.StdTransducer(isyms=None, osyms=None)

Bases: fst._fst.StdVectorFst

add_arc(src, tgt, ilabel, olabel, weight=None)

fst.add_arc(int source, int dest, ilabel, olabel, weight=None): add an arc source->dest labeled with labels ilabel:olabel and weighted with weight

class fst.Transducer

Bases: object

Transducer(isyms=None, osyms=None, semiring=’tropical’) -> transducer from the desired semiring

fst.linear_chain(text, syms=None) → linear chain acceptor for the given input text

Advanced API

class fst._fst.LogArc

Bases: object

SEMIRING

alias of LogWeight

ilabel
nextstate
olabel
weight
class fst._fst.LogState

Bases: object

SEMIRING

alias of LogWeight

arcs

state.arcs: all the arcs starting from this state

final
initial
stateid
class fst._fst.LogVectorFst

Bases: fst._fst._Fst

SEMIRING

alias of LogWeight

acceptor
add_arc(int source, int dest, int ilabel, int olabel, weight=None)

add an arc source->dest labeled with labels ilabel:olabel and weighted with weight

add_state() → new state
arc_sort_input()

fst.arc_sort_input(): sort the input arcs of the transducer

arc_sort_output()

fst.arc_sort_output(): sort the output arcs of the transducer

closure() → Kleene closure of the transducer
closure_plus() → Kleen plus closure (X+ = XX*) of the transducer
compose(LogVectorFst other) → composed transducer

Shortcut: fst >> other

concatenate()

fst.concatenate(LogVectorFst other): modify to the concatenation of the two transducers

concatenation(LogVectorFst other) → concatenation of the two transducers

Shortcut: fst + other

connect()

fst.connect(): removes states and arcs that are not on successful paths.

copy() → a copy of the transducer
determinize() → determinized transducer
difference(LogVectorFst other) → difference of the two transducers

Shortcut: fst - other

draw(SymbolTable isyms=None, SymbolTable osyms=None, SymbolTable ssyms=None)

-> dot format representation of the transducer

input_deterministic
intersect(LogVectorFst other) → intersection of the two acceptors

Shortcut: fst & other

inverse() → inverse of the transducer
invert()

fst.invert(): modify to the inverse of the transducer

invert_weights() → transducer with inverted weights
isyms
logprob_generate(n_path=1) → n_path random paths

sampled according to weights assumed to encode log probabilities

minimize()

fst.minimize(): minimize the transducer

num_arcs() → total number of arcs in the transducer
osyms
output_deterministic
paths() → iterator over all the paths in the transducer
plus_map(value) → transducer with weights equal to the original weights

plus the given value

project_input()

fst.project_input(): project the transducer on the input side

project_output()

fst.project_output(): project the transducer on the output side

prune()

fst.prune(threshold): prune the transducer

push(final=False, weights=False, labels=False) → transducer with

weights or/and labels pushed to initial (default) or final state

push_labels(final=False) → transducer with labels pushed

to initial (default) or final state

push_weights(final=False) → transducer with weights pushed

to initial (default) or final state

random_generate()
relabel()

fst.relabel(imap={}, omap={}): relabel the symbols on the arcs of the transducer imap/omap: (int -> int) or (str -> str) symbol mappings

remove_epsilon()

fst.remove_epsilon(): remove the epsilon transitions from the transducer

remove_weights() → transducer with weights removed
replace(label_fst_map, epsilon=False) → transducer with non-terminals replaced

label_fst_map: non-terminals (str) -> fst map epsilon: replace input label by epsilon?

reverse() → reversed transducer
reweight()

fst.reweight(potentials, final=False): reweight arcs with given potentials in direction of initial (default) or final state

set_closure()

fst.set_closure(): modify to the Kleene closure of the transducer

set_union()

fst.set_union(LogVectorFst other): modify to the union of the two transducers

shortest_distance(bool reverse=False) → length of the shortest path
shortest_path(int n=1) → transducer containing the n shortest paths
start
states
times_map(value) → transducer with weights equal to the original weights

times the given value

top_sort()

fst.top_sort(): topologically sort the nodes of the transducer

uniform_generate(n_path=1) → n_path random paths sampled uniformly
union(LogVectorFst other) → union of the two transducers

Shortcut: fst | other

write()

fst.write(filename): write the binary representation of the transducer in filename

class fst._fst.LogWeight

Bases: object

ONE = LogWeight(0.0)
ZERO = LogWeight(inf)
approx_equal()
class fst._fst.StdArc

Bases: object

SEMIRING

alias of TropicalWeight

ilabel
nextstate
olabel
weight
class fst._fst.StdState

Bases: object

SEMIRING

alias of TropicalWeight

arcs

state.arcs: all the arcs starting from this state

final
initial
stateid
class fst._fst.StdVectorFst

Bases: fst._fst._Fst

SEMIRING

alias of TropicalWeight

acceptor
add_arc(int source, int dest, int ilabel, int olabel, weight=None)

add an arc source->dest labeled with labels ilabel:olabel and weighted with weight

add_state() → new state
arc_sort_input()

fst.arc_sort_input(): sort the input arcs of the transducer

arc_sort_output()

fst.arc_sort_output(): sort the output arcs of the transducer

closure() → Kleene closure of the transducer
closure_plus() → Kleen plus closure (X+ = XX*) of the transducer
compose(StdVectorFst other) → composed transducer

Shortcut: fst >> other

concatenate()

fst.concatenate(StdVectorFst other): modify to the concatenation of the two transducers

concatenation(StdVectorFst other) → concatenation of the two transducers

Shortcut: fst + other

connect()

fst.connect(): removes states and arcs that are not on successful paths.

copy() → a copy of the transducer
determinize() → determinized transducer
difference(StdVectorFst other) → difference of the two transducers

Shortcut: fst - other

draw(SymbolTable isyms=None, SymbolTable osyms=None, SymbolTable ssyms=None)

-> dot format representation of the transducer

input_deterministic
intersect(StdVectorFst other) → intersection of the two acceptors

Shortcut: fst & other

inverse() → inverse of the transducer
invert()

fst.invert(): modify to the inverse of the transducer

invert_weights() → transducer with inverted weights
isyms
logprob_generate(n_path=1) → n_path random paths

sampled according to weights assumed to encode log probabilities

minimize()

fst.minimize(): minimize the transducer

num_arcs() → total number of arcs in the transducer
osyms
output_deterministic
paths() → iterator over all the paths in the transducer
plus_map(value) → transducer with weights equal to the original weights

plus the given value

project_input()

fst.project_input(): project the transducer on the input side

project_output()

fst.project_output(): project the transducer on the output side

prune()

fst.prune(threshold): prune the transducer

push(final=False, weights=False, labels=False) → transducer with

weights or/and labels pushed to initial (default) or final state

push_labels(final=False) → transducer with labels pushed

to initial (default) or final state

push_weights(final=False) → transducer with weights pushed

to initial (default) or final state

random_generate()
relabel()

fst.relabel(imap={}, omap={}): relabel the symbols on the arcs of the transducer imap/omap: (int -> int) or (str -> str) symbol mappings

remove_epsilon()

fst.remove_epsilon(): remove the epsilon transitions from the transducer

remove_weights() → transducer with weights removed
replace(label_fst_map, epsilon=False) → transducer with non-terminals replaced

label_fst_map: non-terminals (str) -> fst map epsilon: replace input label by epsilon?

reverse() → reversed transducer
reweight()

fst.reweight(potentials, final=False): reweight arcs with given potentials in direction of initial (default) or final state

set_closure()

fst.set_closure(): modify to the Kleene closure of the transducer

set_union()

fst.set_union(StdVectorFst other): modify to the union of the two transducers

shortest_distance(bool reverse=False) → length of the shortest path
shortest_path(int n=1) → transducer containing the n shortest paths
start
states
times_map(value) → transducer with weights equal to the original weights

times the given value

top_sort()

fst.top_sort(): topologically sort the nodes of the transducer

uniform_generate(n_path=1) → n_path random paths sampled uniformly
union(StdVectorFst other) → union of the two transducers

Shortcut: fst | other

write()

fst.write(filename): write the binary representation of the transducer in filename

class fst._fst.SymbolTable

Bases: object

copy() → copy of the symbol table
find(int key) → decoded symbol
items() → iterator over (symbol, value) pairs
write()

table.write(filename): save the symbol table to filename

class fst._fst.TropicalWeight

Bases: object

ONE = TropicalWeight(0.0)
ZERO = TropicalWeight(inf)
approx_equal()
fst._fst.read(filename) → transducer read from the binary file

Detect arc type (LogArc or TropicalArc) and produce specific transducer.

fst._fst.read_log(filename) → LogVectorFst read from the binary file
fst._fst.read_std(filename) → StdVectorFst read from the binary file
fst._fst.read_symbols(filename) → SymbolTable read from the binary file

pyfst wraps the OpenFst library in Python, making its excellent C++ API easily accessible for quick development and prototyping

Useful links

Table Of Contents

Related Topics