<jupyter_start><jupyter_text>Meet Sakhi -- Your Friend<jupyter_code>import nltk
import numpy as np
import random
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
import string
#nltk.download('wordnet') # first-time use only
lemmer = nltk.stem.WordNetLemmatizer()
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):
    return LemTokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))

GREETING_KEYWORDS = ("hello", "hi", "greetings", "sup", "what's up","hey",)

GREETING_RESPONSES = ["hi", "hey", "*nods*", "hi there", "hello", "I am glad! You are talking to me"]

def check_for_greeting(sentence):
    """If any of the words in the user's input was a greeting, return a greeting response"""
    for word in sentence.split():
        if word.lower() in GREETING_KEYWORDS:
            return random.choice(GREETING_RESPONSES)
f=open('C://Work//chatbot//Itbodhi2.txt','rU')
raw=f.read()
raw=raw.lower()
#Tokenization
sent_tokens = nltk.sent_tokenize(raw)
word_tokens = nltk.word_tokenize(raw)

# Generating response
def response(user_response):
    sakhi_response=''
    TfidfVec = TfidfVectorizer(tokenizer=LemNormalize, stop_words='english')
    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):
        sakhi_response=sakhi_response+"I am sorry! I don't know what are you asking"
        return sakhi_response
    else:
        sakhi_response=sakhi_response+sent_tokens[idx]
        return sakhi_response
flag=True
print("Sakhi: My name is Sakhi. I will answer your queries about Machine Learning Program. If you want to exit, type Bye!")

while(flag==True):
    user_response = input()
    user_response=user_response.lower()
    if(user_response!='bye'):
        if(user_response=='thanks' or user_response=='thank you' ):
            flag=False
            print("Sakhi: You are welcome..")
        else:
            if(check_for_greeting(user_response)!=None):
                print("Sakhi: "+check_for_greeting(user_response))
            else:
                sent_tokens.append(user_response)
                word_tokens=word_tokens+nltk.word_tokenize(user_response)
                final_words=list(set(word_tokens))
                print("Sakhi: ",end="")
                print(response(user_response))
                sent_tokens.remove(user_response)
    else:
        flag=False
        print("Sakhi: Bye! take care..")<jupyter_output>Sakhi: My name is Sakhi. I will answer your queries about Machine Learning Program. If you want to exit, type Bye!
hi
Sakhi: hey
what is the registration fees?
Sakhi: registration fees is  15000 inr.
where is the venue?
Sakhi: program venue is crossing republic,ghaziabad.
which algorithms will be covered?
Sakhi: the algorithms covered are linear regression, logistic regression, decision trees, random forests, naïve bayes classifier, k-nearest neighbour, neural networks, kmeans clustering, principal components analysis.
Thank You
Sakhi: You are welcome..
{'fraction_non_alphanumeric': 0.10748091603053435, 'fraction_numerical': 0.0033587786259541984, 'mean_word_length': 3.933734939759036, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '395379', 'license': 'MIT', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1051, 'n_words': 273, 'path': 'Sakhi-Version2.ipynb', 'repo_name': 'ruchir3110/Sakhi-2.0', 'size': '3275'}