Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- sentiment-analysis
|
| 5 |
+
- text-classification
|
| 6 |
+
- openai-embeddings
|
| 7 |
+
- pytorch
|
| 8 |
+
pipeline_tag: text-classification
|
| 9 |
+
library_name: transformers
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# TextEmbedding3SmallSentimentHead
|
| 13 |
+
|
| 14 |
+
In case you needed a sentiment analysis classifier on top of embeddings from OpenAI embeddings model.
|
| 15 |
+
|
| 16 |
+
## Model Description
|
| 17 |
+
|
| 18 |
+
- **What this is**: A compact PyTorch classifier head trained on top of `text-embedding-3-small` (1536-dim) to predict sentiment: negative, neutral, positive.
|
| 19 |
+
- **Data**: Preprocessed from the [Kaggle Sentiment Analysis Dataset](https://www.kaggle.com/datasets/abhi8923shriv/sentiment-analysis-dataset).
|
| 20 |
+
- **Metrics (val)**: **F1 macro ≈ 0.89**, **Accuracy ≈ 0.89** on a held-out validation split.
|
| 21 |
+
- **Architecture**: Simple MLP head (256 hidden units, dropout 0.2), trained for 5 epochs with Adam.
|
| 22 |
+
|
| 23 |
+
## Input/Output
|
| 24 |
+
|
| 25 |
+
- **Input**: Float32 tensor of shape `[batch, 1536]` (OpenAI text-embedding-3-small embeddings).
|
| 26 |
+
- **Output**: Logits over 3 classes. Argmax → {0: negative, 1: neutral, 2: positive}.
|
| 27 |
+
|
| 28 |
+
## Usage
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
from transformers import AutoModel
|
| 32 |
+
import torch
|
| 33 |
+
|
| 34 |
+
# Load model
|
| 35 |
+
model = AutoModel.from_pretrained(
|
| 36 |
+
"marcovise/TextEmbedding3SmallSentimentHead",
|
| 37 |
+
trust_remote_code=True
|
| 38 |
+
).eval()
|
| 39 |
+
|
| 40 |
+
# Your 1536-dim OpenAI embeddings
|
| 41 |
+
embeddings = torch.randn(4, 1536) # batch of 4 examples
|
| 42 |
+
|
| 43 |
+
# Predict sentiment
|
| 44 |
+
with torch.no_grad():
|
| 45 |
+
logits = model(inputs_embeds=embeddings)["logits"] # [batch, 3]
|
| 46 |
+
predictions = logits.argmax(dim=1) # [batch]
|
| 47 |
+
# 0=negative, 1=neutral, 2=positive
|
| 48 |
+
|
| 49 |
+
print(predictions) # tensor([1, 0, 2, 1])
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
## Training Details
|
| 53 |
+
|
| 54 |
+
- **Training data**: Kaggle Sentiment Analysis Dataset
|
| 55 |
+
- **Preprocessing**: Text → OpenAI embeddings → 3-class labels {negative: 0.0, neutral: 0.5, positive: 1.0}
|
| 56 |
+
- **Architecture**: 1536 → 256 → ReLU → Dropout(0.2) → 3 classes
|
| 57 |
+
- **Optimizer**: Adam (lr=1e-3, weight_decay=1e-4)
|
| 58 |
+
- **Loss**: CrossEntropyLoss with label smoothing (0.05)
|
| 59 |
+
- **Epochs**: 5
|
| 60 |
+
|
| 61 |
+
## Intended Use
|
| 62 |
+
|
| 63 |
+
- Quick, lightweight sentiment classification for short text once embeddings are available.
|
| 64 |
+
- Works well for general sentiment analysis tasks similar to the training distribution.
|
| 65 |
+
|
| 66 |
+
## Limitations
|
| 67 |
+
|
| 68 |
+
- Trained on a specific sentiment dataset; may have domain bias.
|
| 69 |
+
- Requires OpenAI text-embedding-3-small embeddings as input.
|
| 70 |
+
- Not safety-critical; evaluate before production use.
|
| 71 |
+
- May reflect biases present in the training data.
|
| 72 |
+
|
| 73 |
+
## License
|
| 74 |
+
|
| 75 |
+
MIT
|