Run this model with HF Jobs

Run Louvain/embed-4b-erb on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/Louvain/embed-4b-erb. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/Louvain/embed-4b-erb on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
embed-4b-erb / training /sample.py
scotty595's picture
Model card: what the model has seen, limits, measured difference; add training scripts
7b9a14b verified
Raw History Blame Contribute Delete
2.33 kB
"""
STEP 1 — THE PASSAGES A WORKSPACE WOULD TEACH ITS EMBEDDER FROM. Documents only: see the guarantee in
`common.py`. Stratified by source with square-root weights (Slack's 285k messages would otherwise drown Confluence's
5k pages), at most `--per-doc` passages from a document, the rest chosen at random, seeded.
uv run python sample.py --passages 30000 --out $SELF_TUNE_DATA/passages.jsonl [--exclude pool-doc-ids.txt] [--seed 215]
`--exclude` names document ids kept OUT of training (the held-out variant); ids only, never read as text.
"""
import argparse
import json
import math
import random
from common import corpus_documents, load_exclusions, passages, source_of
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--passages", type=int, default=30000)
ap.add_argument("--per-doc", type=int, default=2)
ap.add_argument("--min-chars", type=int, default=200)
ap.add_argument("--exclude", default="")
ap.add_argument("--seed", type=int, default=215)
ap.add_argument("--out", required=True)
a = ap.parse_args()
rng = random.Random(a.seed)
excluded = load_exclusions(a.exclude)
docs = {d: p for d, p in corpus_documents().items() if d not in excluded}
by_source = {}
for d, p in docs.items():
by_source.setdefault(source_of(p), []).append(d)
weights = {s: math.sqrt(len(ids)) for s, ids in by_source.items()}
total = sum(weights.values())
out, counts = [], {}
for source, ids in sorted(by_source.items()):
want = round(a.passages * weights[source] / total)
rng.shuffle(ids)
got = 0
for d in ids:
if got >= want:
break
chunks = [c for c in passages(docs[d]) if len(c) >= a.min_chars]
rng.shuffle(chunks)
for i, text in enumerate(chunks[: a.per_doc]):
out.append({"pid": f"{d}#{i}", "doc": d, "source": source, "text": text})
got += 1
counts[source] = got
rng.shuffle(out)
with open(a.out, "w", encoding="utf-8") as f:
for row in out:
f.write(json.dumps(row, ensure_ascii=False) + "\n")
print(json.dumps({"passages": len(out), "documents": len({r["doc"] for r in out}), "excluded": len(excluded), "by_source": counts}))
if __name__ == "__main__":
main()