diff options
author | Wilker Aziz <will.aziz@gmail.com> | 2014-09-17 18:36:57 +0400 |
---|---|---|
committer | Wilker Aziz <will.aziz@gmail.com> | 2014-09-17 18:36:57 +0400 |
commit | 9d02e395f35da83a9052ab3c82b1d0152f89cad2 (patch) | |
tree | 9a74fff0176f69281ca32f873f9eda52fe9cdf98 | |
parent | 458de8b92bffe7ee8e865ee125cf84477899ec1a (diff) |
including oov to python example use of full_scores
-rw-r--r-- | python/example.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/python/example.py b/python/example.py index a43c45e..508c98d 100644 --- a/python/example.py +++ b/python/example.py @@ -11,14 +11,16 @@ print(model.score(sentence)) # Check that total full score = direct score def score(s): - return sum(prob for prob, _ in model.full_scores(s)) + return sum(prob for prob, _, _ in model.full_scores(s)) assert (abs(score(sentence) - model.score(sentence)) < 1e-3) # Show scores and n-gram matches words = ['<s>'] + sentence.split() + ['</s>'] -for i, (prob, length) in enumerate(model.full_scores(sentence)): - print('{0} {1} : {2}'.format(prob, length, ' '.join(words[i+2-length:i+2]))) +for i, (prob, length, oov) in enumerate(model.full_scores(sentence)): + print('{0} {1}: {2}'.format(prob, length, ' '.join(words[i+2-length:i+2]))) + if oov: + print '\t"{0}" is an OOV'.format(words[i+1]) # Find out-of-vocabulary words for w in words: |