Datasets:
File size: 8,194 Bytes
8c3aca3 1749280 8c3aca3 1749280 8c3aca3 1749280 8c3aca3 1749280 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | ---
pretty_name: Adcom Captioned AI Images
tags:
- images
- captions
- ai-generated-images
- natural-language
license: apache-2.0
language:
- en
---
# ADCOM Captioned AI Images
## Dataset description
Adcom's captioned AI Images is a collection of images paired with associated
captioning and descriptive metadata.
The repository uses an indexed storage layout designed to make image retrieval
more efficient. Instead of storing all image data directly inside a single
metadata file, it separates the metadata index from the image data.
The dataset consists of:
- A Parquet metadata index: `captions.parquet`
- JSONL image shards containing the image data
- Byte offsets and record lengths in the Parquet index for direct image access
This layout allows users to retrieve individual images without downloading
and scanning every image shard.
## Repository structure
```text
adcom_captioned_ai_images/
│
├── README.md
├── captions.parquet
│
└── [JSONL image shards]
├── ...
└── ...
```
The exact shard paths are stored in the `json_file` column of
`captions.parquet`. Use those paths rather than assuming fixed shard names.
### 1. Metadata index: `captions.parquet`
The Parquet file contains one metadata/index row per image.
| Column | Description |
|---|---|
| `idx` | Image identifier |
| `prompt` | Text prompt or caption associated with the image |
| `tags` | Descriptive tags associated with the image |
| `author` | Author or contributor |
| `json_file` | Repository-relative path to the JSONL shard containing the image |
| `byte_offset` | Zero-based byte offset of the JSONL record within that shard |
| `byte_length` | Number of bytes to read for that record |
The index columns `json_file`, `byte_offset`, and `byte_length` are used
together to locate an image record directly.
Offsets and lengths refer to bytes, not character positions.
### 2. Image data: JSONL shards
Images are stored in JSONL files. Each line represents an individual image
record encoded as JSON.
A record has the following structure:
```json
{
"idx": "IMAGE_ID",
"image": "data:image/png;base64,..."
}
```
The `image` field contains a base64-encoded image, commonly represented as
a data URI. Consumers should also allow for a raw base64 string.
The `idx` field identifies the image and corresponds to the `idx` value in
the Parquet index.
### 3. How indexed retrieval works
For an image with a given `idx`:
1. Find its row in `captions.parquet`.
2. Read the row's `json_file`, `byte_offset`, and `byte_length`.
3. Download the referenced JSONL shard.
4. Seek to `byte_offset` in binary mode.
5. Read `byte_length` bytes.
6. Parse the JSON record and decode its base64 image.
This avoids scanning the entire shard for the selected image.
---
## Quick start
### Install dependencies
```bash
pip install pandas pyarrow pillow huggingface_hub
```
### Load the metadata index
```python
import pandas as pd
from huggingface_hub import hf_hub_download
REPO_ID = "codeShare/adcom_captioned_ai_images"
parquet_path = hf_hub_download(
repo_id=REPO_ID,
filename="captions.parquet",
repo_type="dataset"
)
metadata = pd.read_parquet(parquet_path)
print(metadata.head())
print(f"Total indexed images: {len(metadata):,}")
```
For a private or gated repository, authenticate with a Hugging Face
access token and pass it as the `token` argument to `hf_hub_download`.
### Retrieve one image by ID
This example downloads only the shard containing the requested image and
reads only the indexed record.
```python
import json
import base64
import re
import io
import pandas as pd
from PIL import Image
from huggingface_hub import hf_hub_download
REPO_ID = "codeShare/adcom_captioned_ai_images"
# Load the metadata index.
parquet_path = hf_hub_download(
repo_id=REPO_ID,
filename="captions.parquet",
repo_type="dataset"
)
metadata = pd.read_parquet(parquet_path)
# Choose an image ID from the index.
target_idx = str(metadata.iloc[0]["idx"])
# Find its index entry.
row = metadata.loc[
metadata["idx"].astype(str) == target_idx
].iloc[0]
# Download only the required shard.
shard_path = hf_hub_download(
repo_id=REPO_ID,
filename=str(row["json_file"]),
repo_type="dataset"
)
# Read the exact JSONL record using its byte location.
with open(shard_path, "rb") as f:
f.seek(int(row["byte_offset"]))
raw_record = f.read(int(row["byte_length"]))
record = json.loads(raw_record.decode("utf-8"))
# Verify the retrieved record.
assert str(record["idx"]) == target_idx
# Decode the image.
image_value = record["image"].strip()
if image_value.startswith("data:") and "," in image_value:
image_value = image_value.split(",", 1)[1]
image_value = re.sub(r"\s+", "", image_value)
image_bytes = base64.b64decode(image_value)
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
display(image)
print("Image ID:", target_idx)
print("Prompt:", row["prompt"])
print("Author:", row["author"])
print("Tags:", row["tags"])
```
### Retrieve a random sample of images
The following example samples metadata first and downloads only the shards
needed for the selected images.
```python
import json
import base64
import re
import io
import pandas as pd
from PIL import Image
from huggingface_hub import hf_hub_download
REPO_ID = "codeShare/adcom_captioned_ai_images"
NUM_SAMPLES = 10
RANDOM_SEED = 42
# Load the index.
parquet_path = hf_hub_download(
repo_id=REPO_ID,
filename="captions.parquet",
repo_type="dataset"
)
metadata = pd.read_parquet(parquet_path)
# Optional author filter.
# Set to None to include all authors.
AUTHOR_FILTER = "Adcom"
if AUTHOR_FILTER is not None:
metadata = metadata[
metadata["author"].fillna("").astype(str).str.casefold()
== AUTHOR_FILTER.casefold()
]
if metadata.empty:
raise ValueError("No matching records found.")
# Reproducible random sample.
sampled = metadata.sample(
n=min(NUM_SAMPLES, len(metadata)),
random_state=RANDOM_SEED
)
# Download only the shards required by the sample.
shard_cache = {}
for _, row in sampled.iterrows():
shard_name = str(row["json_file"])
if shard_name not in shard_cache:
shard_cache[shard_name] = hf_hub_download(
repo_id=REPO_ID,
filename=shard_name,
repo_type="dataset"
)
# Retrieve the indexed JSONL record.
with open(shard_cache[shard_name], "rb") as f:
f.seek(int(row["byte_offset"]))
raw_record = f.read(int(row["byte_length"]))
record = json.loads(raw_record.decode("utf-8"))
if str(record["idx"]) != str(row["idx"]):
raise ValueError("Image ID does not match the metadata index.")
# Decode image data.
image_value = record["image"].strip()
if image_value.startswith("data:") and "," in image_value:
image_value = image_value.split(",", 1)[1]
image_value = re.sub(r"\s+", "", image_value)
image_bytes = base64.b64decode(image_value)
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
print("Image ID:", row["idx"])
print("Prompt:", row["prompt"])
print("Author:", row["author"])
display(image)
image.close()
```
---
## Performance notes
- **Metadata-first sampling:** Select records from the Parquet index before downloading image data.
- **Selective shard downloads:** Only download shards referenced by the selected records.
- **Direct record access:** Use byte offsets and lengths instead of scanning JSONL files.
- **Reproducible sampling:** Set `random_state` to a fixed integer to reproduce a sample.
- **Private repository support:** Pass a Hugging Face token to the download functions when authentication is required.
## Important notes
- The Parquet index and JSONL shards must remain consistent. If shard contents are rewritten or reordered, the corresponding byte offsets and lengths must be regenerated.
- Image data is stored as base64 in JSONL records; it is decoded into image bytes when retrieved.
- The dataset card does not declare a license. Please consult the dataset owner for licensing and usage permissions before redistributing or using the data commercially. |