Skip to main content

Adapt Kaldi-ASR nnet3 chain models from to a different language model.

Project description

# kaldi-adapt-lm

Adapt Kaldi-ASR nnet3 chain models from to a different language model.

Constructive comments, patches and pull-requests are very welcome.


To create the language model we would like to adapt our kaldi model to, we first need to create a set of sentences. To get started, download and uncompress a generic set of sentences for you language, e.g.

wget ‘’ unxz sentences-en.txt.xz

now suppose the file utts.txt contained the sentences you would like the model to recognize with a higher probability than the rest. To achieve that, we add these sentences five times in this examples to our text body:

cat utts.txt utts.txt utts.txt utts.txt utts.txt sentences-en.txt >lm.txt

we also want to limit our language model to the vocabulary the audio model supports, so let’s extract the vocabulary next:

MODEL=”models/kaldi-generic-en-tdnn_sp-latest” cut -f 1 -d ‘ ‘ ${MODEL}/data/local/dict/lexicon.txt >vocab.txt

with those files in place we can now train our new language model using KenLM:

lmplz -o 4 –prune 0 1 2 3 –limit_vocab_file vocab.txt –interpolate_unigrams 0 <lm.txt >

Now we can start the kaldi model adaptation process:

kaldi-adapt-lm ${MODEL} mymodel

You should now be able to find a tarball of the resulting model inside the work subdirectory.


  • Python 2
  • Kaldi ASR


My own code is Apache-2.0 licensed unless otherwise noted in the script’s copyright headers.


Guenter Bartsch <<>>

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for kaldi-adapt-lm, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size kaldi_adapt_lm-0.1.3-py2.py3-none-any.whl (10.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size kaldi-adapt-lm-0.1.3.tar.gz (4.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page