Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

ASSIGNMENT – 01

TO CALCULATE THE TF-IDF OF THE GIVEN EXAMPLES-

EXAMPLE 1
Sentences in the following examples are given below: -
• D1 - Tom waited for the train
• D2 - The train was late
• D3 - Jerry took the bus
• D4 - The train leaves in ten minutes
• D5 - Tom and Jerry enjoy traveling
• Query: Who waited for the train?
After removing the stop words from the above documents, the modified
documents are as follows:
• D1 – Tom waited train
• D2 – train late
• D3 – Jerry took bus
• D4 – train leaves ten minutes
• D5 - Tom Jerry enjoy traveling
• Query: waited train
TF – IDF TABLE:
Words TF IDF TF * IDF
D1 D2 D3 D4 D5 D1 D2 D3 D4 D5
Tom 0.33 0 0 0 0.25 0.398 0.13134 0 0 0 0.0995
Waited 0.33 0 0 0 0 0.699 0.23067 0 0 0 0
Train 0.33 0.5 0 0.25 0 0.222 0.07326 0.111 0 0.0555 0
Late 0 0.5 0 0 0 0.699 0 0.3495 0 0 0
Jerry 0 0 0.33 0 0.25 0.398 0 0 0.13134 0 0.0995
Took 0 0 0.33 0 0 0.699 0 0 0.23067 0 0
Bus 0 0 0.33 0 0 0.699 0 0 0.23067 0 0
Leaves 0 0 0 0.25 0 0.699 0 0 0 0.17475 0
Ten 0 0 0 0.25 0 0.699 0 0 0 0.17475 0
Minutes 0 0 0 0.25 0 0.699 0 0 0 0.17475 0
Enjoy 0 0 0 0 0.25 0.699 0 0 0 0 0.17475
traveling 0 0 0 0 0.25 0.699 0 0 0 0 0.17475
Q * (TF * IDF)
Words Q D1 D2 D3 D4 D5
Tom 0 0 0 0 0 0
Waited 1 0.23067 0 0 0 0
Train 1 0.07326 0.111 0 0.0555 0
Late 0 0 0 0 0 0
Jerry 0 0 0 0 0 0
Took 0 0 0 0 0 0
Bus 0 0 0 0 0 0
Leaves 0 0 0 0 0 0
Ten 0 0 0 0 0 0
Minutes 0 0 0 0 0 0
Enjoy 0 0 0 0 0 0
traveling 0 0 0 0 0 0
TOTAL 0.30393 0.111 0 0.0555 0

Document 1 has a higher rank so it is relevant.


EXAMPLE 2
Sentences in the following examples are given below: -
• D1 – Robert was a good king
• D2 – Water freezes at zero degree
• D3 – I love my new pets
• D4 – James never works on weekends
• D5 – Krishna enjoys cooking
• Query: Who enjoys cooking?
After removing the stop words from the above documents, the modified
documents are as follows:
• D1 – Robert good king
• D2 – Water freezes zero degree
• D3 – love new pets
• D4 – James never works weekends
• D5 – Krishna enjoys cooking
• Query: enjoys cooking
• TF – IDF TABLE:
Words TF IDF TF * IDF
D1 D2 D3 D4 D5 D1 D2 D3 D4 D5
Robert 0.33 0 0 0 0 0.699 0.23067 0 0 0 0
Good 0.33 0 0 0 0 0.699 0.23067 0 0 0 0
King 0.33 0 0 0 0 0.699 0.23067 0 0 0 0
Water 0 0.25 0 0 0 0.699 0 0.17475 0 0 0
Freezes 0 0.25 0 0 0 0.699 0 0.17475 0 0 0
Zero 0 0.25 0 0 0 0.699 0 0.17475 0 0 0
Degree 0 0.25 0 0 0 0.699 0 0.17475 0 0 0
Love 0 0 0.33 0 0 0.699 0 0 0.23067 0 0
New 0 0 0.33 0 0 0.699 0 0 0.23067 0 0
Pets 0 0 0.33 0 0 0.699 0 0 0.23067 0 0
James 0 0 0 0.25 0 0.699 0 0 0 0.17475 0
Never 0 0 0 0.25 0 0.699 0 0 0 0.17475 0
Works 0 0 0 0.25 0 0.699 0 0 0 0.17475 0
Weekend 0 0 0 0.25 0 0.699 0 0 0 0.17475 0
Krishna 0 0 0 0 0.33 0.699 0 0 0 0 0.23067
Enjoys 0 0 0 0 0.33 0.699 0 0 0 0 0.23067
Cooking 0 0 0 0 0.33 0.699 0 0 0 0 0.23067
Words Q Q * (TF * IDF)
D1 D2 D3 D4 D5
Robert 0 0 0 0 0 0
Good 0 0 0 0 0 0
King 0 0 0 0 0 0
Water 0 0 0 0 0 0
Freezes 0 0 0 0 0 0
Zero 0 0 0 0 0 0
Degree 0 0 0 0 0 0
Love 0 0 0 0 0 0
New 0 0 0 0 0 0
Pets 0 0 0 0 0 0
James 0 0 0 0 0 0
Never 0 0 0 0 0 0
Works 0 0 0 0 0 0
Weekend 0 0 0 0 0 0
Krishna 0 0 0 0 0 0
Enjoys 1 0 0 0 0 0.23067
Cooking 1 0 0 0 0 0.23067
TOTAL 0 0 0 0 0.46134

Document 5 has a higher rank so it is relevant.

You might also like