When I run this code it throws an error which I believe is due to the batch_classify method not being present in NLTK 3.0. I curious how to resolve this type of issue where something from an older version disappears in the newer version.
def accuracy(classifier, gold):
results = classifier.batch_classify([fs for (fs,l) in gold])
correct = [l==r for ((fs,l), r) in zip(gold, results)]
if correct:
return float(sum(correct))/len(correct)
else:
return 0
def apr (classifier, gold):
results = classifier.batch_classify([fs for (fs,l) in gold])
#gold_class_dict = defaultdict(list)
#classifier_class_dict = {}
sys_correct_dict = Counter()
num_guessed = Counter()
gold_num = Counter()
num_right = 0
total = 0
The method was renamed to
classify_many()
(I couldn't find documentation of NLTK 2.0 to check it, but I'm pretty sure that's what happened).You have to replace all occurrences of
batch_classify(...)
withclassify_many(...)
in your code. When moving from one major version of a library to another, you have to expect this kind of backwards-incompatible changes; they should ideally be documented in the changelog. However, I have to admit that in the past NLTK introduced backwards-incompatible changes even between minor versions, which I think is bad practice.