lukasgarbas / nlp-text-emotion

Multi-class sentiment analysis lstm, finetuned bert
204 stars 80 forks source link

every time i do a prediction,the predicted emotion is neutral. i tried with lstm and cnn #5

Open mark233456 opened 2 years ago

mark233456 commented 2 years ago

could you help me for a bit ? this is what i did to run the prediction.

import pandas as pd import numpy as np import tensorflow as tf import tensorflow.keras as keras

text preprocessing

from nltk.tokenize import word_tokenize import re

plots and metrics

import matplotlib.pyplot as plt from sklearn.metrics import accuracy_score, f1_score, confusion_matrix

preparing input to our model

from tensorflow.keras.preprocessing.text import Tokenizer from tensorflow.keras.preprocessing.sequence import pad_sequences from tensorflow.keras.utils import to_categorical

keras layers

from keras.models import Sequential from tensorflow.keras.layers import Embedding, Conv1D, GlobalMaxPooling1D, Dense from keras.models import load_model

import time

max_seq_len = 500

tokenizer = Tokenizer()

message = ['i am so sad!']

class_names = ['joy', 'fear', 'anger', 'sadness', 'neutral']

model= load_model('models/cnn_w2v.h5')

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)))

kishan2k2 commented 1 year ago

Yes getting the same error