espejelomar
commited on
Commit
•
7ba6e49
1
Parent(s):
caba8d1
Add new SentenceTransformer model.
Browse files- .gitattributes +1 -0
- 1_Pooling/config.json +7 -0
- README.md +177 -0
- config.json +28 -0
- config_sentence_transformers.json +7 -0
- merges.txt +0 -0
- modules.json +14 -0
- pytorch_model.bin +3 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +1 -0
- vocab.json +0 -0
.gitattributes
CHANGED
@@ -25,3 +25,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
pytorch_model.bin filter=lfs diff=lfs merge=lfs -text
|
1_Pooling/config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 768,
|
3 |
+
"pooling_mode_cls_token": false,
|
4 |
+
"pooling_mode_mean_tokens": true,
|
5 |
+
"pooling_mode_max_tokens": false,
|
6 |
+
"pooling_mode_mean_sqrt_len_tokens": false
|
7 |
+
}
|
README.md
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
pipeline_tag: sentence-similarity
|
3 |
+
tags:
|
4 |
+
- sentence-transformers
|
5 |
+
- feature-extraction
|
6 |
+
- sentence-similarity
|
7 |
+
language:
|
8 |
+
- es
|
9 |
+
datasets:
|
10 |
+
- hackathon-pln-es/nli-es
|
11 |
+
widget:
|
12 |
+
- text: "A ver si nos tenemos que poner todos en huelga hasta cobrar lo que queramos."
|
13 |
+
- text: "La huelga es el método de lucha más eficaz para conseguir mejoras en el salario."
|
14 |
+
- text: "Tendremos que optar por hacer una huelga para cobrar lo que queremos."
|
15 |
+
- text: "Queda descartada la huelga aunque no cobremos lo que queramos."
|
16 |
+
---
|
17 |
+
|
18 |
+
# bertin-roberta-base-finetuning-esnli
|
19 |
+
|
20 |
+
This is a [sentence-transformers](https://www.SBERT.net) model trained on a
|
21 |
+
collection of NLI tasks for Spanish. It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
|
22 |
+
|
23 |
+
Based around the siamese networks approach from [this paper](https://arxiv.org/pdf/1908.10084.pdf).
|
24 |
+
<!--- Describe your model here -->
|
25 |
+
|
26 |
+
You can see a demo for this model [here](https://huggingface.co/spaces/hackathon-pln-es/Sentence-Embedding-Bertin).
|
27 |
+
|
28 |
+
You can find our other model, **paraphrase-spanish-distilroberta** [here](https://huggingface.co/hackathon-pln-es/paraphrase-spanish-distilroberta) and its demo [here](https://huggingface.co/spaces/hackathon-pln-es/Paraphrase-Bertin).
|
29 |
+
|
30 |
+
## Usage (Sentence-Transformers)
|
31 |
+
|
32 |
+
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
33 |
+
|
34 |
+
```
|
35 |
+
pip install -U sentence-transformers
|
36 |
+
```
|
37 |
+
|
38 |
+
Then you can use the model like this:
|
39 |
+
|
40 |
+
```python
|
41 |
+
from sentence_transformers import SentenceTransformer
|
42 |
+
sentences = ["Este es un ejemplo", "Cada oración es transformada"]
|
43 |
+
|
44 |
+
model = SentenceTransformer('hackathon-pln-es/bertin-roberta-base-finetuning-esnli')
|
45 |
+
embeddings = model.encode(sentences)
|
46 |
+
print(embeddings)
|
47 |
+
```
|
48 |
+
|
49 |
+
## Usage (HuggingFace Transformers)
|
50 |
+
Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
|
51 |
+
|
52 |
+
```python
|
53 |
+
from transformers import AutoTokenizer, AutoModel
|
54 |
+
import torch
|
55 |
+
|
56 |
+
|
57 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
58 |
+
def mean_pooling(model_output, attention_mask):
|
59 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
60 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
61 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
62 |
+
|
63 |
+
|
64 |
+
# Sentences we want sentence embeddings for
|
65 |
+
sentences = ['This is an example sentence', 'Each sentence is converted']
|
66 |
+
|
67 |
+
# Load model from HuggingFace Hub
|
68 |
+
tokenizer = AutoTokenizer.from_pretrained('hackathon-pln-es/bertin-roberta-base-finetuning-esnli')
|
69 |
+
model = AutoModel.from_pretrained('hackathon-pln-es/bertin-roberta-base-finetuning-esnli')
|
70 |
+
|
71 |
+
# Tokenize sentences
|
72 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
73 |
+
|
74 |
+
# Compute token embeddings
|
75 |
+
with torch.no_grad():
|
76 |
+
model_output = model(**encoded_input)
|
77 |
+
|
78 |
+
# Perform pooling. In this case, mean pooling.
|
79 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
80 |
+
|
81 |
+
print("Sentence embeddings:")
|
82 |
+
print(sentence_embeddings)
|
83 |
+
```
|
84 |
+
|
85 |
+
|
86 |
+
## Evaluation Results
|
87 |
+
|
88 |
+
<!--- Describe how your model was evaluated -->
|
89 |
+
Our model was evaluated on the task of Semantic Textual Similarity using the [SemEval-2015 Task](https://alt.qcri.org/semeval2015/task2/) for [Spanish](http://alt.qcri.org/semeval2015/task2/data/uploads/sts2015-es-test.zip). We measure
|
90 |
+
|
91 |
+
| | [BETO STS](https://huggingface.co/espejelomar/sentece-embeddings-BETO) | BERTIN STS (this model) | Relative improvement |
|
92 |
+
|-------------------:|---------:|-----------:|---------------------:|
|
93 |
+
| cosine_pearson | 0.609803 | 0.683188 | +12.03 |
|
94 |
+
| cosine_spearman | 0.528776 | 0.615916 | +16.48 |
|
95 |
+
| euclidean_pearson | 0.590613 | 0.672601 | +13.88 |
|
96 |
+
| euclidean_spearman | 0.526529 | 0.611539 | +16.15 |
|
97 |
+
| manhattan_pearson | 0.589108 | 0.672040 | +14.08 |
|
98 |
+
| manhattan_spearman | 0.525910 | 0.610517 | +16.09 |
|
99 |
+
| dot_pearson | 0.544078 | 0.600517 | +10.37 |
|
100 |
+
| dot_spearman | 0.460427 | 0.521260 | +13.21 |
|
101 |
+
|
102 |
+
|
103 |
+
## Training
|
104 |
+
The model was trained with the parameters:
|
105 |
+
|
106 |
+
**Dataset**
|
107 |
+
|
108 |
+
We used a collection of datasets of Natural Language Inference as training data:
|
109 |
+
- [ESXNLI](https://raw.githubusercontent.com/artetxem/esxnli/master/esxnli.tsv), only the part in spanish
|
110 |
+
- [SNLI](https://nlp.stanford.edu/projects/snli/), automatically translated
|
111 |
+
- [MultiNLI](https://cims.nyu.edu/~sbowman/multinli/), automatically translated
|
112 |
+
|
113 |
+
The whole dataset used is available [here](https://huggingface.co/datasets/hackathon-pln-es/nli-es).
|
114 |
+
|
115 |
+
Here we leave the trick we used to increase the amount of data for training here:
|
116 |
+
```
|
117 |
+
for row in reader:
|
118 |
+
if row['language'] == 'es':
|
119 |
+
|
120 |
+
sent1 = row['sentence1'].strip()
|
121 |
+
sent2 = row['sentence2'].strip()
|
122 |
+
|
123 |
+
add_to_samples(sent1, sent2, row['gold_label'])
|
124 |
+
add_to_samples(sent2, sent1, row['gold_label']) #Also add the opposite
|
125 |
+
```
|
126 |
+
|
127 |
+
**DataLoader**:
|
128 |
+
|
129 |
+
`sentence_transformers.datasets.NoDuplicatesDataLoader.NoDuplicatesDataLoader`
|
130 |
+
of length 1818 with parameters:
|
131 |
+
```
|
132 |
+
{'batch_size': 64}
|
133 |
+
```
|
134 |
+
|
135 |
+
**Loss**:
|
136 |
+
|
137 |
+
`sentence_transformers.losses.MultipleNegativesRankingLoss.MultipleNegativesRankingLoss` with parameters:
|
138 |
+
```
|
139 |
+
{'scale': 20.0, 'similarity_fct': 'cos_sim'}
|
140 |
+
```
|
141 |
+
|
142 |
+
Parameters of the fit()-Method:
|
143 |
+
```
|
144 |
+
{
|
145 |
+
"epochs": 10,
|
146 |
+
"evaluation_steps": 0,
|
147 |
+
"evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
|
148 |
+
"max_grad_norm": 1,
|
149 |
+
"optimizer_class": "<class 'transformers.optimization.AdamW'>",
|
150 |
+
"optimizer_params": {
|
151 |
+
"lr": 2e-05
|
152 |
+
},
|
153 |
+
"scheduler": "WarmupLinear",
|
154 |
+
"steps_per_epoch": null,
|
155 |
+
"warmup_steps": 909,
|
156 |
+
"weight_decay": 0.01
|
157 |
+
}
|
158 |
+
```
|
159 |
+
|
160 |
+
|
161 |
+
## Full Model Architecture
|
162 |
+
```
|
163 |
+
SentenceTransformer(
|
164 |
+
(0): Transformer({'max_seq_length': 514, 'do_lower_case': False}) with Transformer model: RobertaModel
|
165 |
+
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
|
166 |
+
)
|
167 |
+
```
|
168 |
+
|
169 |
+
## Authors
|
170 |
+
|
171 |
+
[Anibal Pérez](https://huggingface.co/Anarpego),
|
172 |
+
|
173 |
+
[Emilio Tomás Ariza](https://huggingface.co/medardodt),
|
174 |
+
|
175 |
+
[Lautaro Gesuelli](https://huggingface.co/Lgesuelli) y
|
176 |
+
|
177 |
+
[Mauricio Mazuecos](https://huggingface.co/mmazuecos).
|
config.json
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "./hackathon-pln-es_bertin-roberta-base-finetuning-esnli/",
|
3 |
+
"architectures": [
|
4 |
+
"RobertaModel"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"bos_token_id": 0,
|
8 |
+
"classifier_dropout": null,
|
9 |
+
"eos_token_id": 2,
|
10 |
+
"gradient_checkpointing": false,
|
11 |
+
"hidden_act": "gelu",
|
12 |
+
"hidden_dropout_prob": 0.1,
|
13 |
+
"hidden_size": 768,
|
14 |
+
"initializer_range": 0.02,
|
15 |
+
"intermediate_size": 3072,
|
16 |
+
"layer_norm_eps": 1e-05,
|
17 |
+
"max_position_embeddings": 514,
|
18 |
+
"model_type": "roberta",
|
19 |
+
"num_attention_heads": 12,
|
20 |
+
"num_hidden_layers": 12,
|
21 |
+
"pad_token_id": 1,
|
22 |
+
"position_embedding_type": "absolute",
|
23 |
+
"torch_dtype": "float32",
|
24 |
+
"transformers_version": "4.19.2",
|
25 |
+
"type_vocab_size": 1,
|
26 |
+
"use_cache": true,
|
27 |
+
"vocab_size": 50265
|
28 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "2.2.0",
|
4 |
+
"transformers": "4.17.0",
|
5 |
+
"pytorch": "1.10.2"
|
6 |
+
}
|
7 |
+
}
|
merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
modules.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "0",
|
5 |
+
"path": "",
|
6 |
+
"type": "sentence_transformers.models.Transformer"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_Pooling",
|
12 |
+
"type": "sentence_transformers.models.Pooling"
|
13 |
+
}
|
14 |
+
]
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:56cb66330b3a5d995668381f0b2347cc8ddb67e27c60cefa75f1ce3e6f33b6f8
|
3 |
+
size 498649201
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 514,
|
3 |
+
"do_lower_case": false
|
4 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": false}}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"errors": "replace", "bos_token": "<s>", "eos_token": "</s>", "sep_token": "</s>", "cls_token": "<s>", "unk_token": "<unk>", "pad_token": "<pad>", "mask_token": "<mask>", "add_prefix_space": false, "trim_offsets": true, "special_tokens_map_file": null, "name_or_path": "./hackathon-pln-es_bertin-roberta-base-finetuning-esnli/", "tokenizer_class": "RobertaTokenizer"}
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|