Downloads · 30 days
46
12% of all-time downloads
giacomorossojakala/paraphrase-multilingual-mpnet-base-v2-eutekne-filtri-materia-lv1
paraphrase-multilingual-mpnet-base-v2-eutekne-filtri-materia-lv1 is a sentence similarity model from giacomorossojakala. Use it when you need a score for how close two texts are.
This model is a fine-tuned paraphrase-multilingual-mpnet-base-v2 for a multi-label text classification on Eutekne domandefitlrimaterie train dataset.
Downloads · 30 days
46
12% of all-time downloads
All-time downloads
383
Public
Parameters
278M
1.1 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors1.1 GB · 98%
From the Hugging Face model README
This model is a fine-tuned paraphrase-multilingual-mpnet-base-v2 for a multi-label text classification on Eutekne domande_fitlri_materie train dataset.
The multi-label text classification task is faced as a retrieval problem: given a query and a list of description of labels, they are encoded with the same ambedder and the neareast neighbors are retrieved.
This model is intended for classifying legal questions into categories. These categories are based on the Eutekne domande_fitlri_materie.
This model is a finetuning of: paraphrase-multilingual-mpnet-base-v2
{
"train_samples": 4044,
"val_samples": 867,
"test_samples": 867
}
{
"batch_size": 16,
"learning_rate": 2e-05,
"num_epochs": 30,
"max_length": 256
}
| | validation_results | test_results |
|:-------------|---------------------:|---------------:|
| accuracy_1 | 0.745098 | 0.733564 |
| accuracy_3 | 0.906574 | 0.890427 |
| accuracy_5 | 0.944637 | 0.934256 |
| accuracy_10 | 0.980392 | 0.966551 |
| precision_1 | 0.745098 | 0.733564 |
| precision_3 | 0.381392 | 0.365244 |
| precision_5 | 0.25098 | 0.242676 |
| precision_10 | 0.135755 | 0.133679 |
| recall_1 | 0.214194 | 0.215273 |
| recall_3 | 0.29301 | 0.287529 |
| recall_5 | 0.314612 | 0.310036 |
| recall_10 | 0.334751 | 0.332891 |
| f1_1 | 0.311139 | 0.309736 |
| f1_3 | 0.301874 | 0.290957 |
| f1_5 | 0.254062 | 0.246131 |
| f1_10 | 0.178015 | 0.174662 |
| mrr_1 | 0.745098 | 0.733564 |
| mrr_3 | 0.8193 | 0.804306 |
| mrr_5 | 0.828124 | 0.814456 |
| mrr_10 | 0.832849 | 0.818709 |
| r_precision | 0.303022 | 0.300296 |
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
repo_id = f"giacomorossojakala/paraphrase-multilingual-mpnet-base-v2-eutekne-filtri-materia-lv1"
model = SentenceTransformer(repo_id, device=device)
downloaded_path = hf_hub_download(repo_id=HF_REPO_ID, filename="label_description.json", token=HF_TOKEN)
print(f"File downloaded to: /root/.cache/huggingface/hub/models--giacomorossojakala--paraphrase-multilingual-mpnet-base-v2-eutekne-filtri-materia-lv1/snapshots/b70b25241cea5f87305b6685d896eb81041fc649/label_description.json")
label_descriptions = json.load(open(downloaded_path, "r"))
# Get predictions
custom_text = "acquista casa nel 2025 lavori ristrutturazione ma andrà ad abitare nel 2026, detrazioni 50%?"
def classify_text(text, model, label_descriptions, top_k=5):
'''
Classify a text by computing similarity with all label descriptions.
Args:
text: Input text to classify
model: Trained SentenceTransformer model
label_descriptions: Dict mapping label codes to descriptions
top_k: Number of top predictions to return
Returns:
List of (label, similarity_score) tuples, sorted by score (descending)
'''
# Get label list and descriptions
label_list = sorted(list(label_descriptions.keys()))
label_texts = [label_descriptions[label] for label in label_list]
# Encode question and all labels
question_embedding = model.encode(text, convert_to_numpy=True)
label_embeddings = model.encode(label_texts, convert_to_numpy=True, show_progress_bar=False)
# Compute cosine similarities
similarities = cosine_similarity([question_embedding], label_embeddings)[0]
# Get top-k
top_k_indices = np.argsort(similarities)[::-1][:top_k]
predictions = [(label_list[idx], similarities[idx]) for idx in top_k_indices]
return predictions
predictions = classify_text(custom_text, model, label_descriptions, top_k=5)