Я получаю веса TD-IDF только для первого документа в списке. Остальные нули!
tfidf_vectorizer = TfidfVectorizer()
X = tfidf_vectorizer.fit_transform(docs)
print(tfidf_vectorizer.idf_)
pd.DataFrame(X[0].T.todense(), index=tfidf_vectorizer.get_feature_names(), columns=["tfidf"]).sort_values(by=["tfidf"],ascending=False).head(10)
Для списка:
docs=[
"the world dog",
"the cat hello",
"the foo hello",
]
Выход
[1.69314718 1.69314718 1.69314718 1.28768207 1. 1.69314718]
tfidf
dog 0.652491
world 0.652491
the 0.385372
cat 0.000000
foo 0.000000
hello 0.000000
После замены первых двух строк
docs=[
"the cat hello",
"the world dog",
"the foo hello",
]
Вывод:
[1.69314718 1.69314718 1.69314718 1.28768207 1. 1.69314718]
tfidf
cat 0.720333
hello 0.547832
the 0.425441
dog 0.000000
foo 0.000000
world 0.000000
Может кто-нибудь предложить понимание этой проблемы?