osanseviero
commited on
Commit
·
5b6825a
1
Parent(s):
1f189b6
Add new SentenceTransformer model.
Browse files- 1_Pooling/config.json +7 -0
- README.md +88 -0
- config.json +27 -0
- merges.txt +0 -0
- modules.json +14 -0
- pytorch_model.bin +3 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +1 -0
- vocab.json +0 -0
1_Pooling/config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 768,
|
3 |
+
"pooling_mode_cls_token": false,
|
4 |
+
"pooling_mode_mean_tokens": true,
|
5 |
+
"pooling_mode_max_tokens": false,
|
6 |
+
"pooling_mode_mean_sqrt_len_tokens": false
|
7 |
+
}
|
README.md
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- sentence-transformers
|
4 |
+
- feature-extraction
|
5 |
+
---
|
6 |
+
|
7 |
+
# Name of Model
|
8 |
+
|
9 |
+
<!--- Describe your model here -->
|
10 |
+
|
11 |
+
## Model Description
|
12 |
+
The model consists of the following layers:
|
13 |
+
|
14 |
+
(0) Base Transformer Type: RobertaModel
|
15 |
+
|
16 |
+
(1) mean Pooling
|
17 |
+
|
18 |
+
|
19 |
+
## Usage (Sentence-Transformers)
|
20 |
+
|
21 |
+
Using this model becomes more convenient when you have [sentence-transformers](https://github.com/UKPLab/sentence-transformers) installed:
|
22 |
+
|
23 |
+
```
|
24 |
+
pip install -U sentence-transformers
|
25 |
+
```
|
26 |
+
|
27 |
+
Then you can use the model like this:
|
28 |
+
|
29 |
+
```python
|
30 |
+
from sentence_transformers import SentenceTransformer
|
31 |
+
sentences = ["This is an example sentence"]
|
32 |
+
|
33 |
+
model = SentenceTransformer('model_name')
|
34 |
+
embeddings = model.encode(sentences)
|
35 |
+
print(embeddings)
|
36 |
+
```
|
37 |
+
|
38 |
+
|
39 |
+
## Usage (HuggingFace Transformers)
|
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 |
+
sum_embeddings = torch.sum(token_embeddings * input_mask_expanded, 1)
|
51 |
+
sum_mask = torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
52 |
+
return sum_embeddings / sum_mask
|
53 |
+
|
54 |
+
|
55 |
+
# Sentences we want sentence embeddings for
|
56 |
+
sentences = ['This is an example sentence']
|
57 |
+
|
58 |
+
# Load model from HuggingFace Hub
|
59 |
+
tokenizer = AutoTokenizer.from_pretrained('model_name')
|
60 |
+
model = AutoModel.from_pretrained('model_name')
|
61 |
+
|
62 |
+
# Tokenize sentences
|
63 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, max_length=128, return_tensors='pt')
|
64 |
+
|
65 |
+
# Compute token embeddings
|
66 |
+
with torch.no_grad():
|
67 |
+
model_output = model(**encoded_input)
|
68 |
+
|
69 |
+
# Perform pooling. In this case, max pooling.
|
70 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
71 |
+
|
72 |
+
print("Sentence embeddings:")
|
73 |
+
print(sentence_embeddings)
|
74 |
+
```
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
## Training Procedure
|
79 |
+
|
80 |
+
<!--- Describe how your model was trained -->
|
81 |
+
|
82 |
+
## Evaluation Results
|
83 |
+
|
84 |
+
<!--- Describe how your model was evaluated -->
|
85 |
+
|
86 |
+
## Citing & Authors
|
87 |
+
|
88 |
+
<!--- Describe where people can find more information -->
|
config.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/Users/osanseviero/.cache/torch/sentence_transformers/sbert.net_models_osanseviero_full-sentence-distillroberta3/",
|
3 |
+
"architectures": [
|
4 |
+
"RobertaModel"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"bos_token_id": 0,
|
8 |
+
"eos_token_id": 2,
|
9 |
+
"gradient_checkpointing": false,
|
10 |
+
"hidden_act": "gelu",
|
11 |
+
"hidden_dropout_prob": 0.1,
|
12 |
+
"hidden_size": 768,
|
13 |
+
"initializer_range": 0.02,
|
14 |
+
"intermediate_size": 3072,
|
15 |
+
"layer_norm_eps": 1e-05,
|
16 |
+
"max_position_embeddings": 514,
|
17 |
+
"model_type": "roberta",
|
18 |
+
"num_attention_heads": 12,
|
19 |
+
"num_hidden_layers": 6,
|
20 |
+
"output_hidden_states": true,
|
21 |
+
"pad_token_id": 1,
|
22 |
+
"position_embedding_type": "absolute",
|
23 |
+
"transformers_version": "4.6.1",
|
24 |
+
"type_vocab_size": 1,
|
25 |
+
"use_cache": true,
|
26 |
+
"vocab_size": 50265
|
27 |
+
}
|
merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
modules.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "0",
|
5 |
+
"path": "",
|
6 |
+
"type": "sentence_transformers.models.Transformer"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_Pooling",
|
12 |
+
"type": "sentence_transformers.models.Pooling"
|
13 |
+
}
|
14 |
+
]
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:25997a5d584a229e5a483ec39325ae402cd26d8b2b348b85dd6e33019c38288a
|
3 |
+
size 328519167
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 128,
|
3 |
+
"do_lower_case": false
|
4 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": false}}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"unk_token": {"content": "<unk>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "bos_token": {"content": "<s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "eos_token": {"content": "</s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "add_prefix_space": false, "errors": "replace", "sep_token": {"content": "</s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "cls_token": {"content": "<s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "pad_token": {"content": "<pad>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "add_special_tokens": false, "model_max_length": 512, "special_tokens_map_file": "/home/ukp-reimers/.cache/torch/transformers/4f4743e3f4fbeb763d116a0f2697f5e03117bd130711d90eaf795aeaeb7c4659.01d47f83d2e88283cc7f6be55eaef5d08d20297fc3bc1c1618ac15c35d1b97dd", "full_tokenizer_file": null, "name_or_path": "/Users/osanseviero/.cache/torch/sentence_transformers/sbert.net_models_osanseviero_full-sentence-distillroberta3/"}
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|