Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kpu/kenlm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilker Aziz <will.aziz@gmail.com>2014-09-17 18:36:57 +0400
committerWilker Aziz <will.aziz@gmail.com>2014-09-17 18:36:57 +0400
commit9d02e395f35da83a9052ab3c82b1d0152f89cad2 (patch)
tree9a74fff0176f69281ca32f873f9eda52fe9cdf98
parent458de8b92bffe7ee8e865ee125cf84477899ec1a (diff)
including oov to python example use of full_scores
-rw-r--r--python/example.py8
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: