Create custom language model with SRILM
Hello, I have been reading the tutorial documentation about creating custom language models using SRILM toolkit. The documentation also mentions that:
"A language model can be stored and loaded in three different formats: text ARPA format, binary BIN format and binary DMP format. The DMP format is obsolete and not recommended."
However, the demo uses only .dmp format. Can I train a .lm Language Model with SRILM and use it with the demo? E.g.:
// Create language model search
File languageModel = new File(assetsDir, "custom.lm");
recognizer.addNgramSearch(CUSTOM_SEARCH, languageModel);
I think #36 might be related but the answer link is broken. Thanks in advance!
Hello, here are some of my findings:
Things that didn't work for me
- Modeling with SRILM was easy, it outputs a
.lmmodel, in my case with small data, in a few seconds, which I found weird. Note that, I was using capitalized text for the corpus in test and training. The resulting.lmmodel didn't work on Android - The
.lmand.dmpextensions work with Android, one can use this available small-size LM (large LMs give an OOM error). The.lm.bindidn't work on Android. Also, using the eng-70k-0.2-pruned.lm gives a WER of ~ 90% (dict and AM same as demo), the recognizer is slower than VOSK and has issues to stop on long-duration speeches.
Solution
- I downloaded the CMUCLMTK from Sourceforge, installing it from other sources (homebrew, or CMU webpage didn't work). The resulting LM works on Android, but the commands in the tutorial might need an update. Note that in this case the utterances in the
corpus.txtare between<s></s>tags, and the third command needs an extra.asciiextension - Also, to access the commands one needs to add the following path (tested on
ubuntu:latestDocker image,gcc g++ makerequired):
echo 'export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib"' >> ~/.bashrc
. ~/.bashrc
Fixes:
- source1: coping with
text2idngramstuck on "Allocating memory for the buffer..." - source2: coping with wrong idngram format
Final commands:
text2wfreq < corpus.txt | wfreq2vocab > vocabulary.vocab
cat corpus.txt | text2idngram -vocab vocabulary.vocab -idngram languagemodel.idngram.ascii -write_ascii
idngram2lm -vocab_type 0 -idngram languagemodel.idngram**.ascii** -vocab vocabulary.vocab -arpa languagemodel.lm
The resulting LM with .lm extension works, I suppose that the .dmp extension also does. To convert one can use e.g.
sphinx_lm_convert -i languagemodel.lm -o languagemodel.dmp