Skip to content

Commit

Permalink
Pretty print, and show confidences of predictions
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan51 committed Aug 29, 2013
1 parent fd1b465 commit c980413
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions client/linguist.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,38 @@
import sys
from nupic.frameworks.opf.modelfactory import ModelFactory
import model_params
import re

NUM_REPEATS = 1000
PRINT_EVERY_REPEAT_N = 1

def clean(s):
return re.sub('\n', '|', s)

def prediction(inferences):
return clean("".join(inferences['multiStepBestPredictions'].values()))

def confidences(inferences):
c = ""
predictions = inferences['multiStepPredictions']
bestPredictions = inferences['multiStepBestPredictions']

for i in bestPredictions:
v = bestPredictions[i]
prediction = predictions[i]

if v in prediction:
probability = prediction[v]
else:
probability = 0

c += format(probability, ".2f")

if i < len(bestPredictions):
c += " | "

return c

def createModel():
return ModelFactory.create(model_params.MODEL_PARAMS)

Expand Down Expand Up @@ -62,8 +90,7 @@ def runLinguist(datapath):
result = model.run(modelInput)

if should_print:
prediction = "".join(result.inferences['multiStepBestPredictions'].values())
print "[%i]\t %s ==> %s" % (i, modelInput['letter'], prediction)
print "[%i]\t %s ==> %s\t(%s)" % (i, clean(modelInput['letter']), prediction(result.inferences), confidences(result.inferences))

i += 1

Expand Down

0 comments on commit c980413

Please sign in to comment.