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/09/14 09:11:33 UTC
[11/43] incubator-joshua git commit: simplification of distortion
computation
simplification of distortion computation
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/f7cf2e0b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/f7cf2e0b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/f7cf2e0b
Branch: refs/heads/7
Commit: f7cf2e0b6262c7d6f422944e327e7d97301c9ada
Parents: ffd9562
Author: Matt Post <po...@cs.jhu.edu>
Authored: Thu Sep 8 16:35:09 2016 -0400
Committer: Matt Post <po...@cs.jhu.edu>
Committed: Thu Sep 8 16:35:09 2016 -0400
----------------------------------------------------------------------
.../joshua/decoder/ff/phrase/Distortion.java | 28 +++++++++++++-------
.../apache/joshua/decoder/phrase/Candidate.java | 2 +-
.../joshua/decoder/phrase/Hypothesis.java | 4 +--
.../org/apache/joshua/decoder/phrase/Stack.java | 4 +--
4 files changed, 23 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f7cf2e0b/src/main/java/org/apache/joshua/decoder/ff/phrase/Distortion.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/ff/phrase/Distortion.java b/src/main/java/org/apache/joshua/decoder/ff/phrase/Distortion.java
index a0f1e16..dd22a9d 100644
--- a/src/main/java/org/apache/joshua/decoder/ff/phrase/Distortion.java
+++ b/src/main/java/org/apache/joshua/decoder/ff/phrase/Distortion.java
@@ -56,26 +56,34 @@ public class Distortion extends StatelessFF {
public DPState compute(Rule rule, List<HGNode> tailNodes, int i, int j, SourcePath sourcePath,
Sentence sentence, Accumulator acc) {
- if (rule == Hypothesis.MONO_RULE || rule == Hypothesis.SWAP_RULE) {
+ if (rule == Hypothesis.INORDER_RULE || rule == Hypothesis.INVERTED_RULE) {
// int start_point = j - rule.getFrench().length + rule.getArity();
// int jump_size = Math.abs(tailNodes.get(0).j - start_point);
- if (rule == Hypothesis.MONO_RULE) {
- int start_point = j - tailNodes.get(1).getHyperEdges().get(0).getRule().getFrench().length;
- int last_point = tailNodes.get(0).j;
- int jump_size = Math.abs(start_point - last_point);
+ if (rule == Hypothesis.INORDER_RULE) {
+ int last_phrase_end = tailNodes.get(0).j;
+ int new_phrase_start = tailNodes.get(1).i;
+ int jump_size = Math.abs(last_phrase_end - new_phrase_start);
+
+// int start_point = j - tailNodes.get(1).getHyperEdges().get(0).getRule().getFrench().length;
+// int last_point = tailNodes.get(0).j;
+// int jump_size = Math.abs(start_point - last_point);
// System.err.println(String.format("DISTORTION_mono(%d -> %d) = %d",
-// last_point, start_point, jump_size));
+// last_phrase_end, new_phrase_start, jump_size));
acc.add(denseFeatureIndex, -jump_size);
} else {
- int start_point = j - tailNodes.get(0).getHyperEdges().get(0).getRule().getFrench().length;
- int last_point = tailNodes.get(1).j;
- int jump_size = Math.abs(start_point - last_point);
+ int last_phrase_end = tailNodes.get(1).j;
+ int new_phrase_start = tailNodes.get(0).i;
+ int jump_size = Math.abs(last_phrase_end - new_phrase_start);
+
+// int start_point = j - tailNodes.get(0).getHyperEdges().get(0).getRule().getFrench().length;
+// int last_point = tailNodes.get(1).j;
+// int jump_size = Math.abs(start_point - last_point);
// System.err.println(String.format("DISTORTION_swap(%d -> %d) = %d",
-// last_point, start_point, jump_size));
+// last_phrase_end, new_phrase_start, jump_size));
acc.add(denseFeatureIndex, -jump_size);
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f7cf2e0b/src/main/java/org/apache/joshua/decoder/phrase/Candidate.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/phrase/Candidate.java b/src/main/java/org/apache/joshua/decoder/phrase/Candidate.java
index 883bcfb..f340ae3 100644
--- a/src/main/java/org/apache/joshua/decoder/phrase/Candidate.java
+++ b/src/main/java/org/apache/joshua/decoder/phrase/Candidate.java
@@ -120,7 +120,7 @@ public class Candidate implements Comparable<Candidate> {
this.phrases = phrases;
this.future_delta = delta;
this.ranks = ranks;
- this.rule = isMonotonic() ? Hypothesis.MONO_RULE : Hypothesis.SWAP_RULE;
+ this.rule = isMonotonic() ? Hypothesis.INORDER_RULE : Hypothesis.INVERTED_RULE;
// this.score = hypotheses.get(ranks[0]).score + phrases.get(ranks[1]).getEstimatedCost();
this.computedResult = null;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f7cf2e0b/src/main/java/org/apache/joshua/decoder/phrase/Hypothesis.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/phrase/Hypothesis.java b/src/main/java/org/apache/joshua/decoder/phrase/Hypothesis.java
index 2710a48..8e11345 100644
--- a/src/main/java/org/apache/joshua/decoder/phrase/Hypothesis.java
+++ b/src/main/java/org/apache/joshua/decoder/phrase/Hypothesis.java
@@ -44,8 +44,8 @@ public class Hypothesis extends HGNode implements Comparable<Hypothesis> {
public static Rule BEGIN_RULE = new HieroFormatReader().parseLine("[GOAL] ||| <s> ||| <s> ||| ||| 0-0");
public static Rule END_RULE = new HieroFormatReader().parseLine("[GOAL] ||| </s> ||| </s> ||| ||| 0-0");
- public static Rule MONO_RULE = new HieroFormatReader().parseLine("[GOAL] ||| [GOAL,1] [X,2] ||| [GOAL,1] [X,2] ||| ||| 0-0 1-1");
- public static Rule SWAP_RULE = new HieroFormatReader().parseLine("[GOAL] ||| [X,1] [GOAL,2] ||| [GOAL,2] [X,1] ||| ||| 0-1 1-0");
+ public static Rule INORDER_RULE = new HieroFormatReader().parseLine("[GOAL] ||| [GOAL,1] [X,2] ||| [GOAL,1] [X,2] ||| ||| 0-0 1-1");
+ public static Rule INVERTED_RULE = new HieroFormatReader().parseLine("[GOAL] ||| [X,1] [GOAL,2] ||| [GOAL,2] [X,1] ||| ||| 0-1 1-0");
public String toString() {
StringBuffer sb = new StringBuffer();
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f7cf2e0b/src/main/java/org/apache/joshua/decoder/phrase/Stack.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/phrase/Stack.java b/src/main/java/org/apache/joshua/decoder/phrase/Stack.java
index 0ff025f..08ab241 100644
--- a/src/main/java/org/apache/joshua/decoder/phrase/Stack.java
+++ b/src/main/java/org/apache/joshua/decoder/phrase/Stack.java
@@ -147,9 +147,9 @@ public class Stack extends ArrayList<Hypothesis> {
/* Get the rule. If if it's a swap or monolingual rule, find the right backpointer */
Rule rule = cand.getHypothesis().getRule();
- if (rule == Hypothesis.MONO_RULE)
+ if (rule == Hypothesis.INORDER_RULE)
rule = cand.getHypothesis().bestHyperedge.getTailNodes().get(1).bestHyperedge.getRule();
- else if (rule == Hypothesis.SWAP_RULE)
+ else if (rule == Hypothesis.INVERTED_RULE)
rule = cand.getHypothesis().bestHyperedge.getTailNodes().get(0).bestHyperedge.getRule();
String oldWords = rule.getEnglishWords();