uce-gemini-80k

The model maps Gemini text embeddings to 80,513 labeled concept activations. Its float32 encoder selects the top 128 scores among those concepts, producing at most 128 nonzero activations per text.

Input

Provide a NumPy array of shape (N, 3072) containing embeddings from gemini-embedding-2-preview, using the RETRIEVAL_DOCUMENT task type. Do not apply additional unit normalization. Generate the embeddings separately; this package takes embeddings as input rather than raw text.

Usage

For dictionaries only, obtain gemini_uce.py and concept_metadata.py from the same pinned Hub revision, then run Python from their directory. Install huggingface_hub for remote loading and NumPy if including prevalences. Neither weights nor neural dependencies are needed:

from gemini_uce import load_concept_dict

concepts = load_concept_dict("klpeng/uce-gemini-80k", revision="<commit>")

For encoding, download the full package, including _gemini_model.py:

Download the model files and run the following from the model directory:

pip install -r requirements.txt
import numpy as np
from gemini_uce import GeminiUCE

model = GeminiUCE.from_pretrained(".", device="cpu")
embeddings = np.load("embeddings.npy", mmap_mode="r")
activations = model.encode(embeddings, batch_size=64)

print(activations.shape)  # (N, 80513), a SciPy CSR sparse matrix
print(model.explain(activations[0], top_n=10))

model.explain(row, top_n=10) returns up to 10 active concepts from one sparse output row, ordered by decreasing activation. Each result is a dictionary with concept_id, label, and activation. It looks up the saved labels; it does not run another model or make an API call. top_n controls how many concepts are displayed, not the encoder's top-128 selection.

Use device="cuda" for an NVIDIA GPU. Keep the model in float32. For large datasets, model.encode_iter(embeddings, batch_size=64) yields sparse batches without collecting the full output in memory.

Concept dictionary

GeminiUCE.from_pretrained() populates model.concept_dict, a plain dict[int, dict]. Keys cover exactly 0..model.num_features-1; key i describes column i of encode(). Every entry has a string label. Saved fidelity fields such as f1, precision, and recall keep their original names; undefined metrics are None, and absent fidelity metadata adds no metric fields. Historical feature_id values are metadata, never activation column IDs.

from gemini_uce import GeminiUCE, load_concept_dict

revision = "<Hub commit used for these activations>"
model = GeminiUCE.from_pretrained("klpeng/uce-gemini-80k", revision=revision)
concepts = model.concept_dict
print(concepts[0]["label"], concepts[0].get("f1"))

# Use the same dictionary alongside cached activations, without model weights.
concepts = load_concept_dict("klpeng/uce-gemini-80k", revision=revision)
# Or load from a local package directory:
labels_only = load_concept_dict("./uce-gemini-80k", include_fidelity=False)

include_fidelity=True is the default on the model loader and load_concept_dict(). Set it to False to skip fidelity loading and omit fidelity fields. Model loading reads metadata from the same resolved snapshot as the weights. For cached activations, record and reuse the exact Hub commit; the dictionary loader accepts revision, cache_dir, and local_files_only. It downloads only config, labels, optional fidelity files, and provenance, with no weights, and imports no neural or table dependencies. Prevalence files are skipped unless include_prevalence=True.

Set include_prevalence=True on the model loader or load_concept_dict() to add the saved corpus-wide baseline fields to each entry. The default is False. Fields retain their original names, including n_corpus_rows, count_gt_0p05, prevalence_gt_0p05, and prevalence_gt_0p05_upper_99 (plus any other saved thresholds/bounds). Values are plain Python numbers; packages without prevalence metadata add no prevalence fields.

concepts = load_concept_dict(
    "klpeng/uce-gemini-80k", revision=revision, include_prevalence=True,
)
print(concepts[0]["prevalence_gt_0p05"])
# Populate model.concept_dict with the same fields during model loading:
model = GeminiUCE.from_pretrained(
    "klpeng/uce-gemini-80k", revision=revision, include_prevalence=True,
)

These are the historical Gemini teacher corpus prevalences described above, not rates measured from this pruned encoder’s outputs. Thresholds and confidence bounds keep their saved definitions; no prevalence is estimated or recomputed.

The returned dictionary is an ordinary mutable copy; editing it does not update saved metadata.

Working with concept dictionaries

Search labels with ordinary Python:

matches = {i: c for i, c in concepts.items() if "democracy" in c["label"].casefold()}

For tables, install pandas separately:

import pandas as pd

table = pd.DataFrame.from_dict(concepts, orient="index").rename_axis("concept_id")
table.to_csv("concepts.csv")

The dictionary loader accepts local directories, revision, cache_dir, and local_files_only. It requires no PyTorch, Transformers, SciPy, or pandas. NumPy is required only when loading prevalence arrays. Standalone use needs gemini_uce.py and concept_metadata.py; full inference also needs _gemini_model.py. Pin the Hub commit to match cached activations. The model exposes its source information as model.provenance; the dictionary itself contains only concepts.

Example

With model loaded above, embed a sentence and display its 50 highest-activating concepts. The embedding step uses the Google GenAI SDK and requires your Gemini API key in the GEMINI_API_KEY environment variable:

pip install google-genai
import os
from google import genai
from google.genai import types

text = "Djokovic Overwhelms Nadal for the Wimbledon Title"
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
response = client.models.embed_content(
    model="gemini-embedding-2-preview",
    contents=[text],
    config=types.EmbedContentConfig(
        task_type="RETRIEVAL_DOCUMENT",
        output_dimensionality=3072,
    ),
)
example_embeddings = np.array(
    [embedding.values for embedding in response.embeddings], dtype=np.float32
)
example_activations = model.encode(example_embeddings)

for concept in model.explain(example_activations[0], top_n=50):
    print(
        f"{concept['concept_id']:5d}  "
        f"{concept['activation']:.6f}  {concept['label']}"
    )

The output lists the concept ID, activation score, and saved label for each of the top 50 active concepts, ordered from highest to lowest activation.

Concepts and prevalences

The saved prevalences describe 89,827,558 historical Gemini corpus rows. They were computed with global top-128 selection among 131,072 source features, then restricted and remapped to these 80,513 coordinates. They are heuristic baselines, not prevalences recomputed for this physically pruned encoder. Saved thresholds and one-sided 99% confidence bounds keep their original definitions.

model.get_prevalence(i) returns the saved statistics for column i. model.explain(row, include_prevalence=True) includes them under baseline_prevalence for each explained concept. Plain explain() keeps its existing return format.

  • labels.csv has one row per output coordinate: concept_id is the column index (0–80512), label is the concept name, and discussion is a description of activating examples used to produce the label.
  • prevalences.csv and prevalences.npz contain the same heuristic corpus prevalences at activation thresholds >0.05 and >0.1, with counts and one-sided 99% upper confidence bounds. These can be used to identify concepts that are enriched in your dataset.

Per-concept fidelities

fidelities.csv contains precision, recall, F1, accuracy, positive/zero YES rates, and confusion counts for all 80,513 concepts. Join to labels.csv or encoder output columns using concept_id; feature_id is a historical source coordinate. fidelity_summary.json contains aggregate results, and fidelities.json records the evaluation method and source hashes.

Reference: Original Gemini activation >0.05 versus exact zero; up to 50 positives and 50 zeros per concept. GPT-6 Luna with reasoning disabled judged held-out test texts (256-word cap). Annotation YES is the prediction; activating versus zero is the reference. These conditional positive/zero sample metrics are automated judgments and are not weighted by corpus prevalence. Empty recall/F1 cells indicate concepts with no positive examples; these are excluded from corresponding averages.

import csv

with open("fidelities.csv", newline="") as f:
    fidelities = {int(r["concept_id"]): r for r in csv.DictReader(f)}
value = fidelities[0]["f1"]
f1 = float(value) if value else None
Downloads last month
689
Safetensors
Model size
0.2B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support