Utils#
Dictionary#
- class ofasys.preprocessor.dictionary.Dictionary(*, bos='<s>', pad='<pad>', eos='</s>', unk='<unk>', extra_special_symbols=None)[source]#
A mapping from symbols to consecutive integers
- add_from_file(f, prefix=None, check=True)[source]#
Loads a pre-existing dictionary from a text file and adds its symbols to this instance.
- finalize(threshold=-1, nwords=-1, padding_factor=8)[source]#
Sort symbols by frequency in descending order, ignoring special ones.
- Parameters
count (- threshold defines the minimum word) –
dictionary (- nwords defines the total number of words in the final) –
symbols (including special) –
8 (- padding_factor can be used to pad the dictionary size to be a multiple of) –
hardware (which is important on some) –
- classmethod load(f)[source]#
Loads the dictionary from a text file with the format:
` <symbol0> <count0> <symbol1> <count1> ... `