Python: Loaded NLTK Classifier not working

I am trying to train the NLTK classifier to analyze moods and then save the classifier using pickle. A freshly trained classifier works great. However, if I load a saved classifier, the classifier either displays โ€œpositiveโ€ or โ€œnegativeโ€ for ALL examples.

I save the classifier using

classifier = nltk.NaiveBayesClassifier.train(training_set)
classifier.classify(words_in_tweet)
f = open('classifier.pickle', 'wb')
pickle.dump(classifier, f)
f.close()

and loading the classifier using

f = open('classifier.pickle', 'rb')
classifier = pickle.load(f)
f.close()
classifier.classify(words_in_tweet)

I have no mistakes. Any idea what the problem might be, or how to properly debug it?

+4
source share
1 answer

, , , - . , .

NaiveBayesClassifier , ; , ( , ). , import - , ( ) script.

, OP, NLTK . , , . , pickle: , . , (), . "" script, pickle.load .

+1

All Articles