What is the bag-of-words algorithm?

Bag Of Words

The bag-of-words model is a simplifying representation used in natural language processing and information retrieval (IR). In this model, a text (such as a sentence or a document) is represented as the bag (multiset) of its words, disregarding grammar and even word order but keeping multiplicity.
Ref: https://medium.com/analytics-vidhya/fundamentals-of-bag-of-words-and-tf-idf-9846d301ff22#:~:text=The%20bag-of-words%20model,word%20order%20but%20keeping%20multiplicity.

Bag of Words (BoW) model is a simple algorithm used in Natural Language Processing.

In BoW model a sentence or a document is considered as a ‘Bag’ containing words. It will take into account the words and their frequency of occurrence in the sentence or the document disregarding semantic relationship in the sentences.

e.g:

Screenshot 2021-08-12 at 5.19.42 PM

As you can see in the above table, if Bag of Words model is applied to ‘Document X’, the word occurrence frequency will be calculated for all the words in the document.