def predict(txt): inp = dm.data_to_input(txt) prediction = model.predict(inp) predict = prediction[0][0] predict_stars = dm.to_stars(predict) return predict_stars
def predict_data(data): z = [] for d in data: z.append(dm.data_to_input(d)[0]) z = np.array(z) prediction = zip(z, model.predict(data)) return prediction
def generate(forever = False): inp = '' print('Model: ' + model_name) while forever or not any(inp == w for w in stop_words): inp = input('Sample review:\n') z = dm.data_to_input(inp) prediction = model.predict(z) predict = prediction[0][0] predict_stars = dm.to_stars(predict) print(dm.truncate_text('', char_to_display) + ' ----- predicted ' + predict_stars)
def generate_set(X_data, _rev_data): print("---------------------------------------- Data Set ----------------------------------------") print('Model: ' + model_name) z = [] for data in X_data: z.append(dm.data_to_input(data)[0]) X_data = np.array(z) prediction = model.predict(X_data) for i in range(len(_rev_data)): predict = prediction[i][0] predict_stars = dm.to_stars(predict) text = str(i + 1) + ') ' + _rev_data[i] print(dm.truncate_text(text, char_to_display) + ' ----- predicted ' + predict_stars)
total += 1 print('Loss:', loss, 'Accuracy:', str(right / total * 100) + '% |', str(right) + '/' + str(total)) print("---------------------------------------- SAMPLE REVIEWS ----------------------------------------") tests = dm.lines_to_input(file_unlabel) prediction = model.predict(tests) for i in range(len(unlabeled)): predict = prediction[i][0] predict_stars = dm.to_stars(predict) text = str(i + 1) + ') ' + _unlabeled[i] print(dm.truncate_text(text, char_to_display) + ' ----- predicted ' + predict_stars) print("---------------------------------------- CUSTOM REVIEWS ----------------------------------------") while True: inp = input('Sample review:\n') z = dm.data_to_input(inp) prediction = model.predict(z) predict = prediction[0][0] predict_stars = dm.to_stars(predict) print(dm.truncate_text('', char_to_display) + ' ----- predicted ' + predict_stars)
import d_m as dm while True: inp = input('Word:') vec = dm.data_to_input(inp, 1)[0][0] print(vec) print(vec.shape) word = dm.vec2word(vec, 2) print(word)