Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
datasets:
|
4 |
+
- mteb/sts12-sts
|
5 |
+
metrics:
|
6 |
+
- accuracy
|
7 |
+
base_model:
|
8 |
+
- sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
|
9 |
+
library_name: transformers
|
10 |
+
---
|
11 |
+
Model Description
|
12 |
+
This model is a fine-tuned version of sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 for sentence similarity tasks. It was trained on the mteb/stsbenchmark-sts dataset to evaluate the similarity between sentence pairs.
|
13 |
+
|
14 |
+
Model Type: Sequence Classification (Regression)
|
15 |
+
Pre-trained Model: sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
|
16 |
+
Fine-Tuning Dataset: mteb/stsbenchmark-sts
|
17 |
+
Task: Sentence similarity (regression)
|
18 |
+
Training Details
|
19 |
+
Training Objective: To predict the similarity score between pairs of sentences.
|
20 |
+
Training Data: mteb/stsbenchmark-sts, which contains sentence pairs with similarity scores.
|
21 |
+
Number of Labels: 1 (regression)
|
22 |
+
Epochs: 2
|
23 |
+
Batch Size: 8
|
24 |
+
Learning Rate: 2e-5
|
25 |
+
Weight Decay: 0.01
|
26 |
+
Evaluation
|
27 |
+
The model was evaluated using Pearson correlation on the validation set of the mteb/stsbenchmark-sts dataset. Results indicate how well the model predicts similarity scores between sentence pairs.
|
28 |
+
|
29 |
+
Usage
|
30 |
+
To use this model for sentence similarity, follow these steps:
|
31 |
+
|
32 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
33 |
+
|
34 |
+
# Load the fine-tuned model
|
35 |
+
|
36 |
+
|
37 |
+
model = AutoModelForSequenceClassification.from_pretrained("./paraphraser_model")
|
38 |
+
tokenizer = AutoTokenizer.from_pretrained("./paraphraser_model")
|
39 |
+
|
40 |
+
sentences = ["The quick brown fox jumps over the lazy dog.", "A fast dark-colored fox leaps over a sleeping dog."]
|
41 |
+
encoded_input = tokenizer(sentences[0], sentences[1], return_tensors="pt", truncation=True, padding='max_length', max_length=128)
|
42 |
+
|
43 |
+
# Compute Similarity Score:
|
44 |
+
|
45 |
+
import torch
|
46 |
+
import torch.nn.functional as F
|
47 |
+
|
48 |
+
# Perform inference
|
49 |
+
with torch.no_grad():
|
50 |
+
model_output = model(**encoded_input)
|
51 |
+
logits = model_output.logits
|
52 |
+
similarity_score = F.sigmoid(logits).item()
|
53 |
+
|
54 |
+
print(f"Similarity score between the two sentences: {similarity_score}")
|
55 |
+
|
56 |
+
# Mean Pooling Function:
|
57 |
+
|
58 |
+
If using the model for generating sentence embeddings, you can use the following mean pooling function:
|
59 |
+
def mean_pooling(model_output, attention_mask):
|
60 |
+
token_embeddings = model_output[0] # First element of model_output contains the token embeddings
|
61 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).float()
|
62 |
+
sum_embeddings = torch.sum(token_embeddings * input_mask_expanded, dim=1)
|
63 |
+
sum_mask = torch.clamp(input_mask_expanded.sum(dim=1), min=1e-9)
|
64 |
+
return sum_embeddings / sum_mask
|
65 |
+
|
66 |
+
# Limitations
|
67 |
+
Domain Specificity: The model is fine-tuned on the mteb/stsbenchmark-sts dataset and may perform differently on other types of text or datasets.
|
68 |
+
Biases: As with any model trained on human language data, it may inherit and reflect biases present in the training data.
|
69 |
+
|
70 |
+
Future Work
|
71 |
+
Potential improvements include fine-tuning on additional datasets, experimenting with different architectures or hyperparameters, and incorporating additional training techniques to improve performance and robustness.
|
72 |
+
|
73 |
+
Citation
|
74 |
+
If you use this model in your research, please cite it as follows:
|
75 |
+
@inproceedings{your_paper,
|
76 |
+
title={Fine-Tuned Paraphrase-Multilingual-MiniLM-L12-v2 for Sentence Similarity},
|
77 |
+
author={Your Name},
|
78 |
+
year={2024},
|
79 |
+
publisher={Your Institution}
|
80 |
+
}
|
81 |
+
|
82 |
+
|
83 |
+
License
|
84 |
+
This model is licensed under the MIT License. See the LICENSE file for more information.
|