hf-badges-lance / README.md
tsmithv11's picture
Publish hf-badges in Lance format (#1)
0d1a25d
|
Raw History Blame Contribute Delete
4.25 kB
metadata
license: mit
pretty_name: Hugging Face Badges in Lance
language:
  - en
size_categories:
  - n<1K
tags:
  - lance
  - badges
  - svg
  - image
  - text-retrieval
thumbnail: >-
  https://huggingface.co/datasets/lance-format/hf-badges-lance/resolve/main/source/badges-thumbnail.png
configs:
  - config_name: default
    default: true
    data_files:
      - split: train
        path: viewer/badges.parquet

Hugging Face Badges in Lance

Search the official Hugging Face badges by action and retrieve the original artwork by filename. The collection includes badges for sharing a dataset, deploying an app on Spaces, opening a pull request, and using ML Intern. Original Hugging Face Badges dataset and pinned source revision

Data

Lance table Rows Contents
lance/assets.lance 149 All original files, including 146 SVG variants, the thumbnail, source card, and Git attributes. Each row stores the original filename, bytes, byte length, and SHA-256 hash. SVG rows include the theme and any source label, target link, or title.
lance/actions.lance 23 One row per badge action, with its label, the text embedded for search, all filenames for that action, and a retrieval vector.

The upstream catalog has no train, validation, or test splits. Data Studio displays a Parquet preview of all 146 SVG variants rendered as PNGs under its default train split. The native Lance assets retain the original SVG bytes.

Search for badge actions

The source provides no embeddings. This release embeds each badge action in English using its source README heading or SVG title and a short description of the intended action, stored in embedded_text. Light and dark themes, sizes, and alternate filenames for the same action share one search result. The vectors use the first 256 dimensions of the encoder's Matryoshka representation with L2 normalization. The example uses the same encoder for the query and reports cosine similarity, with higher scores indicating closer matches. Pinned static retrieval encoder revision

pip install pylance==14.0.3 huggingface_hub==2.4.0 sentence-transformers==6.3.0
import lance
from huggingface_hub import HfApi
from sentence_transformers import SentenceTransformer

repo = "lance-format/hf-badges-lance"
root = f"hf://datasets/{repo}"
revision = HfApi(token=False).dataset_info(repo, token=False).sha
storage_options = {"hf_revision": revision}
encoder = SentenceTransformer(
    "sentence-transformers/static-retrieval-mrl-en-v1",
    revision="f60985c706f192d45d218078e49e5a8b6f15283a",
    truncate_dim=256,
    device="cpu",
)
query = "Show a badge to deploy my application on Hugging Face Spaces"
query_vector = encoder.encode_query(query, normalize_embeddings=True)
actions = lance.dataset(f"{root}/lance/actions.lance", storage_options=storage_options)
matches = actions.to_table(
    columns=["action_id", "action", "variant_filenames", "_distance"],
    nearest={"column": "embedding", "q": query_vector, "k": 5, "metric": "cosine"},
).to_pylist()

for match in matches:
    score = 1 - match["_distance"]
    filenames = ", ".join(match["variant_filenames"])
    print(f"{score:.4f}  {match['action_id']}  {match['action']}  {filenames}")

To save a badge as an original SVG, select a filename from the matches and read its bytes from the assets table.

from pathlib import Path

filename = matches[0]["variant_filenames"][0]
assets = lance.dataset(f"{root}/lance/assets.lance", storage_options=storage_options)
asset, = assets.to_table(
    filter=f"source_path = '{filename}'",
    columns=["source_bytes"],
).to_pylist()
Path(filename).write_bytes(asset["source_bytes"])

License and attribution

Hugging Face published the original artwork and documentation under the MIT license. This release adds the Lance tables, badge-action search, and PNG previews. Original dataset card · MIT license