Update README.md
Browse files
README.md
CHANGED
@@ -1,17 +1,33 @@
|
|
1 |
---
|
|
|
|
|
|
|
2 |
pipeline_tag: sentence-similarity
|
3 |
tags:
|
4 |
- sentence-transformers
|
5 |
-
- feature-extraction
|
6 |
- sentence-similarity
|
7 |
- transformers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
---
|
9 |
|
10 |
-
#
|
11 |
|
12 |
This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 1024 dimensional dense vector space and can be used for tasks like clustering or semantic search.
|
13 |
-
|
14 |
-
|
15 |
|
16 |
## Usage (Sentence-Transformers)
|
17 |
|
@@ -25,9 +41,9 @@ Then you can use the model like this:
|
|
25 |
|
26 |
```python
|
27 |
from sentence_transformers import SentenceTransformer
|
28 |
-
sentences = ["
|
29 |
|
30 |
-
model = SentenceTransformer('
|
31 |
embeddings = model.encode(sentences)
|
32 |
print(embeddings)
|
33 |
```
|
@@ -35,7 +51,7 @@ print(embeddings)
|
|
35 |
|
36 |
|
37 |
## Usage (HuggingFace Transformers)
|
38 |
-
|
39 |
|
40 |
```python
|
41 |
from transformers import AutoTokenizer, AutoModel
|
@@ -53,8 +69,8 @@ def mean_pooling(model_output, attention_mask):
|
|
53 |
sentences = ['This is an example sentence', 'Each sentence is converted']
|
54 |
|
55 |
# Load model from HuggingFace Hub
|
56 |
-
tokenizer = AutoTokenizer.from_pretrained('
|
57 |
-
model = AutoModel.from_pretrained('
|
58 |
|
59 |
# Tokenize sentences
|
60 |
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
@@ -71,55 +87,52 @@ print(sentence_embeddings)
|
|
71 |
```
|
72 |
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
## Training
|
83 |
-
The model was trained with the parameters:
|
84 |
-
|
85 |
-
**DataLoader**:
|
86 |
|
87 |
-
|
88 |
-
```
|
89 |
-
{'batch_size': 5, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
|
90 |
-
```
|
91 |
|
92 |
-
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
Parameters of the fit()-Method:
|
97 |
-
```
|
98 |
-
{
|
99 |
-
"epochs": 8,
|
100 |
-
"evaluation_steps": 0,
|
101 |
-
"evaluator": "NoneType",
|
102 |
-
"max_grad_norm": 1,
|
103 |
-
"optimizer_class": "<class 'transformers.optimization.AdamW'>",
|
104 |
-
"optimizer_params": {
|
105 |
-
"lr": 1e-05
|
106 |
-
},
|
107 |
-
"scheduler": "WarmupLinear",
|
108 |
-
"steps_per_epoch": null,
|
109 |
-
"warmup_steps": 2760,
|
110 |
-
"weight_decay": 0.01
|
111 |
-
}
|
112 |
-
```
|
113 |
|
114 |
|
115 |
## Full Model Architecture
|
116 |
```
|
117 |
SentenceTransformer(
|
118 |
-
(0): Transformer({'max_seq_length':
|
119 |
-
(1): Pooling({'word_embedding_dimension':
|
120 |
)
|
121 |
```
|
122 |
|
123 |
## Citing & Authors
|
124 |
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language:
|
3 |
+
- pt
|
4 |
+
thumbnail: "Portugues SBERT for the Legal Domain"
|
5 |
pipeline_tag: sentence-similarity
|
6 |
tags:
|
7 |
- sentence-transformers
|
|
|
8 |
- sentence-similarity
|
9 |
- transformers
|
10 |
+
datasets:
|
11 |
+
- assin
|
12 |
+
- assin2
|
13 |
+
- stsb_multi_mt
|
14 |
+
|
15 |
+
widget:
|
16 |
+
- source_sentence: "O advogado apresentou as provas ao juíz."
|
17 |
+
sentences:
|
18 |
+
- "O juíz leu as provas."
|
19 |
+
- "O juíz leu o recurso."
|
20 |
+
- "O juíz atirou uma pedra."
|
21 |
+
example_title: "Example 1"
|
22 |
+
metrics:
|
23 |
+
- bleu
|
24 |
---
|
25 |
|
26 |
+
# rufimelo/Legal-SBERTimbau-sts-large-ma
|
27 |
|
28 |
This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 1024 dimensional dense vector space and can be used for tasks like clustering or semantic search.
|
29 |
+
rufimelo/Legal-SBERTimbau-sts-large-ma is based on Legal-BERTimbau-large which derives from [BERTimbau](https://huggingface.co/neuralmind/bert-large-portuguese-cased) alrge.
|
30 |
+
It is adapted to the Portuguese legal domain and trained for STS on portuguese datasets.
|
31 |
|
32 |
## Usage (Sentence-Transformers)
|
33 |
|
|
|
41 |
|
42 |
```python
|
43 |
from sentence_transformers import SentenceTransformer
|
44 |
+
sentences = ["Isto é um exemplo", "Isto é um outro exemplo"]
|
45 |
|
46 |
+
model = SentenceTransformer('rufimelo/Legal-SBERTimbau-sts-large-ma')
|
47 |
embeddings = model.encode(sentences)
|
48 |
print(embeddings)
|
49 |
```
|
|
|
51 |
|
52 |
|
53 |
## Usage (HuggingFace Transformers)
|
54 |
+
|
55 |
|
56 |
```python
|
57 |
from transformers import AutoTokenizer, AutoModel
|
|
|
69 |
sentences = ['This is an example sentence', 'Each sentence is converted']
|
70 |
|
71 |
# Load model from HuggingFace Hub
|
72 |
+
tokenizer = AutoTokenizer.from_pretrained('rufimelo/Legal-SBERTimbau-sts-large-ma')
|
73 |
+
model = AutoModel.from_pretrained('rufimelo/Legal-SBERTimbau-sts-large-ma')
|
74 |
|
75 |
# Tokenize sentences
|
76 |
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
|
|
87 |
```
|
88 |
|
89 |
|
90 |
+
## Evaluation Results STS
|
91 |
+
|
92 |
+
| Model| Assin | Assin2|stsb_multi_mt pt|
|
93 |
+
| ---------------------------------------- | ---------- | ---------- |---------- |
|
94 |
+
| Legal-SBERTimbau-sts-base| 0.71457| 0.73545 | |
|
95 |
+
| Legal-SBERTimbau-sts-base-ma| 0.74874 | 0.79532|0.82254 |
|
96 |
+
| Legal-SBERTimbau-sts-base-ma-v2| 0.75481 | 0.80262|0.82178|
|
97 |
+
| Legal-SBERTimbau-sts-large| 0.76629| 0.82357 | |
|
98 |
+
| Legal-SBERTimbau-sts-large-v2| 0.76299 | 0.81121|0.81726 |
|
99 |
+
| Legal-SBERTimbau-sts-large-ma| 0.76195| 0.81622 | 0.82608|
|
100 |
+
| Legal-SBERTimbau-sts-large-ma-v2| 0.7836| 0.8462| 0.8261|
|
101 |
+
| Legal-SBERTimbau-sts-large-ma-v3| 0.7749| 0.8470| 0.8364|
|
102 |
+
| ---------------------------------------- | ---------- |---------- |---------- |
|
103 |
+
| BERTimbau base Fine-tuned for STS|0.78455 | 0.80626|0.82841|
|
104 |
+
| BERTimbau large Fine-tuned for STS|0.78193 | 0.81758|0.83784|
|
105 |
+
| ---------------------------------------- | ---------- |---------- |---------- |
|
106 |
+
| paraphrase-multilingual-mpnet-base-v2| 0.71457| 0.79831 |0.83999 |
|
107 |
+
| paraphrase-multilingual-mpnet-base-v2 Fine-tuned with assin(s)| 0.77641|0.79831 |0.84575 |
|
108 |
## Training
|
|
|
|
|
|
|
109 |
|
110 |
+
rufimelo/Legal-SBERTimbau-sts-large-ma is based on Legal-BERTimbau-largewhich derives from [BERTimbau](https://huggingface.co/neuralmind/bert-large-portuguese-cased) large.
|
|
|
|
|
|
|
111 |
|
112 |
+
Firstly, due to the lack of portuguese datasets, it was trained using multilingual knowledge distillation. For the Multilingual Knowledge Distillation process, the teacher model was 'sentence-transformers/stsb-roberta-large', the supposed supported language as English and the language to learn was portuguese.
|
113 |
|
114 |
+
It was trained for Semantic Textual Similarity, being submitted to a fine tuning stage with the [assin](https://huggingface.co/datasets/assin), [assin2](https://huggingface.co/datasets/assin2) and [stsb_multi_mt pt](https://huggingface.co/datasets/stsb_multi_mt) datasets. (batch 8, 5 epochs 'lr': 1e-5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
|
117 |
## Full Model Architecture
|
118 |
```
|
119 |
SentenceTransformer(
|
120 |
+
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: BertModel
|
121 |
+
(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, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False})
|
122 |
)
|
123 |
```
|
124 |
|
125 |
## Citing & Authors
|
126 |
|
127 |
+
If you use this work, please cite BERTimbau's work:
|
128 |
+
|
129 |
+
```bibtex
|
130 |
+
@inproceedings{souza2020bertimbau,
|
131 |
+
author = {F{\'a}bio Souza and
|
132 |
+
Rodrigo Nogueira and
|
133 |
+
Roberto Lotufo},
|
134 |
+
title = {{BERT}imbau: pretrained {BERT} models for {B}razilian {P}ortuguese},
|
135 |
+
booktitle = {9th Brazilian Conference on Intelligent Systems, {BRACIS}, Rio Grande do Sul, Brazil, October 20-23 (to appear)},
|
136 |
+
year = {2020}
|
137 |
+
}
|
138 |
+
```
|