forked from gouravdhar/Chat-Bot-Myra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.py
124 lines (85 loc) · 2.34 KB
/
train.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# coding: utf-8
# In[1]:
import csv
from res_map import responses
res = responses()
data_path = "C:\Users\GAURABH\Desktop\Chat Bot\data5.csv"
data = []
target=[]
i = 0
with open(data_path) as datafile:
filereader = csv.reader(datafile,delimiter =',',quotechar='|')
initial = 0
for row in filereader:
if initial == 0:
initial = 1
continue
else:
data.append(row[0])
target.append(row[1])
data = data[1:]
target = target[1:]
# In[2]:
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.externals import joblib
#import joblib
count_vect = CountVectorizer()
train_counts = count_vect.fit_transform(data)
clf_count = MultinomialNB(alpha=1,fit_prior='false').fit(train_counts,target)
'''
count_path = "trained_model/naive_count/count_vect.pkl"
clf_path = "trained_model/naive_count/clf_count.pkl"
joblib.dump(count_vect,count_path)
joblib.dump(clf_count,clf_path)
'''
joblib.dump(count_vect,'count_vect.pkl')
joblib.dump(clf_count,'clf_count.pkl')
# In[3]:
#test_example = ["will kissing cause hiv"]
#test_example_count = count_vect.transform(test_example)
'''
def respond(self):
print 'input your query'
ask = raw_input()
vec = self.vector(ask)
no = self.clf.predict(vec)[0]
no = int(no)
return self.res[no]
print 'input your query'
ask = raw_input()
test_example = [ask]
test_example_count = count_vect.transform(test_example)
probs = clf_count.predict_proba(test_example_count)[0]
out = clf_count.predict(test_example_count)[0]
outn = int(out)
print res[outn]
# In[4]:
print out
# In[1]:
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
import joblib
count_vect = joblib.load("trained_model/naive_count/count_vect.pkl")
clf_count = joblib.load("trained_model/naive_count/clf_count.pkl")
'''
'''
count_vect = joblib.load("count_vect.pkl")
clf_count = joblib.load("clf_count.pkl")
'''
# In[6]:
'''
test_example = ["will kissing cause hiv"]
test_example_count = count_vect.transform(test_example)
probs = clf_count.predict_proba(test_example_count)[0]
out = clf_count.predict(test_example_count)
# In[9]:
out = out[0]
'''
# In[11]:
'''
from map_englishu import mapping
# In[12]:
mapping[out]
'''
# In[ ]: