Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get individual sentences from TF-IDF

so I used tf-idf on a bunch of sentence, but now I would like to get the TF-IDF vector for an individual sentence back. This is my code. How do I now get the first item in the text matrix?

tfidf = TfidfVectorizer(
min_df = 5,
max_df = 0.95,
max_features = 8000
)

tfidf.fit(df_m_a['text_final'])
text = tfidf.transform(df_m_a['text_final'])

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You have already called fit with tfidf.fit(df_m_a['text_final']). Hence the variable tfidf contains the TF-IDF vectorizer, with the last part of code text = tfidf.transform(df_m_a['text_final']) you will get the transformed vector, you should get what you want with text[0]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading