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/wo_fix.py from Horizon-Labs/multilingual-web-topic-format-base: direct link, hf CLI and curl.
- Browser
- Download file 1.74 kB
-
https://huggingface.co/Horizon-Labs/multilingual-web-topic-format-base/resolve/main/code/webtax/wo_fix.py
- Command line
-
hf download hf://Horizon-Labs/multilingual-web-topic-format-base/code/webtax/wo_fix.py
-
curl -L -o wo_fix.py https://huggingface.co/Horizon-Labs/multilingual-web-topic-format-base/resolve/main/code/webtax/wo_fix.py
1.74 kB
| """WebOrganizer's custom gte ('new') code under transformers 5: non-persistent buffers (position_ids, RoPE cos/sin caches) come out | |
| uninitialised (meta-device loading). Rebuild them after from_pretrained.""" | |
| import torch | |
| def fix_buffers(m): | |
| for mod in m.modules(): | |
| if hasattr(mod, "position_ids") and isinstance(getattr(mod, "position_ids"), torch.Tensor): | |
| n = mod.position_ids.shape[-1]; mod.position_ids = torch.arange(n, device=mod.position_ids.device).expand_as(mod.position_ids).clone() | |
| if hasattr(mod, "_set_cos_sin_cache"): | |
| dev = next((b.device for b in mod.buffers()), torch.device("cpu")) | |
| inv = getattr(mod, "inv_freq", None) | |
| if inv is not None and hasattr(mod, "base") and hasattr(mod, "dim"): | |
| mod.inv_freq = 1.0 / (mod.base ** (torch.arange(0, mod.dim, 2, device=dev).float() / mod.dim)) | |
| mod._set_cos_sin_cache(seq_len=getattr(mod, "max_seq_len_cached", getattr(mod, "max_position_embeddings", 8192)), device=dev, dtype=torch.float32) | |
| return m | |
| def _ext_mask(self, attention_mask, input_shape=None, device=None, dtype=None): | |
| """transformers 4.x ModuleUtilsMixin.get_extended_attention_mask (removed in 5): [bs, seq] -> additive [bs, 1, 1, seq] mask.""" | |
| dtype = dtype or next(self.parameters()).dtype | |
| ext = attention_mask[:, None, None, :] if attention_mask.dim() == 2 else attention_mask[:, None, :, :] | |
| ext = ext.to(dtype=dtype) | |
| return (1.0 - ext) * torch.finfo(dtype).min | |
| def patch(m): | |
| for mod in m.modules(): | |
| if type(mod).__name__ == "NewModel" and not hasattr(type(mod), "get_extended_attention_mask"): | |
| type(mod).get_extended_attention_mask = _ext_mask | |
| return fix_buffers(m) | |