Update README.md
Browse files
README.md
CHANGED
@@ -1,17 +1,48 @@
|
|
|
|
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 768 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 +56,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,23 +66,26 @@ print(embeddings)
|
|
35 |
|
36 |
|
37 |
## Usage (HuggingFace Transformers)
|
38 |
-
|
39 |
|
40 |
```python
|
41 |
from transformers import AutoTokenizer, AutoModel
|
42 |
import torch
|
43 |
|
44 |
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
47 |
|
48 |
|
49 |
# Sentences we want sentence embeddings for
|
50 |
sentences = ['This is an example sentence', 'Each sentence is converted']
|
51 |
|
52 |
# Load model from HuggingFace Hub
|
53 |
-
tokenizer = AutoTokenizer.from_pretrained('
|
54 |
-
model = AutoModel.from_pretrained('
|
55 |
|
56 |
# Tokenize sentences
|
57 |
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
@@ -60,63 +94,62 @@ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tenso
|
|
60 |
with torch.no_grad():
|
61 |
model_output = model(**encoded_input)
|
62 |
|
63 |
-
# Perform pooling. In this case,
|
64 |
-
sentence_embeddings =
|
65 |
|
66 |
print("Sentence embeddings:")
|
67 |
print(sentence_embeddings)
|
68 |
```
|
69 |
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
## Training
|
80 |
-
The model was trained with the parameters:
|
81 |
|
82 |
-
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
{'batch_size': 8, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
|
87 |
-
```
|
88 |
-
|
89 |
-
**Loss**:
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
Parameters of the fit()-Method:
|
94 |
-
```
|
95 |
-
{
|
96 |
-
"epochs": 5,
|
97 |
-
"evaluation_steps": 0,
|
98 |
-
"evaluator": "NoneType",
|
99 |
-
"max_grad_norm": 1,
|
100 |
-
"optimizer_class": "<class 'transformers.optimization.AdamW'>",
|
101 |
-
"optimizer_params": {
|
102 |
-
"lr": 1e-05
|
103 |
-
},
|
104 |
-
"scheduler": "WarmupLinear",
|
105 |
-
"steps_per_epoch": null,
|
106 |
-
"warmup_steps": 1079,
|
107 |
-
"weight_decay": 0.01
|
108 |
-
}
|
109 |
-
```
|
110 |
|
111 |
|
112 |
## Full Model Architecture
|
113 |
```
|
114 |
SentenceTransformer(
|
115 |
-
(0): Transformer({'max_seq_length':
|
116 |
-
(1): Pooling({'word_embedding_dimension':
|
117 |
)
|
118 |
```
|
119 |
|
120 |
## Citing & Authors
|
121 |
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
---
|
3 |
+
language:
|
4 |
+
- pt
|
5 |
+
thumbnail: "Portuguese SBERT for the Legal Domain"
|
6 |
pipeline_tag: sentence-similarity
|
7 |
tags:
|
8 |
- sentence-transformers
|
|
|
9 |
- sentence-similarity
|
10 |
- transformers
|
11 |
+
datasets:
|
12 |
+
- assin
|
13 |
+
- assin2
|
14 |
+
- stsb_multi_mt
|
15 |
+
- rufimelo/PortugueseLegalSentences-v1
|
16 |
+
widget:
|
17 |
+
- source_sentence: "O advogado apresentou as provas ao juíz."
|
18 |
+
sentences:
|
19 |
+
- "O juíz leu as provas."
|
20 |
+
- "O juíz leu o recurso."
|
21 |
+
- "O juíz atirou uma pedra."
|
22 |
+
example_title: "Example 1"
|
23 |
+
model-index:
|
24 |
+
- name: BERTimbau
|
25 |
+
results:
|
26 |
+
- task:
|
27 |
+
name: STS
|
28 |
+
type: STS
|
29 |
+
metrics:
|
30 |
+
- name: Pearson Correlation - assin Dataset
|
31 |
+
type: Pearson Correlation
|
32 |
+
value: xxxxx
|
33 |
+
- name: Pearson Correlation - assin2 Dataset
|
34 |
+
type: Pearson Correlation
|
35 |
+
value: xxxxx
|
36 |
+
- name: Pearson Correlation - stsb_multi_mt pt Dataset
|
37 |
+
type: Pearson Correlation
|
38 |
+
value: xxxxx
|
39 |
---
|
40 |
|
41 |
+
# rufimelo/Legal-BERTimbau-base-TSDAE-sts
|
|
|
|
|
42 |
|
43 |
+
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.
|
44 |
+
rufimelo/Legal-BERTimbau-base-TSDAE-sts is based on Legal-BERTimbau-large which derives from [BERTimbau](https://huggingface.co/neuralmind/bert-large-portuguese-cased) large.
|
45 |
+
It is adapted to the Portuguese legal domain and trained for STS on portuguese datasets.
|
46 |
|
47 |
## Usage (Sentence-Transformers)
|
48 |
|
|
|
56 |
|
57 |
```python
|
58 |
from sentence_transformers import SentenceTransformer
|
59 |
+
sentences = ["Isto é um exemplo", "Isto é um outro exemplo"]
|
60 |
|
61 |
+
model = SentenceTransformer('rufimelo/Legal-BERTimbau-base-TSDAE-sts')
|
62 |
embeddings = model.encode(sentences)
|
63 |
print(embeddings)
|
64 |
```
|
|
|
66 |
|
67 |
|
68 |
## Usage (HuggingFace Transformers)
|
69 |
+
|
70 |
|
71 |
```python
|
72 |
from transformers import AutoTokenizer, AutoModel
|
73 |
import torch
|
74 |
|
75 |
|
76 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
77 |
+
def mean_pooling(model_output, attention_mask):
|
78 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
79 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
80 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
81 |
|
82 |
|
83 |
# Sentences we want sentence embeddings for
|
84 |
sentences = ['This is an example sentence', 'Each sentence is converted']
|
85 |
|
86 |
# Load model from HuggingFace Hub
|
87 |
+
tokenizer = AutoTokenizer.from_pretrained('rufimelo/Legal-BERTimbau-base-TSDAE-sts')
|
88 |
+
model = AutoModel.from_pretrained('rufimelo/Legal-BERTimbau-base-TSDAE-sts')
|
89 |
|
90 |
# Tokenize sentences
|
91 |
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
|
|
94 |
with torch.no_grad():
|
95 |
model_output = model(**encoded_input)
|
96 |
|
97 |
+
# Perform pooling. In this case, mean pooling.
|
98 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
99 |
|
100 |
print("Sentence embeddings:")
|
101 |
print(sentence_embeddings)
|
102 |
```
|
103 |
|
104 |
|
105 |
+
## Evaluation Results STS
|
106 |
+
|
107 |
+
|
108 |
+
| Model| Assin | Assin2|stsb_multi_mt pt| avg|
|
109 |
+
| ---------------------------------------- | ---------- | ---------- |---------- |---------- |
|
110 |
+
| Legal-BERTimbau-sts-base| 0.71457| 0.73545 | 0.72383|0.72462|
|
111 |
+
| Legal-BERTimbau-sts-base-ma| 0.74874 | 0.79532|0.82254 |0.78886|
|
112 |
+
| Legal-BERTimbau-sts-base-ma-v2| 0.75481 | 0.80262|0.82178|0.79307|
|
113 |
+
| Legal-BERTimbau-sts-large| 0.76629| 0.82357 | 0.79120|0.79369|
|
114 |
+
| Legal-BERTimbau-sts-large-v2| 0.76299 | 0.81121|0.81726 |0.79715|
|
115 |
+
| Legal-BERTimbau-sts-large-ma| 0.76195| 0.81622 | 0.82608|0.80142|
|
116 |
+
| Legal-BERTimbau-sts-large-ma-v2| 0.7836| 0.8462| 0.8261| 0.81863|
|
117 |
+
| Legal-BERTimbau-sts-large-ma-v3| 0.7749| **0.8470**| 0.8364| **0.81943**|
|
118 |
+
| ---------------------------------------- | ---------- |---------- |---------- |---------- |
|
119 |
+
| BERTimbau base Fine-tuned for STS|**0.78455** | 0.80626|0.82841|0.80640|
|
120 |
+
| BERTimbau large Fine-tuned for STS|0.78193 | 0.81758|0.83784|0.81245|
|
121 |
+
| ---------------------------------------- | ---------- |---------- |---------- |---------- |
|
122 |
+
| paraphrase-multilingual-mpnet-base-v2| 0.71457| 0.79831 |0.83999 |0.78429|
|
123 |
+
| paraphrase-multilingual-mpnet-base-v2 Fine-tuned with assin(s)| 0.77641|0.79831 |**0.84575**|0.80682|
|
124 |
## Training
|
|
|
125 |
|
126 |
+
rufimelo/Legal-BERTimbau-base-TSDAE-sts is based on rufimelo/Legal-BERTimbau-base-TSDAE which derives from [BERTimbau](https://huggingface.co/neuralmind/bert-base-portuguese-cased) large.
|
127 |
|
128 |
+
rufimelo/Legal-BERTimbau-base-TSDAE was trained with TSDAE: 50000 cleaned documents (https://huggingface.co/datasets/rufimelo/PortugueseLegalSentences-v1)
|
129 |
+
'lr': 1e-5
|
|
|
|
|
|
|
|
|
130 |
|
131 |
+
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. 'lr': 1e-5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
|
134 |
## Full Model Architecture
|
135 |
```
|
136 |
SentenceTransformer(
|
137 |
+
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: BertModel
|
138 |
+
(1): Pooling({'word_embedding_dimension': 1024, '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})
|
139 |
)
|
140 |
```
|
141 |
|
142 |
## Citing & Authors
|
143 |
|
144 |
+
If you use this work, please cite BERTimbau's work:
|
145 |
+
|
146 |
+
```bibtex
|
147 |
+
@inproceedings{souza2020bertimbau,
|
148 |
+
author = {F{\'a}bio Souza and
|
149 |
+
Rodrigo Nogueira and
|
150 |
+
Roberto Lotufo},
|
151 |
+
title = {{BERT}imbau: pretrained {BERT} models for {B}razilian {P}ortuguese},
|
152 |
+
booktitle = {9th Brazilian Conference on Intelligent Systems, {BRACIS}, Rio Grande do Sul, Brazil, October 20-23 (to appear)},
|
153 |
+
year = {2020}
|
154 |
+
}
|
155 |
+
```
|