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 | 7b0e318e5c9e33c6191b1d1e2d7350d961555d4e (patch) | |
tree | d8862b74db0e11e01edb647a8ba85654ef1475a2 /python/test.py | |
parent | 0695d80013ef4994142d8a069424ea57e45a9d80 (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) |