Created
January 7, 2018 07:50
-
-
Save avivl/70a83e35793d3800e6c1d25fc55f97e0 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
def get_tf_record(sentence): | |
global words | |
# tokenize the pattern | |
sentence_words = nltk.word_tokenize(sentence) | |
# stem each word | |
sentence_words = [stemmer.stem(word.lower()) for word in sentence_words] | |
# bag of words | |
bow = [0]*len(words) | |
for s in sentence_words: | |
for i, w in enumerate(words): | |
if w == s: | |
bow[i] = 1 | |
return(np.array(bow)) | |
with open("./test_data.json", "r") as ins: | |
array = [] | |
for line in ins: | |
array.append(line) | |
for line in array: | |
jdata = json.loads(line) | |
predict_score = categories[np.argmax(model.predict([get_tf_record(jdata['review'])]))] | |
real_score = int(jdata['score']) | |
print (real_score, predict_score) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment