Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mark233456 opened this issue May 19, 2022 · 1 comment

Comments

@mark233456
Copy link

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
Copy link

Yes getting the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants