File size: 6,409 Bytes
896b6e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c525ba7
896b6e4
 
 
c525ba7
896b6e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c525ba7
896b6e4
 
 
 
 
 
 
 
 
 
 
 
c525ba7
 
896b6e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bad61ee
 
 
 
 
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
---
pretty_name: Hugging Face Course Documentation Images (Lance)
license: apache-2.0
language:
- en
tags:
- lance
- course
- documentation
- image-retrieval
task_categories:
- image-to-text
configs:
- config_name: default
  data_files:
  - split: test
    path: viewer/test.parquet
- config_name: catalog
  data_files:
  - split: assets
    path: viewer/assets.parquet
---

# Hugging Face Course Documentation Images in Lance

The Hugging Face LLM Course uses these diagrams, screenshots, illustrations, and animations in its lessons. This conversion preserves all 135 files and their original paths, including 132 images. The upstream Hub viewer has one two-image `test` split, which is preserved in Lance and as the exact original Parquet preview. The added image search table covers the complete asset collection. [Original dataset](https://huggingface.co/datasets/huggingface-course/documentation-images/tree/96e71ad956904da670e6827274fc2c9b735b09d5) · [LLM Course](https://huggingface.co/learn/llm-course/chapter1/1)

| Path | Rows | Contents |
| --- | ---: | --- |
| `lance/original-files.lance` | 135 | Every original file with bytes, relative path, size, MIME type, and hashes |
| `lance/images.lance` | 132 | Image paths, metadata, and search embeddings |
| `lance/test.lance` | 2 | Original Hub viewer `test` image rows |
| `viewer/test.parquet` | 2 | Original Hub viewer Parquet |
| `viewer/assets.parquet` | 132 | Thumbnails for browsing the full image collection |

The ["catalog" preview](https://huggingface.co/datasets/lance-format/documentation-images-lance/viewer/catalog/assets) uses full, proportionally scaled SVG renders and the first frame of each GIF. The files table retains the original SVGs, complete animations, and exact source bytes. [Source tree inventory](source/inventory.jsonl) · [Release metadata](release-info.json)

## Search images with text

The release generates 1,152-dimensional float32 image embeddings with the visual encoder of Google SigLIP 2 `google/siglip2-so400m-patch16-384` at revision `dd658faac399427308559e2c3ac1e99cbe43845d`. Images were composited onto white where transparent. Sharp and librsvg render the full SVG viewport at its original aspect ratio. SVGs are centered on a white 384 × 384 canvas for encoding. GIFs use their first frame. The example uses the model's paired text encoder, normalizes both modalities to unit length, and prints five source paths with cosine similarity, calculated as one minus Lance's cosine distance. [Pinned SigLIP 2 checkpoint](https://huggingface.co/google/siglip2-so400m-patch16-384/tree/dd658faac399427308559e2c3ac1e99cbe43845d)

Install the dependencies with `python -m pip install "pylance==14.0.3" "transformers==5.23.0" torch pillow huggingface_hub`.

```python
import lance
import torch
from huggingface_hub import HfApi
from transformers import AutoModel, AutoProcessor

repo = "lance-format/documentation-images-lance"
revision = HfApi(token=False).dataset_info(repo, token=False).sha
uri = f"hf://datasets/{repo}/lance"
options = {"hf_revision": revision}
images = lance.dataset(f"{uri}/images.lance", storage_options=options)

checkpoint = "google/siglip2-so400m-patch16-384"
model_revision = "dd658faac399427308559e2c3ac1e99cbe43845d"
encoder = AutoModel.from_pretrained(checkpoint, revision=model_revision).eval()
processor = AutoProcessor.from_pretrained(checkpoint, revision=model_revision)
query = "a diagram of a transformer model with an encoder and a decoder"
inputs = processor(text=[query.lower()], padding="max_length", max_length=64, truncation=True, return_tensors="pt")
with torch.inference_mode():
    pooled = encoder.get_text_features(**inputs).pooler_output
    vector = torch.nn.functional.normalize(pooled.float(), dim=-1)[0].numpy()

hits = images.to_table(
    columns=["source_path", "content_type", "_distance"],
    nearest={"column": "embedding", "q": vector, "k": 5, "metric": "cosine"},
).to_pylist()
for hit in hits:
    print(f"{1 - hit['_distance']:.4f}  {hit['source_path']}  {hit['content_type']}")
```

In a small check on 16 queries with known target images, the full SVG renders moved two more targets into the top five, from 11 to 13. The score shown for each result is raw cosine similarity. [Query check and preprocessing details](release-info.json)

## Retrieve an original asset

```python
from pathlib import Path

import lance
from huggingface_hub import HfApi

repo = "lance-format/documentation-images-lance"
revision = HfApi(token=False).dataset_info(repo, token=False).sha
files = lance.dataset(
    f"hf://datasets/{repo}/lance/original-files.lance",
    storage_options={"hf_revision": revision},
)
asset, = files.to_table(
    columns=["original_bytes"],
    filter="source_path = 'en/chapter1/transformers_architecture.png'",
    limit=1,
).to_pylist()
Path("transformers_architecture.png").write_bytes(asset["original_bytes"])
```

## Source and license

Original assets are credited to Hugging Face and the LLM Course contributors. The dataset card declares Apache 2.0, and the course project includes the Apache 2.0 license. Changes in this release consist of added Lance tables, image embeddings, thumbnails, and file metadata. Image trademarks and other embedded notices remain visible in the originals. [Original card](source/README.md) · [Apache 2.0 license](LICENSE) · [Course source](https://github.com/huggingface/course)

### Credits for screenshots of published posts

- `en/chapter8/stack-overflow.png` reproduces an answer by **cronoik**, posted on March 14, 2021. The embedded answer remains under **CC BY-SA 4.0**. The Lance files table preserves the exact course screenshot, and the catalog preview displays a resized copy. [Original answer](https://stackoverflow.com/a/66626813) · [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/) · [Stack Overflow licensing](https://stackoverflow.com/help/licensing)
- `en/chapter5/datasets-issues-comment.png` shows **yjernite** and **patrickvonplaten** discussing a Common Voice update. `en/chapter5/datasets-issues-single.png` shows **lewtun**'s Wikipedia streaming issue. `en/chapter5/datasets-issues.png` shows the issue list. [Common Voice issue](https://github.com/huggingface/datasets/issues/2730) · [Wikipedia streaming issue](https://github.com/huggingface/datasets/issues/2808) · [Hugging Face Datasets issue list](https://github.com/huggingface/datasets/issues)