Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started