NeuroFeel is a lightweight NLP model built on NeuroBERT, fine-tuned for short-text emotion detection. With a ~25MB size and ~7M parameters, it classifies text into 13 emotional categories (e.g., Happiness π, Sadness π’, Love β€οΈ). Optimized for edge AI, IoT, and mobile apps, it delivers real-time, offline emotion analysis for chatbots, social media, mental health, and wearable devices.
NeuroFeel brings nuanced emotion detection to edge devices with privacy and efficiency.
Watch this step-by-step guide to train your machine learning model:
Emotion | Emoji |
---|---|
Sadness | π’ |
Anger | π |
Love | β€οΈ |
Surprise | π² |
Fear | π± |
Happiness | π |
Neutral | π |
Disgust | π€’ |
Shame | π |
Guilt | π |
Confusion | π |
Desire | π₯ |
Sarcasm | π |
pip install transformers torch
Requires Python 3.6+, ~25MB storage.
from transformers import pipeline
# Load model
sentiment_analysis = pipeline("text-classification", model="boltuix/NeuroFeel")
# Analyze emotion
result = sentiment_analysis("i love you")
print(result)
Output: [{'label': 'Love', 'score': 0.8563215732574463}]
from transformers import pipeline
# Load model
sentiment_analysis = pipeline("text-classification", model="boltuix/NeuroFeel")
# Emoji mapping
label_to_emoji = {
"Sadness": "π’", "Anger": "π ", "Love": "β€οΈ", "Surprise": "π²", "Fear": "π±",
"Happiness": "π", "Neutral": "π", "Disgust": "π€’", "Shame": "π", "Guilt": "π",
"Confusion": "π", "Desire": "π₯", "Sarcasm": "π"
}
# Input text
text = "i love you"
# Analyze emotion
result = sentiment_analysis(text)[0]
label = result["label"].capitalize()
emoji = label_to_emoji.get(label, "β")
# Output
print(f"Text: {text}")
print(f"Predicted Emotion: {label} {emoji}")
print(f"Confidence: {result['score']:.2%}")
Output: Text: i love you
Predicted Emotion: Love β€οΈ
Confidence: 85.63%
Access the Emotions Dataset to enhance your AI models:
import pandas as pd
from transformers import BertTokenizer, BertForSequenceClassification, Trainer, TrainingArguments
from sklearn.model_selection import train_test_split
import torch
from torch.utils.data import Dataset
# Load data
dataset_path = '/content/dataset.csv'
df = pd.read_csv(dataset_path)
df = df.dropna(subset=['Label'])
df.columns = ['text', 'label']
# Encode labels
labels = sorted(df["label"].unique())
label_to_id = {label: idx for idx, label in enumerate(labels)}
id_to_label = {idx: label for label, idx in label_to_id.items()}
df['label'] = df['label'].map(label_to_id)
# Train/val split
train_texts, val_texts, train_labels, val_labels = train_test_split(
df['text'].tolist(), df['label'].tolist(), test_size=0.2, random_state=42
)
# Tokenizer
tokenizer = BertTokenizer.from_pretrained("boltuix/NeuroBERT-Pro")
# Dataset class
class SentimentDataset(Dataset):
def __init__(self, texts, labels, tokenizer, max_length=128):
self.texts = texts
self.labels = labels
self.tokenizer = tokenizer
self.max_length = max_length
def __len__(self):
return len(self.texts)
def __getitem__(self, idx):
encoding = self.tokenizer(
self.texts[idx],
padding='max_length',
truncation=True,
max_length=self.max_length,
return_tensors='pt'
)
return {
'input_ids': encoding['input_ids'].squeeze(0),
'attention_mask': encoding['attention_mask'].squeeze(0),
'labels': torch.tensor(self.labels[idx], dtype=torch.long)
}
# Load datasets
train_dataset = SentimentDataset(train_texts, train_labels, tokenizer)
val_dataset = SentimentDataset(val_texts, val_labels, tokenizer)
# Load model
model = BertForSequenceClassification.from_pretrained(
"boltuix/NeuroBERT-Pro",
num_labels=len(label_to_id)
)
# Ensure contiguous tensor layout
for param in model.parameters():
param.data = param.data.contiguous()
# Training arguments
training_args = TrainingArguments(
output_dir='./results',
run_name="NeuroFeel",
num_train_epochs=5,
per_device_train_batch_size=16,
per_device_eval_batch_size=16,
warmup_steps=500,
weight_decay=0.01,
logging_dir='./logs',
logging_steps=10,
eval_strategy="epoch",
report_to="none"
)
# Trainer setup
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
eval_dataset=val_dataset
)
# Train and evaluate
trainer.train()
trainer.evaluate()
# Save model and label mappings
model.config.label2id = label_to_id
model.config.id2label = id_to_label
model.config.num_labels = len(label_to_id)
model.save_pretrained("./neuro-feel")
tokenizer.save_pretrained("./neuro-feel")
print("β
Training complete. Model and tokenizer saved to ./neuro-feel")
Model | Parameters | Size | Edge/IoT Focus | Tasks |
---|---|---|---|---|
NeuroFeel | ~7M | ~25MB | High | Emotion Detection, Classification |
NeuroBERT | ~7M | ~30MB | High | MLM, NER, Classification |
BERT-Lite | ~2M | ~10MB | High | MLM, NER, Classification |
DistilBERT | ~66M | ~200MB | Moderate | MLM, NER, Classification, Sentiment |
Apache-2.0 License: Free to use. See LICENSE.
NeuroFeel delivers real-time emotion detection with 13 nuanced categories, optimized for edge AI and IoT. Ideal for chatbots, social media, mental health, and wearables, itβs your solution for expressive AI in 2025. Explore it on Hugging Face!