lukasgarbas / nlp-text-emotion

Multi-class sentiment analysis lstm, finetuned bert
206 stars 79 forks source link

Can you help me with running prediction ? #4

Closed mark233456 closed 2 years ago

mark233456 commented 2 years ago

I am a beginner,and i am trying to run the prediction in a different script with the loaded model,but it starts training again instead of predicting. i copied the code for the LSTM in another script,and for the prediction i did the code like this :

import numpy as np import time

import pandas as pd

import keras import tensorflow as tf from keras.models import load_model

from LSTM_text_train import *

predictor = load_model('biLSTM_w2v.h5')

message = ['delivery was hour late and my pizza was cold!']

seq = tokenizer.texts_to_sequences(message) padded = pad_sequences(seq, maxlen=max_seq_len)

start_time = time.time() pred = model.predict(padded)

print('Message: ' + str(message)) print('predicted: {} ({:.2f} seconds)'.format(class_names[np.argmax(pred)], (time.time() - start_time)))

Thanks in advance !

kishan2k2 commented 1 year ago

It should be predictor.predict(padded)