Text Classification
Transformers
ONNX
Safetensors
Transformers.js
modernbert
topic-classification
domain-classification
web-classification
weborganizer
data-curation
pretraining-data
mmbert
text-embeddings-inference
Instructions to use Horizon-Labs/multilingual-web-topic-format-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Horizon-Labs/multilingual-web-topic-format-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="Horizon-Labs/multilingual-web-topic-format-base")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("Horizon-Labs/multilingual-web-topic-format-base") model = AutoModelForSequenceClassification.from_pretrained("Horizon-Labs/multilingual-web-topic-format-base", device_map="auto") - Transformers.js
How to use Horizon-Labs/multilingual-web-topic-format-base with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('text-classification', 'Horizon-Labs/multilingual-web-topic-format-base'); - Notebooks
- Google Colab
- Kaggle
Download code/webtax/eval_webtax.py from Horizon-Labs/multilingual-web-topic-format-base: direct link, hf CLI and curl.
- Browser
- Download file 2.15 kB
-
https://huggingface.co/Horizon-Labs/multilingual-web-topic-format-base/resolve/main/code/webtax/eval_webtax.py
- Command line
-
hf download hf://Horizon-Labs/multilingual-web-topic-format-base/code/webtax/eval_webtax.py
-
curl -L -o eval_webtax.py https://huggingface.co/Horizon-Labs/multilingual-web-topic-format-base/resolve/main/code/webtax/eval_webtax.py
2.15 kB
| """Evaluate a topic & format classifier (48 sigmoid outputs topic_* / format_*) on webtax/evals: en_llama405b (WebOrganizer Llama-3.1-405B | |
| labels, English) and fw2_judged (65 languages, Gemma-4-31B judge). python webtax/eval_webtax.py --models A --out R.json""" | |
| import argparse, json, os, sys | |
| import numpy as np, pandas as pd, torch | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| HERE = os.path.dirname(os.path.abspath(__file__)); sys.path.insert(0, HERE) | |
| from metrics import acc_f1 | |
| ap = argparse.ArgumentParser(); ap.add_argument("--models", required=True); ap.add_argument("--out", required=True); args = ap.parse_args() | |
| EV = {n: pd.read_parquet(os.path.join(HERE, "evals", f"{n}.parquet")) for n in ("en_llama405b", "fw2_judged")} | |
| res = json.load(open(args.out)) if os.path.exists(args.out) else {} | |
| for spec in args.models.split(","): | |
| tok = AutoTokenizer.from_pretrained(spec); m = AutoModelForSequenceClassification.from_pretrained(spec, torch_dtype=torch.bfloat16).cuda().eval() | |
| labels = [m.config.id2label[i] for i in range(m.config.num_labels)] | |
| ti = [i for i, l in enumerate(labels) if l.startswith("topic_")]; fi = [i for i, l in enumerate(labels) if l.startswith("format_")] | |
| r = {} | |
| for name, df in EV.items(): | |
| P = np.zeros((len(df), len(labels))); order = np.argsort(df.text.str.len().values) | |
| with torch.no_grad(): | |
| for s in range(0, len(df), 32): | |
| b = order[s:s + 32]; e = tok(df.text.iloc[b].tolist(), truncation=True, max_length=512, padding=True, return_tensors="pt") | |
| P[b] = m(input_ids=e["input_ids"].cuda(), attention_mask=e["attention_mask"].cuda()).logits.float().cpu().numpy() | |
| pt = np.array([labels[ti[j]][6:] for j in P[:, ti].argmax(1)]); pf = np.array([labels[fi[j]][7:] for j in P[:, fi].argmax(1)]) | |
| r[name] = dict(topic=acc_f1(pt, df.ref_topic.values, df.lang.values), format=acc_f1(pf, df.ref_format.values, df.lang.values)) | |
| print(spec, name, {k: {kk: round(vv, 4) for kk, vv in v.items()} for k, v in r[name].items()}, flush=True) | |
| res[spec] = r; json.dump(res, open(args.out, "w"), indent=1) | |