Merge branch 'master' of ssh://github.com/moses-smt/mosesdecoder

This commit is contained in:
phikoehn 2014-01-03 18:45:45 +00:00
commit 6846089089
5 changed files with 25 additions and 28 deletions

View File

@ -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);
}

View File

@ -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')

View File

@ -1,4 +1,3 @@
#include "util/check.hh"
#include <stdexcept>
#include <iostream>
#include <vector>
@ -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&>(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<string, xmlrpc_c::value> 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;
}

View File

@ -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<std::vector<float> > 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<std::string,multiModelStatistics*>* allStats = new(std::map<std::string,multiModelStatistics*>);
@ -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<float> PhraseDictionaryMultiModel::MinimizePerplexity(vector<pair<string,
CleanUpAfterSentenceProcessing(sentence); // free memory used by compact phrase tables
size_t numWeights = m_numScoreComponents;
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
numWeights = m_numScoreComponents-1;
}
vector<float> ret (m_numModels*numWeights);
for (size_t iFeature=0; iFeature < numWeights; iFeature++) {

View File

@ -243,12 +243,11 @@ TargetPhraseCollection* PhraseDictionaryMultiModelCounts::CreateTargetPhraseColl
double lexst = ComputeWeightedLexicalTranslation(static_cast<const Phrase&>(*statistics->targetPhrase), src, alignedToS, m_lexTable_e2f, multimodelweights[1], false );
double lexts = ComputeWeightedLexicalTranslation(src, static_cast<const Phrase&>(*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);