Skip to content

Instantly share code, notes, and snippets.

Last active December 3, 2020 13:32
What would you like to do?
TF-IDF computation in Sklearn
from sklearn.feature_extraction.text import TfidfVectorizer
corpus = [
'This is the first document.',
'This document is the second document.',
'And this is the third one.',
'Is this the first document?',
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(corpus)
# returns ['and', 'document', 'first', 'is', 'one', 'second', 'the', 'third', 'this']
# returns (4, 9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment