Skip to content

Instantly share code, notes, and snippets.

@avivl
Created January 7, 2018 07:50
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 avivl/70a83e35793d3800e6c1d25fc55f97e0 to your computer and use it in GitHub Desktop.
Save avivl/70a83e35793d3800e6c1d25fc55f97e0 to your computer and use it in GitHub Desktop.
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