Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pretty_name: IMDb Sentiment Analysis - DistilBERT Feature Cache
|
| 3 |
+
dataset_info:
|
| 4 |
+
features:
|
| 5 |
+
- name: train_feat
|
| 6 |
+
dtype: float16
|
| 7 |
+
shape: [25000, 128, 768]
|
| 8 |
+
- name: test_feat
|
| 9 |
+
dtype: float16
|
| 10 |
+
shape: [25000, 128, 768]
|
| 11 |
+
- name: train_mask
|
| 12 |
+
dtype: bool
|
| 13 |
+
shape: [25000, 128]
|
| 14 |
+
- name: test_mask
|
| 15 |
+
dtype: bool
|
| 16 |
+
shape: [25000, 128]
|
| 17 |
+
configs:
|
| 18 |
+
- config_name: default
|
| 19 |
+
data_files:
|
| 20 |
+
- split: train
|
| 21 |
+
path: train_feat.npy
|
| 22 |
+
- split: test
|
| 23 |
+
path: test_feat.npy
|
| 24 |
+
tags:
|
| 25 |
+
- sentiment-analysis
|
| 26 |
+
- movie-reviews
|
| 27 |
+
- embeddings
|
| 28 |
+
- features
|
| 29 |
+
- distilbert
|
| 30 |
+
- rnn
|
| 31 |
+
- py-torch
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
# IMDb Movie Reviews - DistilBERT Contextual Embedding Cache
|
| 35 |
+
|
| 36 |
+
This dataset contains pre-extracted contextual embedding features of the standard **IMDb Movie Reviews dataset (Sentiment Analysis)**. The features were extracted using a frozen **DistilBERT** (`distilbert-base-uncased`) encoder.
|
| 37 |
+
|
| 38 |
+
By caching these high-dimensional embeddings, you can train downstream classifiers (like LSTMs, GRUs, Attention heads, or custom Transformers) **in seconds** on a local GPU or CPU, bypassing the massive computation overhead of running transformer inference on every epoch.
|
| 39 |
+
|
| 40 |
+
## 📊 Dataset Specification
|
| 41 |
+
|
| 42 |
+
All features are saved as memory-mapped Numpy binary files (`.npy`), allowing them to be loaded on consumer hardware with low memory footprint via `np.memmap`.
|
| 43 |
+
|
| 44 |
+
| File | Shape | Dtype | Size on Disk | Description |
|
| 45 |
+
|---|---|---|---|---|
|
| 46 |
+
| **`train_feat.npy`** | `(25000, 128, 768)` | `float16` | 4.58 GB | Frozen DistilBERT last-hidden-state embeddings for the IMDb Train Split |
|
| 47 |
+
| **`train_mask.npy`** | `(25000, 128)` | `bool` | 3.05 MB | Attention mask for the training split |
|
| 48 |
+
| **`test_feat.npy`** | `(25000, 128, 768)` | `float16` | 4.58 GB | Frozen DistilBERT last-hidden-state embeddings for the IMDb Test Split |
|
| 49 |
+
| **`test_mask.npy`** | `(25000, 128)` | `bool` | 3.05 MB | Attention mask for the test split |
|
| 50 |
+
|
| 51 |
+
### Extraction Details
|
| 52 |
+
- **Base Model**: `distilbert-base-uncased` (frozen, Hugging Face transformers)
|
| 53 |
+
- **Tokenization**: Contextual embeddings extracted from the **last hidden state** (768 dimensions).
|
| 54 |
+
- **Sequence Length (`max_len`)**: 128 tokens (truncated/padded).
|
| 55 |
+
- **Precision**: `float16` (RAM-safe memmap layout).
|
| 56 |
+
|
| 57 |
+
---
|
| 58 |
+
|
| 59 |
+
## 🚀 Downstream Classification Benchmark (Model v17)
|
| 60 |
+
|
| 61 |
+
We trained an LSTM-Attention hybrid head on top of these frozen features to evaluate their quality:
|
| 62 |
+
|
| 63 |
+
### Classifier Architecture (Model v17)
|
| 64 |
+
- **Input**: Frozen DistilBERT Features (768-dim)
|
| 65 |
+
- **Encoder**: 2-layer Bidirectional LSTM (`hidden_dim=256`, `dropout=0.3`, total 4.67M trainable parameters)
|
| 66 |
+
- **Aggregation**: Multi-Head Attention (8 heads) followed by Concat Pooling (mean + max pooling)
|
| 67 |
+
- **Output**: Fully Connected (FC) layer with Label Smoothing (0.05)
|
| 68 |
+
|
| 69 |
+
### Results
|
| 70 |
+
- **Best Test Accuracy**: **86.86%**
|
| 71 |
+
- **Best Test F1-Score**: **86.99%**
|
| 72 |
+
- **Training Time**: ~45 seconds per epoch on a local GPU.
|
| 73 |
+
|
| 74 |
+
### Training curves and confusion matrix:
|
| 75 |
+
|
| 76 |
+
#### 📈 Training Curves
|
| 77 |
+

|
| 78 |
+
|
| 79 |
+
#### 🎯 Confusion Matrix
|
| 80 |
+

|
| 81 |
+
|
| 82 |
+
---
|
| 83 |
+
|
| 84 |
+
## 🛠️ Usage Example
|
| 85 |
+
|
| 86 |
+
You can load these files directly into PyTorch Dataset using memory mapping, which reads pages dynamically from disk without loading the entire 9.2 GB into RAM:
|
| 87 |
+
|
| 88 |
+
```python
|
| 89 |
+
import numpy as np
|
| 90 |
+
import torch
|
| 91 |
+
from torch.utils.data import Dataset
|
| 92 |
+
|
| 93 |
+
class IMDbFeatureDataset(Dataset):
|
| 94 |
+
def __init__(self, feat_path, mask_path, labels, seq_len=128, bert_dim=768):
|
| 95 |
+
self.labels = labels
|
| 96 |
+
self.n = len(labels)
|
| 97 |
+
# Load as memory-mapped array (RAM-safe)
|
| 98 |
+
self.features = np.memmap(feat_path, dtype=np.float16, mode='r',
|
| 99 |
+
shape=(self.n, seq_len, bert_dim))
|
| 100 |
+
self.masks = np.memmap(mask_path, dtype=np.bool_, mode='r',
|
| 101 |
+
shape=(self.n, seq_len))
|
| 102 |
+
|
| 103 |
+
def __len__(self):
|
| 104 |
+
return self.n
|
| 105 |
+
|
| 106 |
+
def __getitem__(self, idx):
|
| 107 |
+
x = torch.from_numpy(self.features[idx].astype(np.float32)) # Convert to fp32
|
| 108 |
+
mask = torch.from_numpy(self.masks[idx])
|
| 109 |
+
y = torch.tensor(self.labels[idx], dtype=torch.float32)
|
| 110 |
+
return x, mask, y
|
| 111 |
+
```
|