language model adaptation

Christopher Kermorvant kermorvant at gmail.com
Wed Aug 31 07:51:53 PDT 2005


HelloSriLM users,

I am looking for a way to save language models adapted with 

ngram -adapt-marginals.

Is it possible ?

As the write method for AdaptiveMarginals is not implemented, I tried to 
write one (copied from writeWithOrder in NgramLM.cc) , by calling 
wordProb(pword,context+1) instead of iterating on the tree, but it doesn't 
seem to work. The probabilities I get in the file, are not the same as the 
one I get if I parse a text file with ppl option (precisely, alphas are the 
same, but denominators are different). 

Any clue or solution to save an adapted model are welcome !

Thank you,

--
Christopher Kermorvant 


void
AdaptiveMarginals::write(File &file)
{
this->running(true) ;
Ngram * lm = (Ngram*)&baseLM;
unsigned i;
unsigned howmanyNgrams[maxNgramOrder + 1];
VocabIndex context[maxNgramOrder + 2];
VocabString scontext[maxNgramOrder + 1];
unsigned order=lm->setorder(); 
if (order > maxNgramOrder) {
order = maxNgramOrder;
}

fprintf(file, "\n\\data\\\n");

for (i = 1; i <= order; i++ ) {
howmanyNgrams[i] = lm->numNgrams(i);
fprintf(file, "ngram %d=%d\n", i, howmanyNgrams[i]);
}

for (i = 1; i <= order; i++ ) {
fprintf(file, "\n\\%d-grams:\n", i);

if (debug(DEBUG_WRITE_STATS)) {
dout() << "writing " << howmanyNgrams[i] << " "
<< i << "-grams\n";
}

NgramBOsIter iter(*lm, context + 1, i - 1, vocab.compareIndex());
BOnode *node;

while (node = iter.next()) {

vocab.getWords(context + 1, scontext, maxNgramOrder + 1);
Vocab::reverse(scontext);

NgramProbsIter piter(*node, vocab.compareIndex());
VocabIndex pword;
LogP *prob;
LogP probAd ;
while (prob = piter.next(pword)) {
if (file.error()) {
return;
}
context[0] = pword;
probAd = wordProb(pword,context+1);
*prob = probAd ;
fprintf(file, "%.*lg\t", LogP_Precision,
(double)(*prob == LogP_Zero ?
LogP_PseudoZero : *prob));
Vocab::write(file, scontext);
fprintf(file, "%s%s", (i > 1 ? " " : ""), vocab.getWord(pword));

if (i < order) {
context[0] = pword;

LogP *bow = lm->findBOW(context);
if (bow) {
fprintf(file, "\t%.*lg", LogP_Precision,
(double)(*bow == LogP_Zero ?
LogP_PseudoZero : *bow));
}
}

fprintf(file, "\n");
}
}
}

fprintf(file, "\n\\end\\\n");
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.speech.sri.com/pipermail/srilm-user/attachments/20050831/844ccdda/attachment.html>


More information about the SRILM-User mailing list