Download README.md from Merlin041/imdb-distilbert-features: direct link, hf CLI and curl.
- Browser
- Download file 4.16 kB
-
https://huggingface.co/datasets/Merlin041/imdb-distilbert-features/resolve/293ca76df6108ae6eab2fccea29aa0c53d0ae0a0/README.md
- Command line
-
hf download hf://datasets/Merlin041/imdb-distilbert-features@293ca76df6108ae6eab2fccea29aa0c53d0ae0a0/README.md
-
curl -L -o README.md https://huggingface.co/datasets/Merlin041/imdb-distilbert-features/resolve/293ca76df6108ae6eab2fccea29aa0c53d0ae0a0/README.md
pretty_name: IMDb Sentiment Analysis - DistilBERT Feature Cache
dataset_info:
features:
- name: train_feat
dtype: float16
shape:
- 25000
- 128
- 768
- name: test_feat
dtype: float16
shape:
- 25000
- 128
- 768
- name: train_mask
dtype: bool
shape:
- 25000
- 128
- name: test_mask
dtype: bool
shape:
- 25000
- 128
configs:
- config_name: default
data_files:
- split: train
path: train_feat.npy
- split: test
path: test_feat.npy
tags:
- sentiment-analysis
- movie-reviews
- embeddings
- features
- distilbert
- rnn
- py-torch
IMDb Movie Reviews - DistilBERT Contextual Embedding Cache
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.
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.
📊 Dataset Specification
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.
| File | Shape | Dtype | Size on Disk | Description |
|---|---|---|---|---|
train_feat.npy |
(25000, 128, 768) |
float16 |
4.58 GB | Frozen DistilBERT last-hidden-state embeddings for the IMDb Train Split |
train_mask.npy |
(25000, 128) |
bool |
3.05 MB | Attention mask for the training split |
test_feat.npy |
(25000, 128, 768) |
float16 |
4.58 GB | Frozen DistilBERT last-hidden-state embeddings for the IMDb Test Split |
test_mask.npy |
(25000, 128) |
bool |
3.05 MB | Attention mask for the test split |
Extraction Details
- Base Model:
distilbert-base-uncased(frozen, Hugging Face transformers) - Tokenization: Contextual embeddings extracted from the last hidden state (768 dimensions).
- Sequence Length (
max_len): 128 tokens (truncated/padded). - Precision:
float16(RAM-safe memmap layout).
🚀 Downstream Classification Benchmark (Model v17)
We trained an LSTM-Attention hybrid head on top of these frozen features to evaluate their quality:
Classifier Architecture (Model v17)
- Input: Frozen DistilBERT Features (768-dim)
- Encoder: 2-layer Bidirectional LSTM (
hidden_dim=256,dropout=0.3, total 4.67M trainable parameters) - Aggregation: Multi-Head Attention (8 heads) followed by Concat Pooling (mean + max pooling)
- Output: Fully Connected (FC) layer with Label Smoothing (0.05)
Results
- Best Test Accuracy: 86.86%
- Best Test F1-Score: 86.99%
- Training Time: ~45 seconds per epoch on a local GPU.
Training curves and confusion matrix:
📈 Training Curves
🎯 Confusion Matrix
🛠️ Usage Example
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:
import numpy as np
import torch
from torch.utils.data import Dataset
class IMDbFeatureDataset(Dataset):
def __init__(self, feat_path, mask_path, labels, seq_len=128, bert_dim=768):
self.labels = labels
self.n = len(labels)
# Load as memory-mapped array (RAM-safe)
self.features = np.memmap(feat_path, dtype=np.float16, mode='r',
shape=(self.n, seq_len, bert_dim))
self.masks = np.memmap(mask_path, dtype=np.bool_, mode='r',
shape=(self.n, seq_len))
def __len__(self):
return self.n
def __getitem__(self, idx):
x = torch.from_numpy(self.features[idx].astype(np.float32)) # Convert to fp32
mask = torch.from_numpy(self.masks[idx])
y = torch.tensor(self.labels[idx], dtype=torch.float32)
return x, mask, y

