Skip to content

Commit 1c45d78

Browse files
committed
all-restrict mode for MultiModel (restrict to phrases in first model)
1 parent 97e5a30 commit 1c45d78

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

moses/TranslationModel/PhraseDictionaryMultiModel.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ PhraseDictionaryMultiModel::PhraseDictionaryMultiModel(const std::string &line)
3535
UTIL_THROW_IF2(m_pdStr.size() != m_multimodelweights.size() &&
3636
m_pdStr.size()*numWeights != m_multimodelweights.size(),
3737
"Number of scores and weights are not equal");
38-
} else if (m_mode == "all") {
38+
} else if (m_mode == "all" || m_mode == "all-restrict") {
3939
size_t componentWeights = 0;
4040
for(size_t i = 0; i < m_numModels; ++i) {
4141
const string &ptName = m_pdStr[i];
@@ -115,7 +115,9 @@ const TargetPhraseCollection *PhraseDictionaryMultiModel::GetTargetPhraseCollect
115115
RemoveAllInMap(*allStats);
116116
delete allStats;
117117
} else if (m_mode == "all") {
118-
ret = CreateTargetPhraseCollectionAll(src);
118+
ret = CreateTargetPhraseCollectionAll(src, false);
119+
} else if (m_mode == "all-restrict") {
120+
ret = CreateTargetPhraseCollectionAll(src, true);
119121
}
120122

121123
ret->NthElement(m_tableLimit); // sort the phrases for pruning later
@@ -204,7 +206,7 @@ TargetPhraseCollection* PhraseDictionaryMultiModel::CreateTargetPhraseCollection
204206
return ret;
205207
}
206208

207-
TargetPhraseCollection* PhraseDictionaryMultiModel::CreateTargetPhraseCollectionAll(const Phrase& src) const
209+
TargetPhraseCollection* PhraseDictionaryMultiModel::CreateTargetPhraseCollectionAll(const Phrase& src, const bool restricted) const
208210
{
209211
// Collect phrases from all models
210212
std::map<std::string, multiModelPhrase*> allPhrases;
@@ -227,7 +229,12 @@ TargetPhraseCollection* PhraseDictionaryMultiModel::CreateTargetPhraseCollection
227229
std::vector<float> raw_scores = targetPhrase->GetScoreBreakdown().GetScoresForProducer(&pd);
228230

229231
std::string targetString = targetPhrase->GetStringRep(m_output);
232+
// Phrase not in collection -> add if unrestricted (all) or first model (all-restrict)
230233
if (allPhrases.find(targetString) == allPhrases.end()) {
234+
// all-restrict and not first model: skip adding unseen phrase
235+
if (restricted && i > 0) {
236+
continue;
237+
}
231238

232239
multiModelPhrase* phrase = new multiModelPhrase;
233240
phrase->targetPhrase = new TargetPhrase(*targetPhrase); //make a copy so that we don't overwrite the original phrase table info

moses/TranslationModel/PhraseDictionaryMultiModel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class PhraseDictionaryMultiModel: public PhraseDictionary
7474
void Load();
7575
virtual void CollectSufficientStatistics(const Phrase& src, std::map<std::string,multiModelStatistics*>* allStats) const;
7676
virtual TargetPhraseCollection* CreateTargetPhraseCollectionLinearInterpolation(const Phrase& src, std::map<std::string,multiModelStatistics*>* allStats, std::vector<std::vector<float> > &multimodelweights) const;
77-
virtual TargetPhraseCollection* CreateTargetPhraseCollectionAll(const Phrase& src) const;
77+
virtual TargetPhraseCollection* CreateTargetPhraseCollectionAll(const Phrase& src, const bool restricted = false) const;
7878
std::vector<std::vector<float> > getWeights(size_t numWeights, bool normalize) const;
7979
std::vector<float> normalizeWeights(std::vector<float> &weights) const;
8080
void CacheForCleanup(TargetPhraseCollection* tpc);

0 commit comments

Comments
 (0)