def predict_score(test_sequence): max_sequence_length = 200 model = load_model('./my_model.h5') with open('./word_integer_map.json') as f: word_to_id = json.load(f) temp = [] test_sequence = test_sequence.lower() save = [] temp = [] ids = [] for word in test_sequence.split(" "): try: if (check(word) != -1): continue i = [] i.append(word_to_id[word]) ids.append(i) save.append(word) #print(word) except: x = 1 pads = [] for i in ids: pads.append(sequence.pad_sequences([i], maxlen=max_sequence_length)) scores = [] for p in pads: scores.append(model.predict(np.array([p][0]))[0][0]) s_dict = {} i = -1 for s in scores: i+=1 print(i) if (check(save[i]) != -1): continue s_dict[s] = save[i] ans = sorted(s_dict.items(),reverse=True) return ans
def stop_response(self, word): global user_score if not (dict.check(word)) or len(word) < 4: print("Nope. Real words with length >= 4 only.") user_score -= 1 return self.vocab_tree.add(word) self.score -= 1
def stop_response(self, word): global user_score, words_played if not(dict.check(word)) or len(word) < 4 or word in words_played: print("Nope. Real words with length >= 4 only.") user_score -= 1 return False self.vocab_tree.add(word) self.score -= 1 return True
def get_show(self, word): global done, user_score print("Show") word_ = input("~> ") if not word in word_ or len(word_) < 4 : print(f"What? We're talking about something that starts with {word.upper()}, of length greater or equal to 4.") self.get_show(word) return elif dict.check(word_): print("You're right; didn't think of that one :) ") self.score -= 1 self.vocab_tree.add(word_) else: print("I knew you were bluffing ;) ") user_score -= 1 done = True
def isWord(word): for ch in word: if not ('a' <= ch.lower() <= 'z'): return False return dict.check(word)
def isWord(word): for ch in word: if not ("a" <= ch.lower() <= "z"): return False return dict.check(word)
pads = [] for i in ids: pads.append(sequence.pad_sequences([i], maxlen=max_sequence_length)) scores = [] for p in pads: scores.append(model.predict(np.array([p][0]))[0][0]) temp_padded = sequence.pad_sequences([temp], maxlen=max_sequence_length) pred_score = model.predict(np.array([temp_padded][0]))[0][0] #print([temp][0][1]) temp_padded = sequence.pad_sequences([temp], maxlen=max_sequence_length) pred_score = model.predict(np.array([temp_padded][0]))[0][0] print("the score for the comment is %s" % (pred_score * 100)) s_dict = {} i = -1 for s in scores: i += 1 if (check(save[i]) != -1): continue s_dict[s] = save[i] ans = sorted(s_dict.items(), reverse=True) print(ans) #print(scores) # gives score percentage