tsmithv11's picture
Credit the original Stack Overflow screenshot excerpt (#2)
bad61ee
|
Raw History Blame Contribute Delete
6 kB
---
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 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. SVGs use rasterized previews and 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], padding="max_length", 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']}")
```
## 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)