<jupyter_start><jupyter_text>Cleaning the texts Regular Expression<jupyter_code>import re<jupyter_output><empty_output><jupyter_text>Stopwords<jupyter_code>from nltk.corpus import stopwords<jupyter_output><empty_output><jupyter_text>Stemming<jupyter_code>from nltk.stem.porter import PorterStemmer<jupyter_output><empty_output><jupyter_text>Lemmatization<jupyter_code>from nltk.stem import WordNetLemmatizer
ps = PorterStemmer()
wordnet=WordNetLemmatizer()
sentences = nltk.sent_tokenize(paragraph)
sentences
len(sentences)
corpus = []
for i in range(len(sentences)):
    review = re.sub('[^a-zA-Z]', ' ', sentences[i])
    review = review.lower()
    review = review.split()
    #review = [ps.stem(word) for word in review if not word in set(stopwords.words('english'))]
    review = [wordnet.lemmatize(word) for word in review if not word in set(stopwords.words('english'))]
    review = ' '.join(review)
    corpus.append(review)
corpus
len(corpus)<jupyter_output><empty_output><jupyter_text>Creating the Bag of Words model<jupyter_code>from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer()
X = cv.fit_transform(corpus).toarray()
X
X.shape<jupyter_output><empty_output><jupyter_text>Creating the TF-IDF model<jupyter_code>from sklearn.feature_extraction.text import TfidfVectorizer
cv = TfidfVectorizer()
Y = cv.fit_transform(corpus).toarray()
Y
Y.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11590106007067137, 'fraction_numerical': 0.0, 'mean_word_length': 7.90566037735849, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '282921', 'license': 'MIT', 'n_tokens_mistral': 526, 'n_tokens_neox': 511, 'n_words': 87, 'path': 'Bag of words & TF-IDF.ipynb', 'repo_name': 'vamshiBunne007/BAGOFWORDS-NLP-TF-IDE', 'size': '1415'}