You are on page 1of 3

BAG OF WORDS ALGORITHM 

PARAGRAPH
We can use health chatbots for treating stress. 
We can use NLP to create chatbots and we will be making health
chatbots now!  Health Chatbots cannot replace human counsellors
now. 
 
Step I - Text Normalization 

Sentence segmentation 
sentence 1: we can use health chatbots for treating stress  
sentence 2: We can use NLP to create chatbots and we will be
making health chatbots now!  
sentence 3: Health Chatbots cannot replace human counsellors now. 

Tokenization 
Sentence 1: We  can  use  health  chatbots  for  treating  stress  . 
Sentence 2: We  can  use  NLP  to  create  chatbots  and  we  will  be 
making  health  chatbots  now  ! 
Sentence 3: Health  Chatbots  cannot  replace  human  counsellors 
now   

REMOVING STOP WORDS


Document 1: We health chatbots treating stress.  
Document 2: We NLP create chatbots making health chatbots !  
Document 3: Health Chatbots replace human counsellors . 

Lower case conversion 


document 1: we health chatbots treating stress.  
document 2: we nlp create chatbots making health chatbots!  
document 3: health chatbots replace human counsellors. 
Stemming 

document 1: we health chatbot treat stress.  


document 2: we nlp create chatbot make health chatbot !  
document 3: health chatbot replac human counsellor. 

Lemmatisation 

document 1: we health chatbot treat stress .  


document 2: we nlp create chatbot make health chatbot !  
document 3: health chatbot replace human counsellor 

Step 2 - Create dictionary

we   health  chatbot  treat  stress  nlp  create  make  replace counsellor  human 

 Step 3 - Make Document Vector 

  we   health  chatbot  treat  stress  nlp  create  make  replace counsellor  human 
Sent 1  1  1  1  1  0  0  0  0  0  0 

Step 4 - Document Vector for whole document

we  health  chatbot  treat  stress  nlp  create make  replace counsellor  human 

1  1  1  1  1  0  0  0  0  0  0 
1  1  1  0  0  1  1  1  0  0  0 
0  1  1  0  0  0  0  0  1  1  1 
 
TFIDF 

Document Frequency 

we  health  chatbot  treat  stress  nlp  create make  counsellor  human  replace 
2  3  3  1  1  1  1  1  1  1  1 
 
Inverse Document Frequency
 
we health chatbot treat stress nlp create make counsellor human Replace 
3/2 3/3  3/3  3/1  3/1  3/1 3/1  3/1  3/1  3/1  3/1 
 
                
TFIDF(w)= TF(W)*log(IDF(W)) 

  we   health  chatbot  treat  stress  nlp  create  make  replace  counsellor human 
DOC 1 1*log3/2 1*log3/3 1*log3/3 1*log3/1 1*log3/1 0*log3/1 0*log3/1 0*log3/1 0*log3/1 0*log3/1  0*log3/1 

DOC 2 1*log3/2 1*log3/3 1*log3/3 0*log3/1 0*log3/1 1*log3/1 1*log3/1 1*log3/1 0*log3/1 0*log3/1  0*log3/1 

DOC 3 0*log3/2 1*log3/3 1*log3/3 0*log3/1 0*log3/1 0*log3/1 0*log3/1 0*log3/1 1*log3/1 1*log3/1  1*log3/1 
 
IDF values 

  we   health  chatbot  treat  stress  nlp  create  make  replace  counsellor  human 
doc 1  0.176  0  0  0.477  0.477  0  0  0  0  0  0 
doc 2  0.176  0  0  0  0  0.477  0.477  0.477  0  0  0 
doc 3  0  0  0  0  0  0  0  0  0.477  0.477  0.477 

Conclusion

Sentence 1: Priority is given to treat and stress 


                    
Sentence 2: Priority is given to nlp, create and make 
                    
Sentence 3: Priority is given to replace, counsellor and human 
                   
 

You might also like