<jupyter_start><jupyter_text>Bag Of Words by `Mr. <NAME>!`* It is a technique to transform the words into differnet numbers, then make the sentences into the matrix form having the word count for each word in it.<jupyter_code># Importing the required Libraries

import goose3     # For fetching the text from the URL
from sklearn.feature_extraction.text import CountVectorizer
import nltk
goose = goose3.Goose()

# Extracting data from the wikopedia article on NLP!
data = goose.extract("https://en.wikipedia.org/wiki/Natural_language_processing")
# Getting the text data by extracting it from the data Variable!
data = data.cleaned_text
data[:15]<jupyter_output><empty_output><jupyter_text>Generating sentences from the data<jupyter_code>sentences = [sentence for sentence in nltk.sent_tokenize(data)]<jupyter_output><empty_output><jupyter_text>Creating a Bag Of Words Model!<jupyter_code>Word_Vectorizer = CountVectorizer()
Vectorized_Data = Word_Vectorizer.fit_transform(sentences)
Vectorized_Data.toarray()
# Printing out first sentence transformed into vectors!
Vectorized_Data.toarray()[0]
print(Word_Vectorizer.get_feature_names())
print("Total Unique Features:", len(Word_Vectorizer.get_feature_names()))<jupyter_output>Total Unique Features: 861
{'fraction_non_alphanumeric': 0.08293460925039872, 'fraction_numerical': 0.006379585326953748, 'mean_word_length': 7.47972972972973, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '437349', 'license': 'MIT', 'n_tokens_mistral': 395, 'n_tokens_neox': 377, 'n_words': 113, 'path': 'Bag_Of_Words/Bag Of Words.ipynb', 'repo_name': 'najoop123/Natural-Language-Processing', 'size': '1261'}