Diwash Pandey - Full Stack & AI/ML Developer Official Logo
12:50:17 AMKTM / NPT +5:45

Explore

Back to AI Lab
NLP#WLCDNK

Neural Sentiment Analysis with LSTM

Emotion Detector

Published

3/26/2026

Type

Applied AI

Views

1

Status

Published

Attached Dataset

download_data.py

1. Objective

This experiment implements a Long Short-Term Memory (LSTM) network to classify text sequences into emotional states. The goal is to achieve high precision in identifying negative sentiment within customer feedback logs.


2. Model Architecture

The network consists of:

  • An Embedding layer
  • Two stacked LSTM layers
  • A Dense output layer with Softmax activation

🔧 Training Script

python
import tensorflow as tf from tensorflow.keras.layers import LSTM, Dense, Embedding # Defining the architecture model = tf.keras.Sequential([ Embedding(input_dim=5000, output_dim=128), LSTM(64, return_sequences=True), LSTM(32), Dense(3, activation='softmax') ]) model.compile(optimizer='adam', loss='categorical_crossentropy') print("NETWORK_INITIALIZED_SUCCESSFULLY")

3. Results & Logs

After 50 epochs, the model converged with a steady decrease in categorical cross-entropy.

Output
Epoch 50/50
loss: 0.1421 - accuracy: 0.9654 - val_loss: 0.2104 - val_accuracy: 0.9211
---
Final Metrics:
Precision: 0.94
Recall: 0.91
F1-Score: 0.92

4. Visual Analysis

Below is the confusion matrix generated during the evaluation phase:

(Confusion matrix image will be rendered here via Supabase / Markdown image upload)


📌 End of Experiment Log

End of experiment