Datasets:
Tasks:
Other
Modalities:
Time-series
Formats:
parquet
Languages:
English
Size:
10K - 100K
ArXiv:
License:
Add dataset card and loading script
Browse files
README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
task_categories:
|
| 6 |
+
- other
|
| 7 |
+
tags:
|
| 8 |
+
- gemma
|
| 9 |
+
- titans
|
| 10 |
+
- activations
|
| 11 |
+
- hidden-states
|
| 12 |
+
- precomputed
|
| 13 |
+
size_categories:
|
| 14 |
+
- 100K<n<1M
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# OpenWebText — Gemma-3-1B Hidden State Activations (Layer 23)
|
| 18 |
+
|
| 19 |
+
Precomputed hidden state activations from layer 23 of [Gemma-3-1B-IT](https://huggingface.co/google/gemma-3-1b-it) for the [OpenWebText](https://huggingface.co/datasets/Skylion007/openwebtext) dataset, tokenized with sequence length 1024.
|
| 20 |
+
|
| 21 |
+
Designed for training a **[Titans](https://arxiv.org/abs/2501.00663)** memory layer inserted after layer 23 of Gemma 3.
|
| 22 |
+
|
| 23 |
+
## Dataset Structure
|
| 24 |
+
|
| 25 |
+
Each shard contains pre-computed forward pass outputs up to layer 23:
|
| 26 |
+
|
| 27 |
+
| File | Shape | Dtype | Description |
|
| 28 |
+
|------|-------|-------|-------------|
|
| 29 |
+
| `shard_NNNNNN.npy` | `(64, 1024, 3072)` | `bfloat16` | Hidden state activations |
|
| 30 |
+
| `shard_NNNNNN_masks.npy` | `(64, 1024)` | `int32` | Attention masks (1=real, 0=pad) |
|
| 31 |
+
| `shard_NNNNNN_tokens.npy` | `(64, 1024)` | `int32` | Token IDs |
|
| 32 |
+
|
| 33 |
+
- **Shards:** 1121 (000000–001120)
|
| 34 |
+
- **Examples per shard:** 64
|
| 35 |
+
- **Total examples:** ~71,744
|
| 36 |
+
- **Sequence length:** 1024
|
| 37 |
+
- **Hidden dimension:** 3072 (Gemma-3-1B embed_dim)
|
| 38 |
+
- **Source model:** `google/gemma-3-1b-it`
|
| 39 |
+
- **Source dataset:** `veriga/openwebtext-gemma3-tokenized-1024`
|
| 40 |
+
- **Total size:** ~153 GB
|
| 41 |
+
|
| 42 |
+
## How It Was Created
|
| 43 |
+
|
| 44 |
+
Activations were computed using a truncated forward pass through the first 23 Gemma 3 transformer layers. The process:
|
| 45 |
+
|
| 46 |
+
1. Load OpenWebText tokens from `veriga/openwebtext-gemma3-tokenized-1024`
|
| 47 |
+
2. Pad/truncate to 1024 tokens, generate attention masks
|
| 48 |
+
3. Forward pass through layers 0–22 of Gemma-3-1B-IT
|
| 49 |
+
4. Apply attention mask: `hidden * mask[:, :, None]` (zero out padding positions)
|
| 50 |
+
5. Save as `.npy` shards in `bfloat16`
|
| 51 |
+
|
| 52 |
+
See the [precomputation notebook](https://github.com/andrew-veriga/Titans_jax/blob/main/colabs/Precompute_Activations_Gemma3_GPU.ipynb) for full details.
|
| 53 |
+
|
| 54 |
+
## Loading the Dataset
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
from datasets import load_dataset
|
| 58 |
+
|
| 59 |
+
ds = load_dataset("veriga/openwebtext-gemma3-tokenized-1024-activations-layer23", split="train")
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
Each example contains:
|
| 63 |
+
```python
|
| 64 |
+
{
|
| 65 |
+
"activations": np.ndarray, # shape (1024, 3072), float32 (cast from bfloat16)
|
| 66 |
+
"mask": np.ndarray, # shape (1024,), int32
|
| 67 |
+
"tokens": np.ndarray, # shape (1024,), int32
|
| 68 |
+
}
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### Streaming (recommended for large datasets)
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
ds = load_dataset(
|
| 75 |
+
"veriga/openwebtext-gemma3-tokenized-1024-activations-layer23",
|
| 76 |
+
split="train",
|
| 77 |
+
streaming=True
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
for example in ds:
|
| 81 |
+
activations = example["activations"] # (1024, 3072)
|
| 82 |
+
mask = example["mask"] # (1024,)
|
| 83 |
+
tokens = example["tokens"] # (1024,)
|
| 84 |
+
# Use for Titans training...
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
### Manual loading (without HF datasets)
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
import numpy as np
|
| 91 |
+
|
| 92 |
+
shard_idx = 0
|
| 93 |
+
activations = np.load(f"shard_{shard_idx:06d}.npy") # (64, 1024, 3072), bfloat16
|
| 94 |
+
mask = np.load(f"shard_{shard_idx:06d}_masks.npy") # (64, 1024), int32
|
| 95 |
+
tokens = np.load(f"shard_{shard_idx:06d}_tokens.npy") # (64, 1024), int32
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
## Use Case: Titans Memory Layer
|
| 99 |
+
|
| 100 |
+
This dataset is intended for training a [Titans](https://arxiv.org/abs/2501.00663) long-term memory module to be inserted after layer 23 of Gemma 3. The precomputed activations allow training the memory layer independently without running the full model forward pass.
|
| 101 |
+
|
| 102 |
+
## Notes
|
| 103 |
+
|
| 104 |
+
- Activations are stored in `bfloat16`; the HF Datasets loader casts them to `float32` for compatibility
|
| 105 |
+
- Padding positions in activations are zeroed out via attention mask multiplication
|
| 106 |
+
- The `metadata.json` file contains `{"next_shard": 1120}` used for resume during precomputation
|
openwebtext-gemma3-tokenized-1024-activations-layer23.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import glob
|
| 3 |
+
import datasets
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
_DESCRIPTION = """\
|
| 7 |
+
Precomputed hidden state activations from layer 23 of Gemma-3-1B-IT
|
| 8 |
+
for the OpenWebText dataset, tokenized with sequence length 1024.
|
| 9 |
+
Designed for training a Titans memory layer.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
_SHARD_BASE = "shard_[0-9]*.npy"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class OpenwebtextGemma3Tokenized1024ActivationsLayer23(datasets.GeneratorBasedBuilder):
|
| 16 |
+
VERSION = datasets.Version("1.0.0")
|
| 17 |
+
|
| 18 |
+
def _info(self):
|
| 19 |
+
return datasets.DatasetInfo(
|
| 20 |
+
description=_DESCRIPTION,
|
| 21 |
+
features=datasets.Features({
|
| 22 |
+
"activations": datasets.Array3D(shape=(1024, 3072), dtype="float32"),
|
| 23 |
+
"mask": datasets.Array2D(shape=(1024,), dtype="int32"),
|
| 24 |
+
"tokens": datasets.Array2D(shape=(1024,), dtype="int32"),
|
| 25 |
+
}),
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
def _split_generators(self, dl_manager):
|
| 29 |
+
all_npy = sorted(glob.glob(_SHARD_BASE))
|
| 30 |
+
shards = [f for f in all_npy
|
| 31 |
+
if not f.endswith("_masks.npy") and not f.endswith("_tokens.npy")]
|
| 32 |
+
return [datasets.SplitGenerator(
|
| 33 |
+
name=datasets.Split.TRAIN,
|
| 34 |
+
gen_kwargs={"shard_files": shards},
|
| 35 |
+
)]
|
| 36 |
+
|
| 37 |
+
def _generate_examples(self, shard_files):
|
| 38 |
+
for shard_path in shard_files:
|
| 39 |
+
shard_id = shard_path.split("shard_")[1].split(".npy")[0]
|
| 40 |
+
act = np.load(shard_path).astype(np.float32)
|
| 41 |
+
mask = np.load(shard_path.replace(".npy", "_masks.npy"))
|
| 42 |
+
tokens = np.load(shard_path.replace(".npy", "_tokens.npy"))
|
| 43 |
+
for i in range(act.shape[0]):
|
| 44 |
+
yield f"{shard_id}_{i}", {
|
| 45 |
+
"activations": act[i],
|
| 46 |
+
"mask": mask[i],
|
| 47 |
+
"tokens": tokens[i],
|
| 48 |
+
}
|