Menu

Change N-gram on the fly

2014-07-15
2014-07-16
  • Dmytro Prylipko

    Dmytro Prylipko - 2014-07-15

    Hi,

    I need to replace N-gram LMs on the fly, without reloading the whole recognizer.
    It can be easily done for JSGFGrammar with loadJSGF, but I am not sure what is the correct way to do it for SimpleNGramModel.

    NB: I am still using the XML configs, and get access components via lookup, since the new API requires to reload the recognizer for every single recognition input.

    I tried to do it like this:

    ngram = (SimpleNGramModel) cm.lookup(NGRAM);
    ngramPS = cm.getPropertySheet(NGRAM);
    ngramPS.setString("location", LMFile.toURI().toURL().toString());
    ngram.newProperties(ngramPS);
    ngram.allocate();
    

    While I can see that e.g. component's vocabulary has been changed, the recognition output tells me that no real replacement has been made. Could you tell me whether it is possible and how?

    Thanks.

     
  • Alexander Solovets

    You must call SimpleNGramModel#deallocate() before changing properties.

     
  • Dmytro Prylipko

    Dmytro Prylipko - 2014-07-15

    Oops, I forgot to put a line above.
    I do deallocate it:

    ngram.deallocate();
    ngramPS.setString("location", LMFile.toURI().toURL().toString());
    ngram.newProperties(ngramPS);
    ngram.allocate();
    
     
  • Alexander Solovets

    This is the valid way to change properties: ConfigurationManagerUtils.setProperty(configurationManager, "simpleNGramModel->location", LMFile.toURI().toURL().toString()).

     
  • Dmytro Prylipko

    Dmytro Prylipko - 2014-07-15

    Ok, thanks.

    I will try it, but as far as I can see, call of ConfigurationManagerUtils.setProperty will lead to the same call of PropertySheet.setString (ConfigurationManagerUtils.java:666).

    I would like to know whether such a ngram swap should work all, without reallocation of the whole decoder (or linguist).

     
  • Dmytro Prylipko

    Dmytro Prylipko - 2014-07-16

    Usage of ConfigurationManagerUtils#setProperty provide me with the same result: the initial LM is not changed :(

     
  • Dmytro Prylipko

    Dmytro Prylipko - 2014-07-16

    Ok, I can see that reallocation of language model has no effect after HMMTree has been created in LexTreeLinguist. And I cannot see any existing way to force the HMMTree to be re-compiled...

     
    • Nickolay V. Shmyrev

      And I cannot see any existing way to force the HMMTree to be re-compiled...

      LexTreeLinguist.allocate()?

       
      • Dmytro Prylipko

        Dmytro Prylipko - 2014-07-16

        This causes everything to be reallocated: dictionary, acoustic model, HMM pool.

         
  • Dmytro Prylipko

    Dmytro Prylipko - 2014-07-16

    So, if anybody will face the same problem, you can add this method to LexTreeLinguist class:

    public void refreshHMMTree() {
        hmmTree = new HMMTree(hmmPool, dictionary, languageModel, addFillerWords, languageWeight);
    }
    
     

Log in to post a comment.

MongoDB Logo MongoDB