Skip to content

Instantly share code, notes, and snippets.

@alfredfrancis
Created January 11, 2017 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredfrancis/e5e482d3a352a9e6dbf9f6200583f77e to your computer and use it in GitHub Desktop.
Save alfredfrancis/e5e482d3a352a9e6dbf9f6200583f77e to your computer and use it in GitHub Desktop.
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