Вы можно более четко понять, что я имею в виду, говоря о том, как должен выглядеть результат ниже.
Вот код, который у меня есть:
Код: Выделить всё
def featureExtraction(clean_tokenized, label):
features = []
for line in clean_tokenized:
for word in line:
d = dict({word: True})
d1 = (d, label)
tup.append(d1)
return features
Код: Выделить всё
[['hate', 'movie'],
['acting', 'terrible']]
Код: Выделить всё
[
({'hate': True, 'movie': True}, 'neg')
({'acting': True, 'terrible': True}, 'neg')
]
Код: Выделить всё
[({'hate': True}, 'pos'), ({'movie': True}, 'pos'), ({'acting': True}, 'pos'), ({'terrible': True}, 'pos')]
Подробнее здесь: https://stackoverflow.com/questions/786 ... on-diction