Text Classification
Transformers
Safetensors
modernbert
feature-extraction
eurovoc
multi-label
multilingual
mmbert
text-embeddings-inference
Instructions to use EuropeanParliament/EuroVoc with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use EuropeanParliament/EuroVoc with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="EuropeanParliament/EuroVoc")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("EuropeanParliament/EuroVoc") model = AutoModel.from_pretrained("EuropeanParliament/EuroVoc", device_map="auto") - Notebooks
- Google Colab
- Kaggle
predict.py: skip content-free input (empty/zero-width/emoji) to prevent unrelated tags on empty input
Browse files- predict.py +3 -1
predict.py
CHANGED
|
@@ -27,7 +27,9 @@ def load():
|
|
| 27 |
|
| 28 |
|
| 29 |
def predict(text, thresh=CONCEPT_THRESHOLD, model=None):
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
b = tok(text, truncation=True, max_length=2048, return_tensors="pt")
|
| 32 |
with torch.no_grad():
|
| 33 |
h = enc(**b).last_hidden_state
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
def predict(text, thresh=CONCEPT_THRESHOLD, model=None):
|
| 30 |
+
if not any(c.isalnum() for c in text): # no letters/digits in any script: only special tokens would
|
| 31 |
+
return [] # be pooled, which yields hundreds of spurious tags. Skip it.
|
| 32 |
+
tok, enc, head, mlb, names = model or load() # reloads per call; pass model= in a loop
|
| 33 |
b = tok(text, truncation=True, max_length=2048, return_tensors="pt")
|
| 34 |
with torch.no_grad():
|
| 35 |
h = enc(**b).last_hidden_state
|