summaryrefslogtreecommitdiff
path: root/hopefear.rb
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2014-03-03 18:05:27 +0100
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2014-03-03 18:05:27 +0100
commitbe750ff96f4be1a1b14633ed7bd2c039b7fbf048 (patch)
tree7072b91e291df30dfaf3f99bb916ccc681763611 /hopefear.rb
parent531f6e06cfdd145ac6e6589a0d0d520e84417481 (diff)
comments, rm dead code
Diffstat (limited to 'hopefear.rb')
-rw-r--r--hopefear.rb67
1 files changed, 22 insertions, 45 deletions
diff --git a/hopefear.rb b/hopefear.rb
index 918b71f..ef1fd43 100644
--- a/hopefear.rb
+++ b/hopefear.rb
@@ -19,10 +19,10 @@ def gethopefear_standard kbest, feedback
hope = kbest[0]
type1 = true
else
- hope = hope_and_fear(kbest, 'hope')
+ hope = hope_and_fear kbest, 'hope'
type2 = true
end
- fear = hope_and_fear(kbest, 'fear')
+ fear = hope_and_fear kbest, 'fear'
return hope, fear, false, type1, type2
end
@@ -33,10 +33,12 @@ def gethopefear_fear_no_exec kbest, feedback, gold, max
hope = kbest[0]
type1 = true
else
- hope = hope_and_fear(kbest, 'hope')
+ hope = hope_and_fear kbest, 'hope'
type2 = true
end
- kbest.sort{|x,y|(y.scores[:decoder]+y.scores[:psb])<=>(x.scores[:decoder]+x.scores[:psb])}.each_with_index { |k,i|
+ # sorted in descending order by max(decoder, psb), best ('hope') first
+ # select the 'best' translation that does not deliver the correct answer
+ kbest.sort{ |x,y| (y.scores[:decoder]+y.scores[:psb])<=>(x.scores[:decoder]+x.scores[:psb]) }.each_with_index { |k,i|
break if i==max
if !exec(k.s, gold, true)[0]
fear = k
@@ -54,10 +56,11 @@ def gethopefear_fear_no_exec_skip kbest, feedback, gold
hope = kbest[0]
type1 = true
else
- hope = hope_and_fear(kbest, 'hope')
+ hope = hope_and_fear kbest, 'hope'
type2 = true
end
fear = hope_and_fear(kbest, 'fear')
+ # skip example if fear gives the right answer
skip = exec(fear.s, gold, true)[0]
return hope, fear, skip, type1, type2
end
@@ -65,11 +68,13 @@ end
def gethopefear_fear_no_exec_hope_exec kbest, feedback, gold, max
hope = fear = nil; hope_idx = 0
type1 = type2 = false
- sorted_kbest = kbest.sort{|x,y|(y.scores[:decoder]+y.scores[:psb])<=>(x.scores[:decoder]+x.scores[:psb])}
+ # sorted in descending order by max(decoder, psb), best ('hope') first
+ sorted_kbest = kbest.sort{ |x,y| (y.scores[:decoder]+y.scores[:psb])<=>(x.scores[:decoder]+x.scores[:psb]) }
if feedback == true
hope = kbest[0]
type1 = true
else
+ # select 'best' translation that correctly executes
sorted_kbest.each_with_index { |k,i|
next if i==0
break if i==max
@@ -81,6 +86,7 @@ def gethopefear_fear_no_exec_hope_exec kbest, feedback, gold, max
}
type2 = true
end
+ # select 'best' translation that does not correctly execute
sorted_kbest.each_with_index { |k,i|
break if i>(kbest.size-(hope_idx+1))||i==max
if !exec(k.s, gold, true)[0]
@@ -88,6 +94,7 @@ def gethopefear_fear_no_exec_hope_exec kbest, feedback, gold, max
break
end
}
+ # skip if hope or fear could no be found
skip = true if !hope||!fear
return hope, fear, skip, type1, type2
end
@@ -99,15 +106,15 @@ def gethopefear_fear_no_exec_hope_exec_skip kbest, feedback, gold, max
hope = kbest[0]
type1 = true
else
- hope = hope_and_fear(kbest, 'hope')
+ hope = hope_and_fear kbest, 'hope'
type2 = true
end
- fear = hope_and_fear(kbest, 'fear')
+ fear = hope_and_fear kbest, 'fear'
+ # skip if fear executes correctly or hope doesn't
skip = exec(fear.s, gold, true)[0]||!exec(hope.s, gold, true)[0]
return hope, fear, skip, type1, type2
end
-
def gethopefear_only_exec kbest, feedback, gold, max, own_reference=nil
hope = fear = nil; hope_idx = 0; new_reference = nil
type1 = type2 = false
@@ -119,6 +126,7 @@ def gethopefear_only_exec kbest, feedback, gold, max, own_reference=nil
hope = own_reference
type1 = true
else
+ # search for first (by decoder score) translation that gives the correct answer
kbest.each_with_index { |k,i|
next if i==0
break if i==max
@@ -130,40 +138,7 @@ def gethopefear_only_exec kbest, feedback, gold, max, own_reference=nil
}
type2 = true
end
- kbest.each_with_index { |k,i|
- next if i==0||i==hope_idx
- break if i==max
- if !exec(k.s, gold, true)[0]
- fear = k
- break
- end
- }
- skip = true if !hope||!fear
- return hope, fear, skip, type1, type2, new_reference
-end
-
-def gethopefear_only_exec_simple kbest, feedback, gold, max, own_reference=nil
- hope = fear = nil; hope_idx = 0; new_reference = nil
- type1 = type2 = false
- if feedback == true
- hope = kbest[0]
- new_reference = hope
- type1 = true
- elsif own_reference
- hope = own_reference
- type1 = true
- else
- kbest.each_with_index { |k,i|
- next if i==0
- break if i==max
- if exec(k.s, gold, true)[0]
- hope_idx = i
- hope = k
- break
- end
- }
- type2 = true
- end
+ # --"-- doesn't give the correct answer
kbest.each_with_index { |k,i|
next if i==0||i==hope_idx
break if i==max
@@ -179,12 +154,14 @@ end
def gethopefear_rampion kbest, reference
hope = fear = nil
type1 = type2 = false
+ # 1best is automatically hope if it matches reference
if kbest[0].s == reference
hope = kbest[0]
- fear = hope_and_fear(kbest, 'fear')
+ fear = hope_and_fear kbest, 'fear'
type1 = true
else
- hope = hope_and_fear(kbest, 'hope')
+ hope = hope_and_fear kbest, 'hope'
+ # 1best is automatically fear if it doesn't match reference
fear = kbest[0]
type2 = true
end