update readme
Browse files
README.md
CHANGED
@@ -1,135 +1,45 @@
|
|
1 |
---
|
2 |
pipeline_tag: sentence-similarity
|
|
|
|
|
3 |
tags:
|
4 |
- sentence-transformers
|
5 |
-
- feature-extraction
|
6 |
- sentence-similarity
|
7 |
- transformers
|
|
|
|
|
|
|
|
|
8 |
|
9 |
---
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
## Usage (Sentence-Transformers)
|
18 |
-
|
19 |
-
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
20 |
-
|
21 |
-
```
|
22 |
-
pip install -U sentence-transformers
|
23 |
-
```
|
24 |
-
|
25 |
-
Then you can use the model like this:
|
26 |
-
|
27 |
-
```python
|
28 |
-
from sentence_transformers import SentenceTransformer
|
29 |
-
sentences = ["This is an example sentence", "Each sentence is converted"]
|
30 |
-
|
31 |
-
model = SentenceTransformer('{MODEL_NAME}')
|
32 |
-
embeddings = model.encode(sentences)
|
33 |
-
print(embeddings)
|
34 |
-
```
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
## Usage (HuggingFace Transformers)
|
39 |
-
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.
|
40 |
-
|
41 |
-
```python
|
42 |
-
from transformers import AutoTokenizer, AutoModel
|
43 |
-
import torch
|
44 |
-
|
45 |
-
|
46 |
-
#Mean Pooling - Take attention mask into account for correct averaging
|
47 |
-
def mean_pooling(model_output, attention_mask):
|
48 |
-
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
49 |
-
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
50 |
-
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
51 |
-
|
52 |
-
|
53 |
-
# Sentences we want sentence embeddings for
|
54 |
-
sentences = ['This is an example sentence', 'Each sentence is converted']
|
55 |
-
|
56 |
-
# Load model from HuggingFace Hub
|
57 |
-
tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
|
58 |
-
model = AutoModel.from_pretrained('{MODEL_NAME}')
|
59 |
-
|
60 |
-
# Tokenize sentences
|
61 |
-
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
62 |
-
|
63 |
-
# Compute token embeddings
|
64 |
-
with torch.no_grad():
|
65 |
-
model_output = model(**encoded_input)
|
66 |
-
|
67 |
-
# Perform pooling. In this case, mean pooling.
|
68 |
-
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
69 |
-
|
70 |
-
print("Sentence embeddings:")
|
71 |
-
print(sentence_embeddings)
|
72 |
-
```
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
## Evaluation Results
|
77 |
-
|
78 |
-
<!--- Describe how your model was evaluated -->
|
79 |
-
|
80 |
-
For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name={MODEL_NAME})
|
81 |
|
|
|
|
|
82 |
|
83 |
## Training
|
84 |
-
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
```
|
90 |
-
{'batch_size': 68, 'sampler': 'torch.utils.data.dataloader._InfiniteConstantSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
|
91 |
-
```
|
92 |
-
|
93 |
-
**Loss**:
|
94 |
-
|
95 |
-
`sentence_transformers.losses.BatchHardSoftMarginTripletLoss.BatchHardSoftMarginTripletLoss`
|
96 |
-
|
97 |
-
Parameters of the fit()-Method:
|
98 |
-
```
|
99 |
-
{
|
100 |
-
"epochs": 7,
|
101 |
-
"evaluation_steps": 8905,
|
102 |
-
"evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
|
103 |
-
"max_grad_norm": 1,
|
104 |
-
"optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
|
105 |
-
"optimizer_params": {
|
106 |
-
"lr": 5.5512022294147105e-06
|
107 |
-
},
|
108 |
-
"scheduler": "WarmupLinear",
|
109 |
-
"steps_per_epoch": null,
|
110 |
-
"warmup_steps": 93507,
|
111 |
-
"weight_decay": 0.01
|
112 |
-
}
|
113 |
-
```
|
114 |
-
|
115 |
-
|
116 |
-
## Full Model Architecture
|
117 |
-
```
|
118 |
-
SentenceTransformer(
|
119 |
-
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
|
120 |
-
(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})
|
121 |
-
)
|
122 |
-
```
|
123 |
-
|
124 |
-
## Citing & Authors
|
125 |
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
## Licensing
|
129 |
-
|
130 |
Copyright (c) 2023 [Philip May](https://may.la/), [Deutsche Telekom AG](https://www.telekom.com/)\
|
131 |
Copyright (c) 2022 [deepset GmbH](https://www.deepset.ai/)
|
132 |
|
133 |
Licensed under the **MIT License** (the "License"); you may not use this file except in compliance with the License.
|
134 |
You may obtain a copy of the License by reviewing the file
|
135 |
-
[LICENSE]() in the repository.
|
|
|
1 |
---
|
2 |
pipeline_tag: sentence-similarity
|
3 |
+
language:
|
4 |
+
- de
|
5 |
tags:
|
6 |
- sentence-transformers
|
|
|
7 |
- sentence-similarity
|
8 |
- transformers
|
9 |
+
- setfit
|
10 |
+
license: mit
|
11 |
+
datasets:
|
12 |
+
- deutsche-telekom/ger-backtrans-paraphrase
|
13 |
|
14 |
---
|
15 |
|
16 |
+
# German BERT large paraphrase cosine
|
17 |
+
This is a [sentence-transformers](https://www.SBERT.net) model:
|
18 |
+
It maps sentences & paragraphs (text) into a 1024 dimensional dense vector space.
|
19 |
+
The model is intended to be used together with [SetFit](https://github.com/huggingface/setfit)
|
20 |
+
to improve German few-shot text classification.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
This model is based on [deepset/gbert-large](https://huggingface.co/deepset/gbert-large).
|
23 |
+
Many thanks to [deepset](https://www.deepset.ai/)!
|
24 |
|
25 |
## Training
|
26 |
+
TODO
|
27 |
|
28 |
+
## Evaluation Results
|
29 |
+
We use the [NLU Few-shot Benchmark - English and German](https://huggingface.co/datasets/deutsche-telekom/NLU-few-shot-benchmark-en-de)
|
30 |
+
dataset to evaluate this model in a German few-shot scenario.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
**Qualitative results**
|
33 |
+
- multilingual sentence embeddings provide the worst results
|
34 |
+
- Electra models also deliver poor results
|
35 |
+
- German BERT base size model ([deepset/gbert-base](https://huggingface.co/deepset/gbert-base)) provides good results
|
36 |
+
- German BERT large size model ([deepset/gbert-large](https://huggingface.co/deepset/gbert-large)) provides very good results
|
37 |
+
- our fine-tuned models (this model and [deutsche-telekom/gbert-large-paraphrase-cosine](https://huggingface.co/deutsche-telekom/gbert-large-paraphrase-cosine)) provide best results
|
38 |
|
39 |
## Licensing
|
|
|
40 |
Copyright (c) 2023 [Philip May](https://may.la/), [Deutsche Telekom AG](https://www.telekom.com/)\
|
41 |
Copyright (c) 2022 [deepset GmbH](https://www.deepset.ai/)
|
42 |
|
43 |
Licensed under the **MIT License** (the "License"); you may not use this file except in compliance with the License.
|
44 |
You may obtain a copy of the License by reviewing the file
|
45 |
+
[LICENSE](https://huggingface.co/deutsche-telekom/gbert-large-paraphrase-cosine/blob/main/LICENSE) in the repository.
|