Skip to content

Commit 68d267d

Browse files
author
root
committed
first commit
0 parents  commit 68d267d

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

qst.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import nltk
2+
import pandas as pd
3+
from sklearn.neighbors import KNeighborsClassifier
4+
from sklearn.feature_extraction.text import CountVectorizer
5+
from sklearn.cross_validation import train_test_split
6+
# import and instantiate a Multinomial Naive Bayes model
7+
from sklearn.naive_bayes import MultinomialNB
8+
from sklearn import metrics
9+
from sklearn.datasets import load_iris
10+
iris = load_iris()
11+
12+
13+
def qst_type(test_qst):
14+
path = 'qstns.tsv'
15+
sent = pd.read_table(path, header=None, names=['qtype', 'sentance'])
16+
sent.shape
17+
sent['label_num'] = sent.qtype.map({'whqst':0, 'statement':1,'yesOrNo':2})
18+
X = iris.data
19+
y = iris.target
20+
X = sent.sentance
21+
y = sent.label_num
22+
sent.head(5)
23+
24+
25+
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)
26+
27+
vect = CountVectorizer()
28+
vect.fit(X_train)
29+
X_train_dtm = vect.transform(X_train)
30+
X_train_dtm = vect.fit_transform(X_train)
31+
X_train_dtm
32+
X_test_dtm = vect.transform(X_test)
33+
X_test_dtm
34+
35+
36+
nb = MultinomialNB()
37+
nb.fit(X_train_dtm, y_train)
38+
y_pred_class = nb.predict(X_test_dtm)
39+
#a=y_pred_class.tostring()
40+
#print (a)
41+
#metrics.accuracy_score(y_test, y_pred_class)
42+
43+
44+
test_qst_dtm = vect.transform(test_qst)
45+
test_qst_dtm
46+
y_pred_class = nb.predict(test_qst_dtm)
47+
a = y_pred_class
48+
if a == 0:
49+
c = "wh_questions"
50+
return(c)
51+
elif a == 1:
52+
c = ["statement"]
53+
elif a == 2:
54+
c == ["yes or no question"]
55+
56+
return(a)
57+
58+
#Just edit the question here and try type of qustions
59+
test_qst = ["Tell me city which is capital of India"]
60+
q_type = qst_type(test_qst)
61+
print(q_type)

qstns.tsv

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
whqst what is your name?
2+
whqst where are you?
3+
whqst when will you come
4+
whqst who are you
5+
whqst who is this
6+
whqst how do you do
7+
whqst how are you
8+
whqst how is you
9+
whqst how can i
10+
yesOrNo do you know who
11+
yesOrNo do you know why
12+
yesOrNo do you know what
13+
yesOrNo can do this for me
14+
yesOrNo do it or not
15+
yesOrNo is this your
16+
yesOrNo is that your
17+
statement yes i am
18+
statement i know how it is
19+

0 commit comments

Comments
 (0)