Assignment - 7: Import Import Import Import
Assignment - 7: Import Import Import Import
tokens = word_tokenize(document)
print("Tokenized Words:", tokens)
stop_words = set(stopwords.words('english'))
filtered_tokens = [word for word in tokens if word.lower() not in stop_words
print("After Stop Words Removal:", filtered_tokens)
stemmer = PorterStemmer()
lemmatizer = WordNetLemmatizer()
# Using the same doc twice just to simulate multiple documents for IDF
documents = [
"Natural Language Processing is a fascinating field of AI. NLP helps mac
"Natural Language Processing is a fascinating field of AI. NLP helps mac
]
tfidf_vectorizer = TfidfVectorizer()
tfidf_matrix = tfidf_vectorizer.fit_transform(documents)
import pandas as pd
df = pd.DataFrame(denselist, columns=feature_names)
print(df)
# Plotting
plt.bar(sorted_terms, sorted_scores, color='skyblue')
plt.xlabel('Terms')
plt.ylabel('TF-IDF Score')
plt.title('Top 5 TF-IDF Scores')
plt.show()
In [ ]: