Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
pipeline_tag: sentence-similarity
|
3 |
+
tags:
|
4 |
+
- sentence-transformers
|
5 |
+
- feature-extraction
|
6 |
+
- sentence-similarity
|
7 |
+
- transformers.js
|
8 |
+
- onnx
|
9 |
+
widget:
|
10 |
+
- example_title: Nederlands
|
11 |
+
source_sentence: Deze week ga ik naar de kapper
|
12 |
+
sentences:
|
13 |
+
- Ik ga binnenkort mijn haren laten knippen
|
14 |
+
- Morgen wil ik uitslapen
|
15 |
+
- Gisteren ging ik naar de bioscoop
|
16 |
+
datasets:
|
17 |
+
- NetherlandsForensicInstitute/AllNLI-translated-nl
|
18 |
+
- NetherlandsForensicInstitute/altlex-translated-nl
|
19 |
+
- NetherlandsForensicInstitute/coco-captions-translated-nl
|
20 |
+
- NetherlandsForensicInstitute/flickr30k-captions-translated-nl
|
21 |
+
- NetherlandsForensicInstitute/msmarco-translated-nl
|
22 |
+
- NetherlandsForensicInstitute/quora-duplicates-translated-nl
|
23 |
+
- NetherlandsForensicInstitute/sentence-compression-translated-nl
|
24 |
+
- NetherlandsForensicInstitute/simplewiki-translated-nl
|
25 |
+
- NetherlandsForensicInstitute/stackexchange-duplicate-questions-translated-nl
|
26 |
+
- NetherlandsForensicInstitute/wiki-atomic-edits-translated-nl
|
27 |
+
language:
|
28 |
+
- nl
|
29 |
+
---
|
30 |
+
|
31 |
+
# robbert-2022-dutch-sentence-transformers - Onnx
|
32 |
+
- Model creator: [Netherlands Forensic Institute](https://huggingface.co/NetherlandsForensicInstitute)
|
33 |
+
- Original model: [robbert-2022-dutch-sentence-transformers](https://huggingface.co/NetherlandsForensicInstitute/robbert-2022-dutch-sentence-transformers)
|
34 |
+
|
35 |
+
# Description
|
36 |
+
This Onnx model is a converted version of robbert-2022-dutch-sentence-transformers using the transformers.js script found [here](https://github.com/xenova/transformers.js?tab=readme-ov-file#convert-your-models-to-onnx).
|
37 |
+
|
38 |
+
# Original model card: robbert-2022-dutch-sentence-transformers
|
39 |
+
|
40 |
+
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.
|
41 |
+
|
42 |
+
<!--- Describe your model here -->
|
43 |
+
|
44 |
+
This model is based on [KU Leuven's RobBERT model](https://huggingface.co/DTAI-KULeuven/robbert-2022-dutch-base).
|
45 |
+
It has been finetuned on the [Paraphrase dataset](https://public.ukp.informatik.tu-darmstadt.de/reimers/sentence-transformers/datasets/paraphrases/), which we (machine-) translated to Dutch. The Paraphrase dataset consists of multiple datasets that consist of duo's of similar texts, for example duplicate questions on a forum.
|
46 |
+
We have released the translated data that we used to train this model on our Huggingface page.
|
47 |
+
|
48 |
+
## Usage (Sentence-Transformers)
|
49 |
+
|
50 |
+
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
51 |
+
|
52 |
+
```
|
53 |
+
pip install -U sentence-transformers
|
54 |
+
```
|
55 |
+
|
56 |
+
Then you can use the model like this:
|
57 |
+
|
58 |
+
```python
|
59 |
+
from sentence_transformers import SentenceTransformer
|
60 |
+
sentences = ["This is an example sentence", "Each sentence is converted"]
|
61 |
+
|
62 |
+
model = SentenceTransformer('NetherlandsForensicInstitute/robbert-2022-dutch-sentence-transformers')
|
63 |
+
embeddings = model.encode(sentences)
|
64 |
+
print(embeddings)
|
65 |
+
```
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
## Usage (HuggingFace Transformers)
|
70 |
+
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.
|
71 |
+
|
72 |
+
```python
|
73 |
+
from transformers import AutoTokenizer, AutoModel
|
74 |
+
import torch
|
75 |
+
|
76 |
+
|
77 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
78 |
+
def mean_pooling(model_output, attention_mask):
|
79 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
80 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
81 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
82 |
+
|
83 |
+
|
84 |
+
# Sentences we want sentence embeddings for
|
85 |
+
sentences = ['This is an example sentence', 'Each sentence is converted']
|
86 |
+
|
87 |
+
# Load model from HuggingFace Hub
|
88 |
+
tokenizer = AutoTokenizer.from_pretrained('NetherlandsForensicInstitute/robbert-2022-dutch-sentence-transformers}')
|
89 |
+
model = AutoModel.from_pretrained('NetherlandsForensicInstitute/robbert-2022-dutch-sentence-transformers')
|
90 |
+
|
91 |
+
# Tokenize sentences
|
92 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
93 |
+
|
94 |
+
# Compute token embeddings
|
95 |
+
with torch.no_grad():
|
96 |
+
model_output = model(**encoded_input)
|
97 |
+
|
98 |
+
# Perform pooling. In this case, mean pooling.
|
99 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
100 |
+
|
101 |
+
print("Sentence embeddings:")
|
102 |
+
print(sentence_embeddings)
|
103 |
+
```
|
104 |
+
|
105 |
+
|
106 |
+
## Training
|
107 |
+
The model was trained with the parameters:
|
108 |
+
|
109 |
+
**DataLoader**:
|
110 |
+
|
111 |
+
`MultiDatasetDataLoader.MultiDatasetDataLoader` of length 414262 with parameters:
|
112 |
+
```
|
113 |
+
{'batch_size': 1}
|
114 |
+
```
|
115 |
+
|
116 |
+
**Loss**:
|
117 |
+
|
118 |
+
`sentence_transformers.losses.MultipleNegativesRankingLoss.MultipleNegativesRankingLoss` with parameters:
|
119 |
+
```
|
120 |
+
{'scale': 20.0, 'similarity_fct': 'cos_sim'}
|
121 |
+
```
|
122 |
+
|
123 |
+
Parameters of the fit()-Method:
|
124 |
+
```
|
125 |
+
{
|
126 |
+
"epochs": 1,
|
127 |
+
"evaluation_steps": 50000,
|
128 |
+
"evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
|
129 |
+
"max_grad_norm": 1,
|
130 |
+
"optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
|
131 |
+
"optimizer_params": {
|
132 |
+
"lr": 2e-05
|
133 |
+
},
|
134 |
+
"scheduler": "WarmupLinear",
|
135 |
+
"steps_per_epoch": null,
|
136 |
+
"warmup_steps": 500,
|
137 |
+
"weight_decay": 0.01
|
138 |
+
}
|
139 |
+
```
|
140 |
+
|
141 |
+
|
142 |
+
## Full Model Architecture
|
143 |
+
```
|
144 |
+
SentenceTransformer(
|
145 |
+
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: RobertaModel
|
146 |
+
(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})
|
147 |
+
)
|
148 |
+
```
|
149 |
+
|
150 |
+
## Citing & Authors
|
151 |
+
|
152 |
+
<!--- Describe where people can find more information -->
|