nlp-text-emotion icon indicating copy to clipboard operation
nlp-text-emotion copied to clipboard

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

Open mark233456 opened this issue 3 years ago • 1 comments

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

mark233456 avatar May 19 '22 14:05 mark233456

Yes getting the same error

kishan2k2 avatar Sep 20 '23 20:09 kishan2k2