mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
n-best tree output
This commit is contained in:
parent
0a127cb0f1
commit
61c00ed636
@ -712,6 +712,8 @@ void IOWrapper::OutputNBestList(const ChartKBestExtractor::KBestVec &nBestList,
|
||||
bool includeWordAlignment =
|
||||
StaticData::Instance().PrintAlignmentInfoInNbest();
|
||||
|
||||
bool PrintNBestTrees = StaticData::Instance().PrintNBestTrees();
|
||||
|
||||
for (ChartKBestExtractor::KBestVec::const_iterator p = nBestList.begin();
|
||||
p != nBestList.end(); ++p) {
|
||||
const ChartKBestExtractor::Derivation &derivation = **p;
|
||||
@ -743,6 +745,12 @@ void IOWrapper::OutputNBestList(const ChartKBestExtractor::KBestVec &nBestList,
|
||||
}
|
||||
}
|
||||
|
||||
// optionally, print tree
|
||||
if (PrintNBestTrees) {
|
||||
TreePointer tree = ChartKBestExtractor::GetOutputTree(derivation);
|
||||
out << " ||| " << tree->GetString();
|
||||
}
|
||||
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
|
@ -128,6 +128,7 @@ public:
|
||||
void OutputBestNone(long translationId);
|
||||
void OutputNBestList(const std::vector<boost::shared_ptr<Moses::ChartKBestExtractor::Derivation> > &nBestList, long translationId);
|
||||
void OutputNBestList(const std::vector<search::Applied> &nbest, long translationId);
|
||||
void OutputNBestTrees(const std::vector<boost::shared_ptr<Moses::ChartKBestExtractor::Derivation> > &nBestList, long translationId);
|
||||
void OutputDetailedTranslationReport(const Moses::ChartHypothesis *hypo, const Moses::Sentence &sentence, long translationId);
|
||||
void OutputDetailedTranslationReport(const search::Applied *applied, const Moses::Sentence &sentence, long translationId);
|
||||
void OutputDetailedTreeFragmentsTranslationReport(const Moses::ChartHypothesis *hypo, const Moses::Sentence &sentence, long translationId);
|
||||
|
@ -124,6 +124,35 @@ Phrase ChartKBestExtractor::GetOutputPhrase(const Derivation &d)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Generate the target tree of the derivation d.
|
||||
TreePointer ChartKBestExtractor::GetOutputTree(const Derivation &d)
|
||||
{
|
||||
const ChartHypothesis &hypo = d.edge.head->hypothesis;
|
||||
const TargetPhrase &phrase = hypo.GetCurrTargetPhrase();
|
||||
if (const PhraseProperty *property = phrase.GetProperty("Tree")) {
|
||||
const std::string *tree = property->GetValueString();
|
||||
TreePointer mytree (boost::make_shared<InternalTree>(*tree));
|
||||
|
||||
//get subtrees (in target order)
|
||||
std::vector<TreePointer> previous_trees;
|
||||
for (size_t pos = 0; pos < phrase.GetSize(); ++pos) {
|
||||
const Word &word = phrase.GetWord(pos);
|
||||
if (word.IsNonTerminal()) {
|
||||
size_t nonTermInd = phrase.GetAlignNonTerm().GetNonTermIndexMap()[pos];
|
||||
const Derivation &subderivation = *d.subderivations[nonTermInd];
|
||||
const TreePointer prev_tree = GetOutputTree(subderivation);
|
||||
previous_trees.push_back(prev_tree);
|
||||
}
|
||||
}
|
||||
|
||||
mytree->Combine(previous_trees);
|
||||
return mytree;
|
||||
}
|
||||
else {
|
||||
UTIL_THROW2("Error: TreeStructureFeature active, but no internal tree structure found");
|
||||
}
|
||||
}
|
||||
|
||||
// Create an unweighted hyperarc corresponding to the given ChartHypothesis.
|
||||
ChartKBestExtractor::UnweightedHyperarc ChartKBestExtractor::CreateEdge(
|
||||
const ChartHypothesis &h)
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <cassert>
|
||||
#include "ChartHypothesis.h"
|
||||
#include "ScoreComponentCollection.h"
|
||||
#include "FF/InternalTree.h"
|
||||
|
||||
#include <boost/unordered_set.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
@ -89,6 +90,7 @@ public:
|
||||
std::size_t k, KBestVec &);
|
||||
|
||||
static Phrase GetOutputPhrase(const Derivation &);
|
||||
static TreePointer GetOutputTree(const Derivation &);
|
||||
|
||||
private:
|
||||
typedef boost::unordered_map<const ChartHypothesis *,
|
||||
|
@ -57,6 +57,7 @@ Parameter::Parameter()
|
||||
AddParam("max-trans-opt-per-coverage", "maximum number of translation options per input span (after applying mapping steps)");
|
||||
AddParam("max-phrase-length", "maximum phrase length (default 20)");
|
||||
AddParam("n-best-list", "file and size of n-best-list to be generated; specify - as the file in order to write to STDOUT");
|
||||
AddParam("n-best-trees", "Write n-best target-side trees (additional to normal n-best-list) to file {n-best-list-file}.trees");
|
||||
AddParam("lattice-samples", "generate samples from lattice, in same format as nbest list. Uses the file and size arguments, as in n-best-list");
|
||||
AddParam("n-best-factor", "factor to compute the maximum number of contenders (=factor*nbest-size). value 0 means infinity, i.e. no threshold. default is 0");
|
||||
AddParam("print-all-derivations", "to print all derivations in search graph");
|
||||
|
@ -431,6 +431,7 @@ bool StaticData::LoadData(Parameter *parameter)
|
||||
if (m_useConsensusDecoding) m_mbr=true;
|
||||
|
||||
SetBooleanParameter( &m_defaultNonTermOnlyForEmptyRange, "default-non-term-for-empty-range-only", false );
|
||||
SetBooleanParameter( &m_printNBestTrees, "n-best-trees", false );
|
||||
|
||||
|
||||
// Compact phrase table and reordering model
|
||||
|
@ -199,6 +199,7 @@ protected:
|
||||
FactorType m_placeHolderFactor;
|
||||
bool m_useLegacyPT;
|
||||
bool m_defaultNonTermOnlyForEmptyRange;
|
||||
bool m_printNBestTrees;
|
||||
|
||||
FeatureRegistry m_registry;
|
||||
PhrasePropertyFactory m_phrasePropertyFactory;
|
||||
@ -766,6 +767,10 @@ public:
|
||||
bool GetDefaultNonTermOnlyForEmptyRange() const
|
||||
{ return m_defaultNonTermOnlyForEmptyRange; }
|
||||
|
||||
bool PrintNBestTrees() const {
|
||||
return m_printNBestTrees;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user