Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.