Aymen Ben Othmen
commited on
Commit
•
36935f1
1
Parent(s):
41735f6
Add SetFit model
Browse files- 1_Pooling/config.json +1 -1
- README.md +42 -4
- config.json +13 -10
- config_sentence_transformers.json +2 -2
- model_head.pkl +2 -2
- modules.json +0 -6
- pytorch_model.bin +2 -2
- special_tokens_map.json +13 -5
- tokenizer.json +2 -2
- tokenizer_config.json +17 -13
1_Pooling/config.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
{
|
2 |
-
"word_embedding_dimension":
|
3 |
"pooling_mode_cls_token": false,
|
4 |
"pooling_mode_mean_tokens": true,
|
5 |
"pooling_mode_max_tokens": false,
|
|
|
1 |
{
|
2 |
+
"word_embedding_dimension": 768,
|
3 |
"pooling_mode_cls_token": false,
|
4 |
"pooling_mode_mean_tokens": true,
|
5 |
"pooling_mode_max_tokens": false,
|
README.md
CHANGED
@@ -4,12 +4,13 @@ tags:
|
|
4 |
- sentence-transformers
|
5 |
- feature-extraction
|
6 |
- sentence-similarity
|
|
|
7 |
|
8 |
---
|
9 |
|
10 |
# {MODEL_NAME}
|
11 |
|
12 |
-
This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a
|
13 |
|
14 |
<!--- Describe your model here -->
|
15 |
|
@@ -34,6 +35,44 @@ print(embeddings)
|
|
34 |
|
35 |
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
## Evaluation Results
|
38 |
|
39 |
<!--- Describe how your model was evaluated -->
|
@@ -77,9 +116,8 @@ Parameters of the fit()-Method:
|
|
77 |
## Full Model Architecture
|
78 |
```
|
79 |
SentenceTransformer(
|
80 |
-
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model:
|
81 |
-
(1): Pooling({'word_embedding_dimension':
|
82 |
-
(2): Normalize()
|
83 |
)
|
84 |
```
|
85 |
|
|
|
4 |
- sentence-transformers
|
5 |
- feature-extraction
|
6 |
- sentence-similarity
|
7 |
+
- transformers
|
8 |
|
9 |
---
|
10 |
|
11 |
# {MODEL_NAME}
|
12 |
|
13 |
+
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.
|
14 |
|
15 |
<!--- Describe your model here -->
|
16 |
|
|
|
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 -->
|
|
|
116 |
## Full Model Architecture
|
117 |
```
|
118 |
SentenceTransformer(
|
119 |
+
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: XLMRobertaModel
|
120 |
+
(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})
|
|
|
121 |
)
|
122 |
```
|
123 |
|
config.json
CHANGED
@@ -1,26 +1,29 @@
|
|
1 |
{
|
2 |
-
"_name_or_path": "/home/ubuntu/.cache/torch/sentence_transformers/sentence-
|
3 |
"architectures": [
|
4 |
-
"
|
5 |
],
|
6 |
"attention_probs_dropout_prob": 0.1,
|
|
|
7 |
"classifier_dropout": null,
|
|
|
8 |
"gradient_checkpointing": false,
|
9 |
"hidden_act": "gelu",
|
10 |
"hidden_dropout_prob": 0.1,
|
11 |
-
"hidden_size":
|
12 |
"initializer_range": 0.02,
|
13 |
-
"intermediate_size":
|
14 |
-
"layer_norm_eps": 1e-
|
15 |
-
"max_position_embeddings":
|
16 |
-
"model_type": "
|
17 |
"num_attention_heads": 12,
|
18 |
"num_hidden_layers": 12,
|
19 |
-
"
|
|
|
20 |
"position_embedding_type": "absolute",
|
21 |
"torch_dtype": "float32",
|
22 |
"transformers_version": "4.22.2",
|
23 |
-
"type_vocab_size":
|
24 |
"use_cache": true,
|
25 |
-
"vocab_size":
|
26 |
}
|
|
|
1 |
{
|
2 |
+
"_name_or_path": "/home/ubuntu/.cache/torch/sentence_transformers/sentence-transformers_paraphrase-multilingual-mpnet-base-v2/",
|
3 |
"architectures": [
|
4 |
+
"XLMRobertaModel"
|
5 |
],
|
6 |
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"bos_token_id": 0,
|
8 |
"classifier_dropout": null,
|
9 |
+
"eos_token_id": 2,
|
10 |
"gradient_checkpointing": false,
|
11 |
"hidden_act": "gelu",
|
12 |
"hidden_dropout_prob": 0.1,
|
13 |
+
"hidden_size": 768,
|
14 |
"initializer_range": 0.02,
|
15 |
+
"intermediate_size": 3072,
|
16 |
+
"layer_norm_eps": 1e-05,
|
17 |
+
"max_position_embeddings": 514,
|
18 |
+
"model_type": "xlm-roberta",
|
19 |
"num_attention_heads": 12,
|
20 |
"num_hidden_layers": 12,
|
21 |
+
"output_past": true,
|
22 |
+
"pad_token_id": 1,
|
23 |
"position_embedding_type": "absolute",
|
24 |
"torch_dtype": "float32",
|
25 |
"transformers_version": "4.22.2",
|
26 |
+
"type_vocab_size": 1,
|
27 |
"use_cache": true,
|
28 |
+
"vocab_size": 250002
|
29 |
}
|
config_sentence_transformers.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
{
|
2 |
"__version__": {
|
3 |
"sentence_transformers": "2.0.0",
|
4 |
-
"transformers": "4.
|
5 |
-
"pytorch": "1.
|
6 |
}
|
7 |
}
|
|
|
1 |
{
|
2 |
"__version__": {
|
3 |
"sentence_transformers": "2.0.0",
|
4 |
+
"transformers": "4.7.0",
|
5 |
+
"pytorch": "1.9.0+cu102"
|
6 |
}
|
7 |
}
|
model_head.pkl
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:877aa880a769b2381d1bee6faef581fa8df01edcf2b53bedbc9bb1d574dbb81b
|
3 |
+
size 6991
|
modules.json
CHANGED
@@ -10,11 +10,5 @@
|
|
10 |
"name": "1",
|
11 |
"path": "1_Pooling",
|
12 |
"type": "sentence_transformers.models.Pooling"
|
13 |
-
},
|
14 |
-
{
|
15 |
-
"idx": 2,
|
16 |
-
"name": "2",
|
17 |
-
"path": "2_Normalize",
|
18 |
-
"type": "sentence_transformers.models.Normalize"
|
19 |
}
|
20 |
]
|
|
|
10 |
"name": "1",
|
11 |
"path": "1_Pooling",
|
12 |
"type": "sentence_transformers.models.Pooling"
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
}
|
14 |
]
|
pytorch_model.bin
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:08eaf63cb3fd75d55d493acf54b8dda86e90ae2be6a457eb8d1c6463cf670d19
|
3 |
+
size 1112244081
|
special_tokens_map.json
CHANGED
@@ -1,7 +1,15 @@
|
|
1 |
{
|
2 |
-
"
|
3 |
-
"
|
4 |
-
"
|
5 |
-
"
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
}
|
|
|
1 |
{
|
2 |
+
"bos_token": "<s>",
|
3 |
+
"cls_token": "<s>",
|
4 |
+
"eos_token": "</s>",
|
5 |
+
"mask_token": {
|
6 |
+
"content": "<mask>",
|
7 |
+
"lstrip": true,
|
8 |
+
"normalized": false,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false
|
11 |
+
},
|
12 |
+
"pad_token": "<pad>",
|
13 |
+
"sep_token": "</s>",
|
14 |
+
"unk_token": "<unk>"
|
15 |
}
|
tokenizer.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b60b6b43406a48bf3638526314f3d232d97058bc93472ff2de930d43686fa441
|
3 |
+
size 17082913
|
tokenizer_config.json
CHANGED
@@ -1,16 +1,20 @@
|
|
1 |
{
|
2 |
-
"
|
3 |
-
"
|
4 |
-
"
|
5 |
-
"mask_token":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
"model_max_length": 512,
|
7 |
-
"name_or_path": "/home/ubuntu/.cache/torch/sentence_transformers/sentence-
|
8 |
-
"
|
9 |
-
"
|
10 |
-
"
|
11 |
-
"
|
12 |
-
"
|
13 |
-
"tokenize_chinese_chars": true,
|
14 |
-
"tokenizer_class": "BertTokenizer",
|
15 |
-
"unk_token": "[UNK]"
|
16 |
}
|
|
|
1 |
{
|
2 |
+
"bos_token": "<s>",
|
3 |
+
"cls_token": "<s>",
|
4 |
+
"eos_token": "</s>",
|
5 |
+
"mask_token": {
|
6 |
+
"__type": "AddedToken",
|
7 |
+
"content": "<mask>",
|
8 |
+
"lstrip": true,
|
9 |
+
"normalized": true,
|
10 |
+
"rstrip": false,
|
11 |
+
"single_word": false
|
12 |
+
},
|
13 |
"model_max_length": 512,
|
14 |
+
"name_or_path": "/home/ubuntu/.cache/torch/sentence_transformers/sentence-transformers_paraphrase-multilingual-mpnet-base-v2/",
|
15 |
+
"pad_token": "<pad>",
|
16 |
+
"sep_token": "</s>",
|
17 |
+
"special_tokens_map_file": null,
|
18 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
19 |
+
"unk_token": "<unk>"
|
|
|
|
|
|
|
20 |
}
|