pocketsphinx-android icon indicating copy to clipboard operation
pocketsphinx-android copied to clipboard

Create custom language model with SRILM

Open RoxanaTapia opened this issue 5 years ago • 1 comments

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!

RoxanaTapia avatar Feb 08 '21 11:02 RoxanaTapia

Hello, here are some of my findings:

Things that didn't work for me

  • Modeling with SRILM was easy, it outputs a .lm model, 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 .lm model didn't work on Android
  • The .lm and .dmp extensions work with Android, one can use this available small-size LM (large LMs give an OOM error). The .lm.bin didn'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.txt are between <s></s> tags, and the third command needs an extra .ascii extension
  • Also, to access the commands one needs to add the following path (tested on ubuntu:latest Docker image, gcc g++ make required):
echo 'export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib"' >> ~/.bashrc
. ~/.bashrc

Fixes:

  • source1: coping with text2idngram stuck 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

RoxanaTapia avatar Feb 10 '21 09:02 RoxanaTapia