diff --git a/contrib/relent-filter/src/LatticeMBRGrid.cpp b/contrib/relent-filter/src/LatticeMBRGrid.cpp index 71c387839..bbef5f938 100755 --- a/contrib/relent-filter/src/LatticeMBRGrid.cpp +++ b/contrib/relent-filter/src/LatticeMBRGrid.cpp @@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "Manager.h" #include "StaticData.h" +#include "util/exception.hh" using namespace std; using namespace Moses; @@ -68,7 +69,7 @@ public: /** Add a parameter with key, command line argument, and default value */ void addParam(gridkey key, const string& arg, float defaultValue) { m_args[arg] = key; - CHECK(m_grid.find(key) == m_grid.end()); + UTIL_THROW_IF2(m_grid.find(key) != m_grid.end(), "Duplicate parameter " << arg); m_grid[key].push_back(defaultValue); } diff --git a/contrib/server/client_multimodel.py b/contrib/server/client_multimodel.py index 3f7d670d7..bf4016cad 100755 --- a/contrib/server/client_multimodel.py +++ b/contrib/server/client_multimodel.py @@ -16,12 +16,21 @@ else: import xmlrpc.client as xmlrpclib -def translate(input_object, server, weights=None): +def translate(input_object, server, weights=None, model_name=None): + """translate each sentence in an input_object (list, file-like object or other object that iterates over sentences) + server is a xmlrpclib.ServerProxy + model_name is the name of the PhraseDictionaryMultiModel(Counts) feature function that the weights should be applied to. It is defined in the moses.ini + weights is a list of floats (one float per model, or one float per model per feature) + """ for line in input_object: params = {} params['text'] = line if weights: + if not model_name: + sys.stderr.write("Error: if you define weights, you need to specify the feature to which the weights are to be applied (e.g. PhraseDictionaryMultiModel0)\n") + sys.exit(1) + params['model_name'] = model_name params['lambda'] = weights print server.translate(params) @@ -77,4 +86,4 @@ if __name__ == '__main__': phrase_pairs = read_phrase_pairs(gzip.open('/path/to/moses-regression-tests/models/multimodel/extract.sorted.gz')) weights = optimize(phrase_pairs, server, 'PhraseDictionaryMultiModelCounts0') - translate(sys.stdin, server, weights) + translate(sys.stdin, server, weights, 'PhraseDictionaryMultiModelCounts0') \ No newline at end of file diff --git a/contrib/server/mosesserver.cpp b/contrib/server/mosesserver.cpp index 86b9f2029..25e2cb0ed 100644 --- a/contrib/server/mosesserver.cpp +++ b/contrib/server/mosesserver.cpp @@ -1,4 +1,3 @@ -#include "util/check.hh" #include #include #include @@ -237,17 +236,19 @@ public: } } + si = params.find("model_name"); + if (si != params.end() && multiModelWeights.size() > 0) { + const string model_name = xmlrpc_c::value_string(si->second); + PhraseDictionaryMultiModel* pdmm = (PhraseDictionaryMultiModel*) FindPhraseDictionary(model_name); + pdmm->SetTemporaryMultiModelWeightsVector(multiModelWeights); + } + const StaticData &staticData = StaticData::Instance(); if (addGraphInfo) { (const_cast(staticData)).SetOutputSearchGraph(true); } - if (multiModelWeights.size() > 0) { - PhraseDictionaryMultiModel* pdmm = (PhraseDictionaryMultiModel*) PhraseDictionary::GetColl()[0]; //TODO: only works if multimodel is first phrase table - pdmm->SetTemporaryMultiModelWeightsVector(multiModelWeights); - } - stringstream out, graphInfo, transCollOpts; map retData; @@ -534,7 +535,6 @@ int main(int argc, char** argv) } else { myAbyssServer.run(); } - // xmlrpc_c::serverAbyss.run() never returns - CHECK(false); - return 0; + std::cerr << "xmlrpc_c::serverAbyss.run() returned but should not." << std::endl; + return 1; } diff --git a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp index 3ddf5b516..40d2e50c5 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp @@ -37,9 +37,6 @@ PhraseDictionaryMultiModel::PhraseDictionaryMultiModel(const std::string &line) } size_t numWeights = m_numScoreComponents; - if (m_mode == "interpolate") { - numWeights--; - } UTIL_THROW_IF2(m_pdStr.size() != m_multimodelweights.size() & m_pdStr.size()*numWeights != m_multimodelweights.size(), "Number of scores and weights are not equal"); @@ -95,9 +92,7 @@ const TargetPhraseCollection *PhraseDictionaryMultiModel::GetTargetPhraseCollect std::vector > multimodelweights; if (m_mode == "interpolate") { - //interpolation of phrase penalty is skipped, and fixed-value (2.718) is used instead. results will be screwed up if phrase penalty is not last feature - size_t numWeights = m_numScoreComponents-1; - multimodelweights = getWeights(numWeights, true); + multimodelweights = getWeights(m_numScoreComponents, true); } std::map* allStats = new(std::map); @@ -181,13 +176,10 @@ TargetPhraseCollection* PhraseDictionaryMultiModel::CreateTargetPhraseCollection Scores scoreVector(m_numScoreComponents); - for(size_t i = 0; i < m_numScoreComponents-1; ++i) { + for(size_t i = 0; i < m_numScoreComponents; ++i) { scoreVector[i] = TransformScore(std::inner_product(statistics->p[i].begin(), statistics->p[i].end(), multimodelweights[i].begin(), 0.0)); } - //assuming that last value is phrase penalty - scoreVector[m_numScoreComponents-1] = 1.0; - statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector); //correct future cost estimates and total score @@ -377,10 +369,6 @@ vector PhraseDictionaryMultiModel::MinimizePerplexity(vector ret (m_numModels*numWeights); for (size_t iFeature=0; iFeature < numWeights; iFeature++) { diff --git a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp index b56525014..04bb321d0 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp @@ -243,12 +243,11 @@ TargetPhraseCollection* PhraseDictionaryMultiModelCounts::CreateTargetPhraseColl double lexst = ComputeWeightedLexicalTranslation(static_cast(*statistics->targetPhrase), src, alignedToS, m_lexTable_e2f, multimodelweights[1], false ); double lexts = ComputeWeightedLexicalTranslation(src, static_cast(*statistics->targetPhrase), alignedToT, m_lexTable_f2e, multimodelweights[3], true ); - Scores scoreVector(5); + Scores scoreVector(4); scoreVector[0] = FloorScore(TransformScore(m_combineFunction(statistics->fst, statistics->ft, multimodelweights[0]))); scoreVector[1] = FloorScore(TransformScore(lexst)); scoreVector[2] = FloorScore(TransformScore(m_combineFunction(statistics->fst, fs, multimodelweights[2]))); scoreVector[3] = FloorScore(TransformScore(lexts)); - scoreVector[4] = FloorScore(TransformScore(2.718)); statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector);