Downloads · 30 days
0
abhinav1857/nlp_for_journal
nlp_for_journal is a machine learning model from abhinav1857. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This repository contains a custom fine-tuned BERT + LSTM model for sentiment classification, trained on journal-style emotional writing. The model is designed to detect nuanced emotional states and works well for refl…
Downloads · 30 days
0
Access
Public
Updated May 7, 2025
Repo size
442 MB
Likes
0
Public
Click a slice to open those files.
.pt442 MB · 100%
From the Hugging Face model README
This repository contains a custom fine-tuned BERT + LSTM model for sentiment classification, trained on journal-style emotional writing. The model is designed to detect nuanced emotional states and works well for reflective, personal text (e.g., journaling, social media, diary entries).
bert-base-uncased (Hugging Face Transformers)LSTM to capture sentence-level emotional flow| File | Description |
|---|---|
bert_lstm_sentiment_model.pt | Trained PyTorch model (BERT + LSTM + Classifier) |
label_encoder.pkl | sklearn.preprocessing.LabelEncoder used during training |
The model was trained to classify the following emotional labels:
#pip install torch transformers scikit-learn #if not already installed, remove the first comment
import torch
import pickle
from transformers import BertTokenizer
# Load model
model = torch.load("bert_lstm_sentiment_model.pt", map_location=torch.device('cpu'))
model.eval()
# Load tokenizer and label encoder
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
with open("label_encoder.pkl", "rb") as f:
label_encoder = pickle.load(f)
# Sample input
text = "I feel empty and overwhelmed today."
# Tokenize
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
outputs = model(**inputs)
predicted_class = torch.argmax(outputs.logits, dim=1).item()
emotion = label_encoder.inverse_transform([predicted_class])[0]
print(f"Predicted Emotion: {emotion}")