Created
January 11, 2017 11:55
-
-
Save alfredfrancis/e5e482d3a352a9e6dbf9f6200583f77e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.feature_extraction.text import TfidfVectorizer | |
from sklearn.naive_bayes import MultinomialNB | |
from sklearn.pipeline import Pipeline | |
from NLTKPreprocessor import NLTKPreprocessor | |
import os | |
import json | |
PATH = "new.model" | |
model = Pipeline([ | |
('vectorizer', TfidfVectorizer(min_df=1,ngram_range=(1,3))), | |
('clf',MultinomialNB(alpha=.5)) | |
]) | |
with open("questions.json","r") as file: | |
content = file.read() | |
questions = json.loads(content) | |
x = [] | |
y = [] | |
for question in questions: | |
x.append(question["text"]) | |
y.append(question["intentName"]) | |
model.fit(x, y) | |
while True: | |
print ("Enter the question:") | |
print model.predict([raw_input()]) | |
#Train classifier | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment