初始化项目,由ModelHub XC社区提供模型

Model: somosnlp-hackathon-2022/bertin-roberta-base-finetuning-esnli
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-06-25 17:44:00 +08:00
commit 587cbde2b6
15 changed files with 150649 additions and 0 deletions

27
.gitattributes vendored Normal file
View File

@@ -0,0 +1,27 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bin.* filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zstandard filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text

7
1_Pooling/config.json Normal file
View File

@@ -0,0 +1,7 @@
{
"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
}

178
README.md Normal file
View File

@@ -0,0 +1,178 @@
---
pipeline_tag: sentence-similarity
tags:
- sentence-transformers
- feature-extraction
- sentence-similarity
language:
- es
datasets:
- hackathon-pln-es/nli-es
widget:
- text: "A ver si nos tenemos que poner todos en huelga hasta cobrar lo que queramos."
- text: "La huelga es el método de lucha más eficaz para conseguir mejoras en el salario."
- text: "Tendremos que optar por hacer una huelga para cobrar lo que queremos."
- text: "Queda descartada la huelga aunque no cobremos lo que queramos."
---
# bertin-roberta-base-finetuning-esnli
This is a [sentence-transformers](https://www.SBERT.net) model trained on a
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.
Based around the siamese networks approach from [this paper](https://arxiv.org/pdf/1908.10084.pdf).
<!--- Describe your model here -->
You can see a demo for this model [here](https://huggingface.co/spaces/hackathon-pln-es/Sentence-Embedding-Bertin).
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).
## Usage (Sentence-Transformers)
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
```
pip install -U sentence-transformers
```
Then you can use the model like this:
```python
from sentence_transformers import SentenceTransformer
sentences = ["Este es un ejemplo", "Cada oración es transformada"]
model = SentenceTransformer('hackathon-pln-es/bertin-roberta-base-finetuning-esnli')
embeddings = model.encode(sentences)
print(embeddings)
```
## Usage (HuggingFace Transformers)
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.
```python
from transformers import AutoTokenizer, AutoModel
import torch
#Mean Pooling - Take attention mask into account for correct averaging
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
# Sentences we want sentence embeddings for
sentences = ['This is an example sentence', 'Each sentence is converted']
# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained('hackathon-pln-es/bertin-roberta-base-finetuning-esnli')
model = AutoModel.from_pretrained('hackathon-pln-es/bertin-roberta-base-finetuning-esnli')
# Tokenize sentences
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddings
with torch.no_grad():
model_output = model(**encoded_input)
# Perform pooling. In this case, mean pooling.
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
```
## Evaluation Results
<!--- Describe how your model was evaluated -->
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
| | [BETO STS](https://huggingface.co/espejelomar/sentece-embeddings-BETO) | BERTIN STS (this model) | Relative improvement |
|-------------------:|---------:|-----------:|---------------------:|
| cosine_pearson | 0.609803 | 0.683188 | +12.03 |
| cosine_spearman | 0.528776 | 0.615916 | +16.48 |
| euclidean_pearson | 0.590613 | 0.672601 | +13.88 |
| euclidean_spearman | 0.526529 | 0.611539 | +16.15 |
| manhattan_pearson | 0.589108 | 0.672040 | +14.08 |
| manhattan_spearman | 0.525910 | 0.610517 | +16.09 |
| dot_pearson | 0.544078 | 0.600517 | +10.37 |
| dot_spearman | 0.460427 | 0.521260 | +13.21 |
## Training
The model was trained with the parameters:
**Dataset**
We used a collection of datasets of Natural Language Inference as training data:
- [ESXNLI](https://raw.githubusercontent.com/artetxem/esxnli/master/esxnli.tsv), only the part in spanish
- [SNLI](https://nlp.stanford.edu/projects/snli/), automatically translated
- [MultiNLI](https://cims.nyu.edu/~sbowman/multinli/), automatically translated
The whole dataset used is available [here](https://huggingface.co/datasets/hackathon-pln-es/nli-es).
Here we leave the trick we used to increase the amount of data for training here:
```
for row in reader:
if row['language'] == 'es':
sent1 = row['sentence1'].strip()
sent2 = row['sentence2'].strip()
add_to_samples(sent1, sent2, row['gold_label'])
add_to_samples(sent2, sent1, row['gold_label']) #Also add the opposite
```
**DataLoader**:
`sentence_transformers.datasets.NoDuplicatesDataLoader.NoDuplicatesDataLoader`
of length 1818 with parameters:
```
{'batch_size': 64}
```
**Loss**:
`sentence_transformers.losses.MultipleNegativesRankingLoss.MultipleNegativesRankingLoss` with parameters:
```
{'scale': 20.0, 'similarity_fct': 'cos_sim'}
```
Parameters of the fit()-Method:
```
{
"epochs": 10,
"evaluation_steps": 0,
"evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
"max_grad_norm": 1,
"optimizer_class": "<class 'transformers.optimization.AdamW'>",
"optimizer_params": {
"lr": 2e-05
},
"scheduler": "WarmupLinear",
"steps_per_epoch": null,
"warmup_steps": 909,
"weight_decay": 0.01
}
```
## Full Model Architecture
```
SentenceTransformer(
(0): Transformer({'max_seq_length': 514, 'do_lower_case': False}) with Transformer model: RobertaModel
(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})
)
```
## Authors
[Anibal Pérez](https://huggingface.co/Anarpego),
[Emilio Tomás Ariza](https://huggingface.co/medardodt),
[Lautaro Gesuelli](https://huggingface.co/Lgesuelli) y
[Mauricio Mazuecos](https://huggingface.co/mmazuecos).

28
config.json Normal file
View File

@@ -0,0 +1,28 @@
{
"_name_or_path": "bertin-project/bertin-roberta-base-spanish",
"architectures": [
"RobertaModel"
],
"attention_probs_dropout_prob": 0.1,
"bos_token_id": 0,
"classifier_dropout": null,
"eos_token_id": 2,
"gradient_checkpointing": false,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 768,
"initializer_range": 0.02,
"intermediate_size": 3072,
"layer_norm_eps": 1e-05,
"max_position_embeddings": 514,
"model_type": "roberta",
"num_attention_heads": 12,
"num_hidden_layers": 12,
"pad_token_id": 1,
"position_embedding_type": "absolute",
"torch_dtype": "float32",
"transformers_version": "4.17.0",
"type_vocab_size": 1,
"use_cache": true,
"vocab_size": 50265
}

View File

@@ -0,0 +1,7 @@
{
"__version__": {
"sentence_transformers": "2.2.0",
"transformers": "4.17.0",
"pytorch": "1.10.2"
}
}

View File

@@ -0,0 +1,11 @@
epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman
0,-1,0.6831884913062921,0.6159162222541099,0.6726005233636806,0.6115392058863335,0.6720401096771059,0.6105173097665644,0.6005167896896939,0.5212600492097655
1,-1,0.6706171111332979,0.6008531510212776,0.6565912032452935,0.5949169636344843,0.6555142909342582,0.5935398433843475,0.5765151466955727,0.49637768476198035
2,-1,0.6763825624896551,0.6087882606796842,0.6627392144068636,0.6053590389366899,0.6612759395162868,0.6030838801547247,0.5826990236692152,0.5088888493638298
3,-1,0.66260616452593,0.5913823777186296,0.6469213245153994,0.5891702556310773,0.6449471942861446,0.5872578064093931,0.5818409585899842,0.5052892808258618
4,-1,0.6566925461921814,0.5871384798501856,0.6379456634562074,0.5819500400390282,0.6356299181697714,0.5793092883148608,0.5725533633222645,0.5005210619710372
5,-1,0.6560126958746472,0.584645192515697,0.6375859060277993,0.5799601798248812,0.6358427415811263,0.578232849404072,0.5777523875165609,0.5017760148916008
6,-1,0.6503433461367746,0.578081436343585,0.6326739453456565,0.5758382504320848,0.6308846572628577,0.5745397200941126,0.571361965152683,0.49444579046714365
7,-1,0.6511867735121081,0.5769374865250576,0.6323147897935092,0.5744373103224324,0.6309669803317294,0.573106665075477,0.57342064744336,0.4975609366385161
8,-1,0.6506119610377241,0.5781030546060674,0.6326539782626099,0.5757848865607669,0.6310415147465013,0.5743098307522757,0.5723862516745356,0.49789660206491654
9,-1,0.6488271901388144,0.5782767677139244,0.6287620409812228,0.5742694918130841,0.6272343282453402,0.5729337473833224,0.5685335534384852,0.4968351056062509
1 epoch steps cosine_pearson cosine_spearman euclidean_pearson euclidean_spearman manhattan_pearson manhattan_spearman dot_pearson dot_spearman
2 0 -1 0.6831884913062921 0.6159162222541099 0.6726005233636806 0.6115392058863335 0.6720401096771059 0.6105173097665644 0.6005167896896939 0.5212600492097655
3 1 -1 0.6706171111332979 0.6008531510212776 0.6565912032452935 0.5949169636344843 0.6555142909342582 0.5935398433843475 0.5765151466955727 0.49637768476198035
4 2 -1 0.6763825624896551 0.6087882606796842 0.6627392144068636 0.6053590389366899 0.6612759395162868 0.6030838801547247 0.5826990236692152 0.5088888493638298
5 3 -1 0.66260616452593 0.5913823777186296 0.6469213245153994 0.5891702556310773 0.6449471942861446 0.5872578064093931 0.5818409585899842 0.5052892808258618
6 4 -1 0.6566925461921814 0.5871384798501856 0.6379456634562074 0.5819500400390282 0.6356299181697714 0.5793092883148608 0.5725533633222645 0.5005210619710372
7 5 -1 0.6560126958746472 0.584645192515697 0.6375859060277993 0.5799601798248812 0.6358427415811263 0.578232849404072 0.5777523875165609 0.5017760148916008
8 6 -1 0.6503433461367746 0.578081436343585 0.6326739453456565 0.5758382504320848 0.6308846572628577 0.5745397200941126 0.571361965152683 0.49444579046714365
9 7 -1 0.6511867735121081 0.5769374865250576 0.6323147897935092 0.5744373103224324 0.6309669803317294 0.573106665075477 0.57342064744336 0.4975609366385161
10 8 -1 0.6506119610377241 0.5781030546060674 0.6326539782626099 0.5757848865607669 0.6310415147465013 0.5743098307522757 0.5723862516745356 0.49789660206491654
11 9 -1 0.6488271901388144 0.5782767677139244 0.6287620409812228 0.5742694918130841 0.6272343282453402 0.5729337473833224 0.5685335534384852 0.4968351056062509

1
loss_digest.json Normal file

File diff suppressed because one or more lines are too long

50005
merges.txt Normal file

File diff suppressed because it is too large Load Diff

14
modules.json Normal file
View File

@@ -0,0 +1,14 @@
[
{
"idx": 0,
"name": "0",
"path": "",
"type": "sentence_transformers.models.Transformer"
},
{
"idx": 1,
"name": "1",
"path": "1_Pooling",
"type": "sentence_transformers.models.Pooling"
}
]

3
pytorch_model.bin Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:eaff1c454271166e40db8096964f269f9b5de9fad5e056c455e5de9be3404ba9
size 498664817

View File

@@ -0,0 +1,4 @@
{
"max_seq_length": 514,
"do_lower_case": false
}

1
special_tokens_map.json Normal file
View File

@@ -0,0 +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}}

100361
tokenizer.json Normal file

File diff suppressed because it is too large Load Diff

1
tokenizer_config.json Normal file
View File

@@ -0,0 +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": "bertin-project/bertin-roberta-base-spanish", "tokenizer_class": "RobertaTokenizer"}

1
vocab.json Normal file

File diff suppressed because one or more lines are too long