You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by mj...@apache.org on 2016/06/03 21:01:39 UTC
[08/14] incubator-joshua git commit: Added k-best extraction (logic
is duplicated)
Added k-best extraction (logic is duplicated)
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/f4090b0f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/f4090b0f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/f4090b0f
Branch: refs/heads/joshua_api
Commit: f4090b0fb419b186d6c4aa395b046417763de0e4
Parents: 19aadf0
Author: Matt Post <po...@cs.jhu.edu>
Authored: Wed May 25 11:49:16 2016 -0400
Committer: Matt Post <po...@cs.jhu.edu>
Committed: Wed May 25 11:49:16 2016 -0400
----------------------------------------------------------------------
src/joshua/decoder/Decoder.java | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f4090b0f/src/joshua/decoder/Decoder.java
----------------------------------------------------------------------
diff --git a/src/joshua/decoder/Decoder.java b/src/joshua/decoder/Decoder.java
index 2cc8438..1a48110 100644
--- a/src/joshua/decoder/Decoder.java
+++ b/src/joshua/decoder/Decoder.java
@@ -45,6 +45,7 @@ import joshua.decoder.ff.FeatureFunction;
import joshua.decoder.ff.PhraseModel;
import joshua.decoder.ff.StatefulFF;
import joshua.decoder.ff.lm.LanguageModelFF;
+import joshua.decoder.ff.lm.StateMinimizingLanguageModel;
import joshua.decoder.ff.tm.Grammar;
import joshua.decoder.ff.tm.Rule;
import joshua.decoder.ff.tm.Trie;
@@ -498,16 +499,22 @@ public class Decoder {
}
KBestExtractor extractor = new KBestExtractor(sentence, hg, featureFunctions, weights, false, config);
- DerivationState viterbi = extractor.getViterbiDerivation();
- Translation best = new TranslationFactory(sentence, viterbi, config)
- .formattedTranslation(config.outputFormat)
+ int k = 1;
+ for (DerivationState derivation: extractor) {
+ if (k > config.topN || derivation == null)
+ break;
+
+ Translation t = new TranslationFactory(sentence, derivation, config)
+ .formattedTranslation(config.outputFormat)
.translation();
-
- Decoder.LOG(1, String.format("Translation %d: %.3f %s", sentence.id(), best.score(), best.toString()));
+
+ if (k == 1)
+ Decoder.LOG(1, String.format("Translation %d: %.3f %s", sentence.id(), t.score(), t.toString()));
- String bestString = best.getFormattedTranslation();
- out.write(bestString.getBytes());
- out.write("\n".getBytes());
+ String bestString = t.getFormattedTranslation();
+ out.write(bestString.getBytes());
+ out.write("\n".getBytes());
+ }
}
out.flush();