Попробуйте preprocessor
вместо tokenizer
.
return lambda x: strip_accents(x.lower())
AttributeError: 'list' object has no attribute 'lower'
Если x
в приведенном выше сообщении об ошибке является списком, то выполнение x.lower()
для списка вызовет ошибку.
Все ваши два примера - это игнорируемые слова, поэтому, чтобы этот пример что-то возвращал, добавьте несколько случайных слов. Вот пример:
tokenized_sentences = [['this', 'is', 'one', 'cat', 'or', 'dog'],
['this', 'is', 'another', 'dog']]
tfidf = TfidfVectorizer(preprocessor=' '.join, stop_words='english')
tfidf.fit_transform(tokenized_sentences)
Возврат:
<2x2 sparse matrix of type '<class 'numpy.float64'>'
with 3 stored elements in Compressed Sparse Row format>
Функции:
>>> tfidf.get_feature_names()
['cat', 'dog']
ОБНОВЛЕНИЕ: может быть, использовать lambda
s на токенизаторе и препроцессоре?
tokenized_sentences = [['this', 'is', 'one', 'cat', 'or', 'dog'],
['this', 'is', 'another', 'dog']]
tfidf = TfidfVectorizer(tokenizer=lambda x: x,
preprocessor=lambda x: x, stop_words='english')
tfidf.fit_transform(tokenized_sentences)
<2x2 sparse matrix of type '<class 'numpy.float64'>'
with 3 stored elements in Compressed Sparse Row format>
>>> tfidf.get_feature_names()
['cat', 'dog']
person
Jarad
schedule
07.02.2018