Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What type of chatbot is this? Please explain the responses, methods and the preprocessing used. #preprocessing from nltk.corpus import stopwords from nltk import word_tokenize lemmer

What type of chatbot is this? Please explain the responses, methods and the preprocessing used.

#preprocessing from nltk.corpus import stopwords from nltk import word_tokenize

lemmer = nltk.stem.WordNetLemmatizer() #WordNet is a semantically-oriented dictionary of English included in NLTK. def LemTokens(tokens): return [lemmer.lemmatize(token) for token in tokens] remove_punct_dict = dict((ord(punct), None) for punct in string.punctuation) def LemNormalize(text): stop = set(stopwords.words('english') + list(string.punctuation)) text2= ' '.join([i for i in word_tokenize(text.lower()) if i not in stop]) return LemTokens(nltk.word_tokenize(text2.lower().translate(remove_punct_dict)))

def response(user_response): robo_response='' TfidfVec = TfidfVectorizer(tokenizer=LemNormalize) tfidf = TfidfVec.fit_transform(sent_tokens) vals = cosine_similarity(tfidf[-1], tfidf) idx=vals.argsort()[0][-2] flat = vals.flatten() flat.sort() req_tfidf = flat[-2] if(req_tfidf==0): robo_response=robo_response+"I don't understand you" return robo_response else: robo_response = robo_response+sent_tokens[idx] return robo_response

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago