I am trying to create a classifier using NLTK, however, I believe that I have a problem in the format of my data that I cannot get over.
My data looks like this:
data = [("TEXT 1", 'no'), ("TEXT 2", 'yes'), ("TEXT 3", 'no'), ("TEXT 4", 'no'), ("TEXT 5", 'yes')]
Then, I run the following code:
import nltk
from nltk.classify import maxent
classifier = maxent.MaxentClassifier.train(data, bernoulli=False, max_iter=10)
But, unfortunately I have the following error. What does this error consist of and how do I overcome it?
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-93-e1b29adbeebb> in <module>
----> 1 classifier = maxent.MaxentClassifier.train(data, bernoulli=False, max_iter=10)
/usr/local/lib/python3.8/dist-packages/nltk/classify/maxent.py in train(cls, train_toks, algorithm, trace, encoding, labels, gaussian_prior_sigma, **cutoffs)
324 algorithm = algorithm.lower()
325 if algorithm == "iis":
--> 326 return train_maxent_classifier_with_iis(
327 train_toks, trace, encoding, labels, **cutoffs
328 )
/usr/local/lib/python3.8/dist-packages/nltk/classify/maxent.py in train_maxent_classifier_with_iis(train_toks, trace, encoding, labels, **cutoffs)
1175 # Construct an encoding from the training data.
1176 if encoding is None:
-> 1177 encoding = BinaryMaxentFeatureEncoding.train(train_toks, labels=labels)
1178
1179 # Count how many times each feature occurs in the training data.
/usr/local/lib/python3.8/dist-packages/nltk/classify/maxent.py in train(cls, train_toks, count_cutoff, labels, **options)
665
666 # Record each of the features.
--> 667 for (fname, fval) in tok.items():
668
669 # If a count cutoff is given, then only add a joint
AttributeError: 'str' object has no attribute 'items'