Introduction
A finite-state transducer is a graph that turns one sequence of symbols into another: the states are joined by arcs that read an input symbol, write an output symbol and carry a weight. Speech recognition and text processing use them for pronunciation lexicons and language models. The OpenFst library saves them in a binary file, usually with the extension .fst.
The format here was checked on eight files, the pmap.*.fst pronunciation
maps in macOS’s SpeechRecognitionSharedSupport.framework: the header,
the two symbol tables and the one state with its arcs. All eight are the vector type with
standard arcs. The header, the flags, the properties bits, the symbol table and the
vector and const types are also checked against the OpenFst source code
(fst.h, fst.cc, vector-fst.h, const-fst.h,
properties.h, symbol-table.cc). The other types (compact, ngram,
lookahead and so on) are not described, and the page is marked partial.
The extension is shared with FL Studio presets, which start with “FLhd”, and with F* source files, which are text. The first four bytes tell them apart.
Structure
Everything is little-endian. A string is a 4-byte length and then that many bytes, with no terminator.
| Offset | Size | Field | In the files seen |
|---|---|---|---|
| 0 | 4 | Magic, D6 FD B2 7E (0x7EB2FDD6, 2125659606: kFstMagicNumber in fst.cc) | always |
| 4 | 4 + n | FST type, a string | vector (n = 6) |
| 14 | 4 + n | Arc type, a string | standard (n = 8): tropical weights |
| 26 | 4 | Version, int32 (the version of the FST type, see below) | 2 |
| 30 | 4 | Flags, int32: three bits | 3 |
| 34 | 8 | Properties, uint64: a bitmap of facts about the transducer (below) | 0x8115820003 |
| 42 | 8 | Start state, int64 (−1 for none) | 0 |
| 50 | 8 | Number of states, int64 (−1 if the writer could not count them: vector type) | 1 |
| 58 | 8 | Number of arcs, int64: set by the const type, left 0 by the vector type | 0 in all eight files, though they hold 1,519 to 2,914 arcs; read the count in each state |
| 66 | varies | Input symbol table, if flag bit 0 is set | present |
| then | varies | Output symbol table, if flag bit 1 is set | present |
| then | varies | The states (vector type) | one state with all the arcs |
The header is the class FstHeader of fst.h: the nine fields
above, in this order, read and written by FstHeader::Read and
Write in fst.cc. After it come the input symbol table if flag
bit 0 is set and then the output symbol table if flag bit 1 is set, then the type’s own data.
In the vector type each state is a final weight (4-byte float; 0 in these files), an arc
count (8 bytes) and then that many 16-byte arcs: input label, output label (both 4 bytes,
0 is epsilon), weight (4-byte float) and next state (4 bytes). The eight files have one
state, and every arc leads back to state 0: the transducer maps phoneme symbols to
output symbols with a cost, for example the second arc of pmap.en_GB.fst
is input 0, output 2, weight 4.0215.
Arc types and weights
The arc type string is the weight’s own name, except that tropical weights are named
standard (arc.h: Weight::Type() == "tropical" ? "standard" : Weight::Type()).
float-weight.h adds 64 to the name of a weight kept in a double. The arc types that have
a plain floating-point weight, and which the explorer decodes, are:
standard,log,minmax: the weight is a 4-byte floattropical64,log64,minmax64: the weight is an 8-byte double
Other arc types (the string, gallic, lexicographic, product and signed log weights, and so on) have other weight layouts and are not described here.
The vector type
vector-fst.h writes, for each state in order, the final weight, the number of arcs
as an int64 and then each arc field by field with no padding: input label (int32), output
label (int32), weight (4 or 8 bytes) and next state (int32), so 16 bytes for a float weight
and 20 for a double. If the writer cannot seek back to count the states first, the header holds
−1 for the number of states and the reader goes on reading states to the end of the file.
VectorFst::Write never sets the header’s arc count: it stays 0. That is why the
count is 0 in the eight files, which settles what was open before.
The const type
const-fst.h writes the C++ memory layout. The type name is const, with
the size of its index type in bits when that is not 32: const8, const16,
const64. The header’s numbers of states and arcs are both set. After the header
and the symbol tables come all the states, then all the arcs:
- A state is
{ weight; pos; narcs; niepsilons; noepsilons }: the final weight, the index of the state’s first arc in the arc array, its number of arcs, and how many of its arcs have input and output label 0. The four numbers have the index type’s size, so a state is 20 bytes forconstwith float weights; padding follows C++ alignment (a 4-byte weight before 8-byte numbers leaves 4 bytes). - An arc is the C++ structure
{ ilabel; olabel; weight; nextstate }: 16 bytes with a float weight and 24 with a double weight (4 bytes of padding at the end). - With flag bit 2 (aligned) set, zero bytes bring the file offset to a multiple of 16 before the states and again before the arcs (
AlignOutputinutil.cc).
The explorer reads these layouts from the source. No real file of the const type was found to check them against; the test builds them by hand from the source.
Versions
The version is the version of the FST type’s own layout, not of the header. The vector type
writes 2 and refuses anything older (kMinFileVersion = 2). The const type writes 2 normally and 1 when it
writes the aligned form (kAlignedFileVersion = 1) and reads 1 and 2; it treats version 1 as aligned.
A symbol table is the magic 74 FB B2 7E (0x7EB2FB74), the table’s name
as a string, the next free key (8 bytes), the number of symbols (8 bytes), then each
symbol as a string followed by its key (8 bytes). In the macOS files the name is a path
from the vendor’s build, the tables have 38 to 55 symbols that begin
<eps> (key 0), AA, AE, AH in the English files, and the output table
has two more symbols than the input table in every file. (SymbolTableImpl::Write in
symbol-table.cc; the magic is kSymbolTableMagicNumber, 2125658996.) The
keys are int64 and need not run from 0 without gaps; the next free key is stored.
Flags
| Bit | Value | Name in fst.h | Meaning |
|---|---|---|---|
| 0 | 1 | HAS_ISYMBOLS | An input symbol table follows the header |
| 1 | 2 | HAS_OSYMBOLS | An output symbol table follows |
| 2 | 4 | IS_ALIGNED | The data is memory-aligned (const type) |
There are no other flags. An earlier version of this page named an “is mapped” bit 3: no such bit exists (whether a file is memory-mapped is a read option, not a flag).
Properties
The 64-bit properties field is the set of k… constants of
properties.h. Bits 0 to 2 are single facts. From bit 16 the facts come in pairs: the
low bit of a pair means the property holds and the next bit means it does not hold; when neither is set the
writer did not know.
| Bits | Property | Bits | Property |
|---|---|---|---|
| 0 | kExpanded: the machine is an expanded FST (it knows its number of states) | 1 | kMutable: the machine is a mutable FST |
| 2 | kError: an error was found | 16, 17 | acceptor, not an acceptor (input = output labels) |
| 18, 19 | input deterministic, not | 20, 21 | output deterministic, not |
| 22, 23 | has epsilons, no epsilons | 24, 25 | has input epsilons, none |
| 26, 27 | has output epsilons, none | 28, 29 | input label sorted, not |
| 30, 31 | output label sorted, not | 32, 33 | weighted, unweighted |
| 34, 35 | cyclic, acyclic | 36, 37 | initial state cyclic, acyclic |
| 38, 39 | top sorted, not | 40, 41 | all states accessible, not |
| 42, 43 | all states coaccessible, not | 44, 45 | string (a chain: state 0 initial, the last state final, one arc from each state to the next), not |
| 46, 47 | weighted cycles, unweighted cycles | 48 to 63 | unused |
The macOS files’ 0x8115820003 is expanded and mutable (the vector type’s own bits), plus
the known facts, which the explorer now lists by name.
Worked example
00000000 d6 fd b2 7e magic
00000004 06 00 00 00 76 65 63 74 6f 72 "vector"
0000000e 08 00 00 00 73 74 61 6e 64 61 72 64 "standard"
0000001a 02 00 00 00 03 00 00 00 version 2, flags 3
00000022 03 00 82 15 81 00 00 00 properties
0000002a 00..(8) 01 00..(8) 00..(8) start 0, 1 state, 0 arcs
00000042 74 fb b2 7e 56 00 00 00 2f 61 6d 72 ... symbol table, name of 86 bytes
Not described
This page is partial. The header, flags, properties, symbol table and the vector and const types come from the OpenFst source; real files seen are eight vector files with standard arcs and one state.
Known, not yet covered
- Reference and viewer: the other FST types that OpenFst defines (compact types such as
compact_acceptorandcompact_string,ngram,lookahead,edit,pdt,mpdtand so on) and the weight types with other layouts (string, gallic, lexicographic, product, signed log): all defined in the open source OpenFst library, but not described here; the viewer shows those states as bytes. - Reference and viewer: the const type and the 64-bit weights are described from the source and tested on files built by hand, not on a real file; files with more than one state were not seen either.
- Viewer: it does not check the header’s state and arc counts against the data, or the properties bits against the arcs.
Also used for
- FL Studio channel preset – File type 32: one channel of the channel rack, with its sample or plugin.
- FL Studio mixer preset – File type 64: one mixer insert, with its effect plugin and its settings.
- FL Studio plugin preset – File type 48: one plugin’s name and saved state, with no channel around it.
- FL Studio preset – FL Studio channel, plugin and mixer presets: an FLP file with another file type.
Links
Software
- OpenFst – library and command-line tools for weighted finite-state transducers (C++)
Reference
- OpenFst headers –
fst.h,properties.h,vector-fst.h,const-fst.h,arc.handfloat-weight.h, as a source mirror (C++)