diff options
author | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-08-01 17:32:37 +0200 |
---|---|---|
committer | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-08-01 17:32:37 +0200 |
commit | 3f8e33cfe481a09c121a410e66a6074b5d05683e (patch) | |
tree | a41ecaf0bbb69fa91a581623abe89d41219c04f8 /python/test.py | |
parent | c139ce495861bb341e1b86a85ad4559f9ad53c14 (diff) | |
parent | 9fe0219562e5db25171cce8776381600ff9a5649 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'python/test.py')
-rw-r--r-- | python/test.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/python/test.py b/python/test.py index 8069aa0a..eb9e6a95 100644 --- a/python/test.py +++ b/python/test.py @@ -2,12 +2,11 @@ import cdec import gzip -config = 'formalism=scfg' weights = '../tests/system_tests/australia/weights' grammar_file = '../tests/system_tests/australia/australia.scfg.gz' # Load decoder width configuration -decoder = cdec.Decoder(config) +decoder = cdec.Decoder(formalism='scfg') # Read weights decoder.read_weights(weights) @@ -26,15 +25,17 @@ forest = decoder.translate(sentence, grammar=grammar) # Get viterbi translation print 'Output[0]:', forest.viterbi().encode('utf8') -print ' ETree[0]:', forest.viterbi_tree().encode('utf8') -print ' FTree[0]:', forest.viterbi_source_tree().encode('utf8') +f_tree, e_tree = forest.viterbi_trees() +print ' FTree[0]:', f_tree.encode('utf8') +print ' ETree[0]:', e_tree.encode('utf8') print 'LgProb[0]:', forest.viterbi_features().dot(decoder.weights) # Get k-best translations -kbest = zip(forest.kbest(5), forest.kbest_tree(5), forest.kbest_features(5)) -for i, (sentence, tree, features) in enumerate(kbest, 1): +kbest = zip(forest.kbest(5), forest.kbest_trees(5), forest.kbest_features(5)) +for i, (sentence, (f_tree, e_tree), features) in enumerate(kbest, 1): print 'Output[%d]:' % i, sentence.encode('utf8') - print ' Tree[%d]:' % i, tree.encode('utf8') + print ' FTree[%d]:' % i, f_tree.encode('utf8') + print ' ETree[%d]:' % i, e_tree.encode('utf8') print ' FVect[%d]:' % i, dict(features) # Sample translations from the forest @@ -44,6 +45,9 @@ for sentence in forest.sample(5): # Get feature vector for 1best fsrc = forest.viterbi_features() +# Feature expectations +print 'Feature expectations:', dict(forest.inside_outside()) + # Reference lattice lattice = ((('australia',0,1),),(('is',0,1),),(('one',0,1),),(('of',0,1),),(('the',0,4),('a',0,4),('a',0,1),('the',0,1),),(('small',0,1),('tiny',0,1),('miniscule',0,1),('handful',0,2),),(('number',0,1),('group',0,1),),(('of',0,2),),(('few',0,1),),(('countries',0,1),),(('that',0,1),),(('has',0,1),('have',0,1),),(('diplomatic',0,1),),(('relations',0,1),),(('with',0,1),),(('north',0,1),),(('korea',0,1),),(('.',0,1),),) @@ -54,8 +58,9 @@ assert (lattice == tuple(lat)) assert forest.intersect(lat) # Get best synchronous parse -print forest.viterbi_tree() -print forest.viterbi_source_tree() +f_tree, e_tree = forest.viterbi_trees() +print 'FTree:', f_tree.encode('utf8') +print 'ETree:', e_tree.encode('utf8') # Compare 1best and reference feature vectors fref = forest.viterbi_features() |