Skip to content

Instantly share code, notes, and snippets.

@espeed
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save espeed/ec085a79542b51b5d89a to your computer and use it in GitHub Desktop.
Save espeed/ec085a79542b51b5d89a to your computer and use it in GitHub Desktop.
import timeit
import pickle
import nltk.data
from nltk.util import ngrams
t0 = timeit.default_timer()
fin = open("C:/Users/ned/Desktop/gherkin.pickle","rb")
classifier = pickle.load(fin)
t1 = timeit.default_timer()
load_time = t1-t0
print "LOAD TIME: ", load_time
words = ['boring', 'and', 'stupid', 'movie']
ngram_list = words + list(ngrams(words, 2)) + list(ngrams(words, 3))
feats = dict([(word, True) for word in ngram_list])
t0 = timeit.default_timer()
result = classifier.classify(feats)
t1 = timeit.default_timer()
classify_time = t1-t0
print "CLASSIFY TIME: ", classify_time
print "RESULT: ", result
import pickle
from nltk.util import ngrams
fin = open("C:/Users/ned/Desktop/gherkin.pickle","rb")
classifier = pickle.load(fin)
words = ['boring', 'and', 'stupid', 'movie']
ngram_list = words + list(ngrams(words, 2)) + list(ngrams(words, 3))
feats = dict([(word, True) for word in ngram_list])
dist = classifier.prob_classify(feats)
#for sample in dist.samples():
# print("%s probability: %f" % (sample, dist.prob(sample)))
sample = "pos"
print("%s probability: %f" % (sample, dist.prob(sample)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment