Online command implementation in Moses

by prashantmathur

I am currently integrating the functionality Online Command in Moses developed by a colleague of mine. This functionality allows one to change the weights of the models at the time of decoding. There is a similar kind of functionality implemented in WIPO branch of Moses. Anyways, I’ll get to the problem.

In this functionality each line is a sentence or a weight. If one wants to change a language model’s weight to 0.5, just insert a line

@CMD@ weight-l 0.5

before the sentence whose model’s weight you want to modify. In order to do that, I need Moses to read the file one line at a time and not all at once.

Coming to coding, if you look at Main.cpp in directory moses-cmd/src/


InputType* source = NULL;
size_t lineCount = 0;
while(ReadInput(*ioWrapper,staticData.GetInputType(),source)) {
// set up task of translating one sentence
VERBOSE(3, “Setting up task of translating one sentence\n”);
TranslationTask* task =
new TranslationTask(lineCount,source, outputCollector.get(),
alignmentInfoCollector.get() );
// execute task


In this code if one is not using thread  pool.Submit(task)  should not be called. However, it is being called and I still have no idea why? Due to this all the lines in the input file were read at once in the threads and they were decoded after the threads were flushed. So, the last modified weight was applied to all the sentences which was bad!

So, I tried to figure out how not to let the code go in pool.Submit() fucntion. When I comment out

// pool.Submit(task);

The code worked like a charm. Although, commenting out these lines means the code is not thread safe anymore.

PS: If you want to download this functionality try out