Thursday, September 25, 2025

CLASS X (Artificial Intellegence) - Document Vectorization and Bag of Words (BoW)

 

Document Vectorization and Bag of Words (BoW)

 

Q.  What do you mean by corpus?

ANS - Corpus is the collection of all the documents

  

Q. What is term frequency?

ANS - Term frequency is the frequency of a word in one document.

 

Q. What is the full form of TFIDF?

ANS - Term Frequency and Inverse Document Frequency

 

Q. What is a document vector table?

ANS - Document Vector Table is used while implementing Bag of Words algorithm or Document Vector Table is a table containing the frequency of each word of the vocabulary in each document.

 

Q. Explain the concept of Bag of Words.

ANS - Bag of Words is a Natural Language Processing (NLP) model which helps in extracting features out of the text. In bag of words, we get the occurrences of each word and construct the vocabulary for the corpus.

 

Q. Consider the following documents

Document 1: Aman and Anil are stressed.
Document 2: Aman went to a therapist.
Document 3: Anil went to download a health chatbot.

Implement all the four steps of Bag of Words (BoW) model to create a document vector table.

 

ANS - STEP 1. Text Normalisation

After text normalisation, the text becomes:
Document 1: [aman, and, anil, are, stressed]
Document 2: [aman, went, to, a, therapist]
Document 3: [anil, went, to, download, a, health, chatbot]

 

STEP 2. Create Dictionary

create a dictionary means make a list of all the unique words occurring in all three documents.

Create Dictionary

 

STEP 3. Create document vectors

In this step, the vocabulary is written in the top row. Now, for each word in the document, if it matches with the vocabulary, put a 1 under it. If the same word appears again, increment the previous value by 1. And if the word does not occur in that document, put a 0 under it.

 

STEP 4. Create document vectors for all the documents

Repeat step 3 for all the documents to get vectors.

document vectors for all documents

NOTE - The Above table is also called as TF-IDF (Term Frequency & Inverse Document Frequency)

 

Q. Create a document vector table for the given corpus:

Document 1: We are going to Mumbai

Document 2: Mumbai is a famous place.

Document 3: We are going to a famous place.

Document 4: I am famous in Mumbai.

 

Ans: -

CLASS X (Aritificial Intelligence) - Confusion Matrix and the four methods to evaluate the model

 

Confusion Matrix and the four methods to evaluate the model

Confusion Matrix - The comparison between the results of Prediction and reality is called the Confusion Matrix.

How to interpret a confusion matrix for a machine learning model

There are four methods to evaluate the model











 
 

  

 

 

 

 

 

 

 

 

 

 

 

 

 


QUSTION

Consider the scenario where the AI model is created to predict if there will be rain or not. The confusion matrix for the same is given below. Calculate precision, accuracy and recall.

TP = 70   TN = 50

FN = 50  FP = 30

NOW CALCULATE ALL FOUR (ACCURACY, PRECISION, RECALL AND F1 SCORE) USING GIVEN FORMULAS



 

 

 

 

ACCURACY = (70+50) / (70 + 50 + 30 + 50) * 100

ACCURACY = 120/200 * 100

ACCURACY = 60 %

 



 

 

 

 

 


PRECISION = 70/(70 + 30) * 100

PRECISION = 70/100 * 100

PRECISION = 70%

 

 

RECALL = 70/(70 + 50)

RECALL = 70/120

RECALL = 0.583

 

 

 F1 SCORE = 2 * (70 * 0.583)/( 70 + 0.583)

F1 SCORE = 2 * (40.81)/ 70.583

F1 SCORE = 2 * 0.578

F1 SCORE = 1.156

 

How many total tests were performed in the above scenario?

TP + TN + FN + FP

70 + 50 + 50 + 30 = 200

 

 

 

 

HOMEWORK

 

 

 

 

CLASS X - TEXT NORMALIZATION (ARTIFICIAL INTELLIGENCE)

Text Normalization

 CLASS X - ARTIFICIAL INTELLIGENCE

 

 CBSE CLASS X – Artificial Intelligence

 

Q. Normalise the text on the segmented sentences given below:

Document 1: Diya and Riya are best friends.

Document 2: Diya likes to play guitar but Riya prefers to play violin

 

Q. Sushmitha, a student of class X, was exploring the Natural Language Processing domain. She got stuck while performing the text normalization. Help her to normalize the text on the segmented sentences given below:

Document 1: Akash and Ajay are best friends.

Document 2: Akash likes to play football but Ajay prefers to play online games.

 

Corpus

In Text Normalization, A corpus is a large and structured set of machine-readable texts that have been produced in a natural communicative setting.  A corpus can be defined as a collection of entire text of all documents in a dataset.

 

Text Normalization

It is a process to reduce the variations in text’s word forms to a common form when the variation means the same thing.

The different in text normalization is

1. Sentence Segmentation

2. Tokenisation

3. Removing Stop words, Special characters and Numbers

4. Converting text to a common case

5. Stemming  and Lemmatization

 

 

Q. Normalize the given text and comment on the vocabulary before and after the normalization:

Raj and Vijay are best friends. They play together with other friends. Raj likes to play football but Vijay prefers to play online games. Raj wants to be a footballer. Vijay wants to become an online gamer.

ANS -

1.    Sentence Segmentation:

Under sentence segmentation, the whole text is divided into individual sentences.

1. Raj and Vijay are best friends.

2. They play together with other friends.

3. Raj likes to play football but Vijay prefers to play online games.

4. Raj wants to be a footballer.

5. Vijay wants to become an online gamer.

 

2. Tokenisation

Under tokenisation, every word, number and special character is considered separately and each of them is now a separate token.

3. Removing Stop words, Special characters and Numbers

Stopwords are the words which occur very frequently in the corpus but do not add much meaning  to it.

eg. - a, an, and, are, as, for, it, is, into, in, if, on, or, such, the, this, there, to etc.

Hence, to make it easier for the computer to focus on meaningful terms, these words are removed.

 

3. Removing Stop words, Special characters and Numbers

1. Raj and Vijay are best friends.

    Raj, Vijay, best, friends

2. They play together with other friends.

    Play, together, other, friends

3. Raj likes to play football but Vijay prefers to play online games.

    Raj, likes, play, football, Vijay, prefers, play, online, games

4. Raj wants to be a footballer.

    Raj, wants, footballer

5. Vijay wants to become an online gamer.

    Vijay, wants, become, online, gamer

 

4. Converting text to a common case

After the stop words removal, we convert the whole text into a similar case, preferably lower case.

1. raj, vijay, best, friends.

2. play, together, other, friends.

3. raj, likes, play, football, vijay, prefers, play, online, games.

4. raj, wants, footballer.

5. vijay, wants, become, online, gamer.

 

5. Stemming and Lemmatization

stemming is the process in which the affixes of words are removed, and the words are converted to their base form.

 

5. Stemming and Lemmatization

stemming is the process in which the affixes of words are removed, and the words are converted to their base form.

1. raj, vijay, best, friend

2. play, together, other, friend

3. raj, like, play, football, vijay, prefer, play, online, game

4. raj, want, footballer

5. vijay, want, become, online, gamer

 

 

 

 

 

 

 


 

CBSE SAMPLE PAPER COMPUTER SCIENCE - 2026 WITH ANSWER KEY

CBSE SAMPLE PAPER 

COMPUTER SCIENCE - 2026 WITH ANSWER KEY

 

CLICK HERE FOR SAMPLE PAPER 

 

CLICK HERE FOR ANSWER KEY