diff options
author | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-06-23 11:59:48 -0400 |
---|---|---|
committer | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-06-23 11:59:48 -0400 |
commit | b738e349be490c24d3604c224f44fc54e16d3d7b (patch) | |
tree | 5d435257ef3c0023daa2211eb7260c470dbb6cdc /python/test.py | |
parent | 0b27ea3f91d0ad2f2ed718839d308db3d1baf5ae (diff) |
Support for sparse/dense vectors in the python extension
- SparseVector, DenseVector
- improved Lattice
- Lattice translation
- Hypergraph reweighting, pruning
Diffstat (limited to 'python/test.py')
-rw-r--r-- | python/test.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/python/test.py b/python/test.py index 1542dd4f..92403298 100644 --- a/python/test.py +++ b/python/test.py @@ -19,14 +19,16 @@ with gzip.open(grammar_file) as f: # Input sentence sentence = u'澳洲 是 与 北韩 有 邦交 的 少数 国家 之一 。' -print 'Input:', sentence +print ' Input:', sentence.encode('utf8') # Decode forest = decoder.translate(sentence, grammar=grammar) # Get viterbi translation print 'Output[0]:', forest.viterbi().encode('utf8') -print ' Tree[0]:', forest.viterbi_tree().encode('utf8') +print ' ETree[0]:', forest.viterbi_tree().encode('utf8') +print ' FTree[0]:', forest.viterbi_source_tree().encode('utf8') +print 'LgProb[0]:', forest.viterbi_features().dot(decoder.weights) # Get k-best translations for i, (sentence, tree) in enumerate(zip(forest.kbest(5), forest.kbest_tree(5)), 1): @@ -37,6 +39,9 @@ for i, (sentence, tree) in enumerate(zip(forest.kbest(5), forest.kbest_tree(5)), for sentence in forest.sample(5): print 'Sample:', sentence.encode('utf8') +# Get feature vector for 1best +fsrc = forest.viterbi_features() + # 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),),) @@ -44,6 +49,12 @@ lat = cdec.Lattice(lattice) assert (lattice == tuple(lat)) # Intersect forest and lattice -forest.intersect(lat) +assert forest.intersect(lat) + # Get best synchronous parse print forest.viterbi_tree() +print forest.viterbi_source_tree() + +# Compare 1best and reference feature vectors +fref = forest.viterbi_features() +print dict(fsrc - fref) |