VasudevaK commited on
Commit
c8c91d2
·
1 Parent(s): 53d4aaa

tuned better

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -9,9 +9,9 @@ import nltk
9
  nltk.download('all')
10
  import string
11
  from sklearn.feature_extraction.text import TfidfVectorizer
 
12
  # import fastai
13
 
14
-
15
  def similarity(input, joke):
16
  return cosine_similarity(input, joke)
17
 
@@ -74,21 +74,22 @@ def LemNormalize(text):
74
  return LemTokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))
75
 
76
  def NLTK(input):
77
- f = open('corpus.txt', errors='strict')
78
  data = f.read()
79
  data = data.lower()
 
80
  sent_tokens = nltk.sent_tokenize(data)
81
- return bot(sent_tokens)
82
 
83
- def bot(sent_tokens):
84
  robo1_response = ''
85
  TfidfVec = TfidfVectorizer(tokenizer = LemNormalize, stop_words='english')
86
  tfidf = TfidfVec.fit_transform(sent_tokens)
87
  vals = cosine_similarity(tfidf[-1], tfidf)
88
- idx = vals.argsort()[0][-2]
89
  flat = vals.flatten()
90
  flat.sort()
91
- req_tfidf = flat[-2]
92
  if (req_tfidf == 0):
93
  robo1_response= robo1_response+"I could not answer this right now but you can contact the head of our dept (PUSPHA RAJ)." # add the dept recommendation engine and contact details
94
  return robo1_response
 
9
  nltk.download('all')
10
  import string
11
  from sklearn.feature_extraction.text import TfidfVectorizer
12
+ import random
13
  # import fastai
14
 
 
15
  def similarity(input, joke):
16
  return cosine_similarity(input, joke)
17
 
 
74
  return LemTokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))
75
 
76
  def NLTK(input):
77
+ f = open('/content/corpus.txt', errors='strict')
78
  data = f.read()
79
  data = data.lower()
80
+ data = data + input.lower()
81
  sent_tokens = nltk.sent_tokenize(data)
82
+ return bot(sent_tokens, input)
83
 
84
+ def bot(sent_tokens, input):
85
  robo1_response = ''
86
  TfidfVec = TfidfVectorizer(tokenizer = LemNormalize, stop_words='english')
87
  tfidf = TfidfVec.fit_transform(sent_tokens)
88
  vals = cosine_similarity(tfidf[-1], tfidf)
89
+ idx = random.randint(0, len(vals.argsort()[0]))
90
  flat = vals.flatten()
91
  flat.sort()
92
+ req_tfidf = flat[-5]
93
  if (req_tfidf == 0):
94
  robo1_response= robo1_response+"I could not answer this right now but you can contact the head of our dept (PUSPHA RAJ)." # add the dept recommendation engine and contact details
95
  return robo1_response