Views
No views yet
1{
2 "train_samples": 4044,
3 "val_samples": 867,
4 "test_samples": 867
5}1{
2 "batch_size": 16,
3 "learning_rate": 2e-05,
4 "num_epochs": 30,
5 "max_length": 256
6}1| | validation_results | test_results |
2|:-------------|---------------------:|---------------:|
3| accuracy_1 | 0.681661 | 0.663206 |
4| accuracy_3 | 0.83045 | 0.817762 |
5| accuracy_5 | 0.889273 | 0.861592 |
6| accuracy_10 | 0.929642 | 0.916955 |
7| precision_1 | 0.681661 | 0.663206 |
8| precision_3 | 0.532488 | 0.517878 |
9| precision_5 | 0.396078 | 0.376471 |
10| precision_10 | 0.233449 | 0.227682 |
11| recall_1 | 0.195662 | 0.199829 |
12| recall_3 | 0.422025 | 0.41992 |
13| recall_5 | 0.495023 | 0.479549 |
14| recall_10 | 0.555928 | 0.547916 |
15| f1_1 | 0.284624 | 0.286278 |
16| f1_3 | 0.434482 | 0.426173 |
17| f1_5 | 0.405207 | 0.386656 |
18| f1_10 | 0.305581 | 0.297389 |
19| mrr_1 | 0.681661 | 0.663206 |
20| mrr_3 | 0.749519 | 0.731642 |
21| mrr_5 | 0.76313 | 0.741619 |
22| mrr_10 | 0.768567 | 0.749094 |
23| r_precision | 0.475959 | 0.468916 |1from sentence_transformers import SentenceTransformer
2from sklearn.metrics.pairwise import cosine_similarity
3
4repo_id = f"giacomorossojakala/paraphrase-multilingual-mpnet-base-v2-eutekne-filtri-materia-lv1-2-desc-cascata"
5model = SentenceTransformer(repo_id, device=device)
6
7downloaded_path = hf_hub_download(repo_id=HF_REPO_ID, filename="label_description.json", token=HF_TOKEN)
8label_descriptions = json.load(open(downloaded_path, "r"))
9
10# Get predictions
11custom_text = "acquista casa nel 2025 lavori ristrutturazione ma andrà ad abitare nel 2026, detrazioni 50%?"
12
13def classify_text(text, model, label_descriptions, top_k=5):
14 '''
15 Classify a text by computing similarity with all label descriptions.
16
17 Args:
18 text: Input text to classify
19 model: Trained SentenceTransformer model
20 label_descriptions: Dict mapping label codes to descriptions
21 top_k: Number of top predictions to return
22
23 Returns:
24 List of (label, similarity_score) tuples, sorted by score (descending)
25 '''
26
27 # Get label list and descriptions
28 label_list = sorted(list(label_descriptions.keys()))
29 label_texts = [label_descriptions[label] for label in label_list]
30
31 # Encode question and all labels
32 question_embedding = model.encode(text, convert_to_numpy=True)
33 label_embeddings = model.encode(label_texts, convert_to_numpy=True, show_progress_bar=False)
34
35 # Compute cosine similarities
36 similarities = cosine_similarity([question_embedding], label_embeddings)[0]
37
38 # Get top-k
39 top_k_indices = np.argsort(similarities)[::-1][:top_k]
40 predictions = [(label_list[idx], similarities[idx]) for idx in top_k_indices]
41
42 return predictions
43
44
45
46predictions = classify_text(custom_text, model, label_descriptions, top_k=5)