Kyleiwaniec
commited on
Commit
·
da8c55e
1
Parent(s):
f2a3388
Upload folder using huggingface_hub
Browse files- .ipynb_checkpoints/similarity_evaluation_sts-test_results-checkpoint.csv +2 -0
- 1_Pooling/config.json +7 -0
- README.md +126 -0
- added_tokens.json +7 -0
- config.json +31 -0
- config_sentence_transformers.json +7 -0
- eval/similarity_evaluation_sts-dev_results.csv +21 -0
- merges.txt +0 -0
- modules.json +14 -0
- pytorch_model.bin +3 -0
- sentence_bert_config.json +4 -0
- similarity_evaluation_sts-test_results.csv +2 -0
- special_tokens_map.json +9 -0
- tokenizer.json +0 -0
- tokenizer_config.json +59 -0
- vocab.json +0 -0
.ipynb_checkpoints/similarity_evaluation_sts-test_results-checkpoint.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman
|
2 |
+
-1,-1,0.6744054047228356,0.6750742998718,0.6631685565159673,0.6599136568909711,0.6595100643715024,0.6593615183588794,0.666057660517302,0.6624310997086206
|
1_Pooling/config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 1024,
|
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,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
pipeline_tag: sentence-similarity
|
3 |
+
tags:
|
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 1024 dimensional dense vector space and can be used for tasks like clustering or semantic search.
|
14 |
+
|
15 |
+
<!--- Describe your model here -->
|
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 |
+
The model was trained with the parameters:
|
85 |
+
|
86 |
+
**DataLoader**:
|
87 |
+
|
88 |
+
`torch.utils.data.dataloader.DataLoader` of length 75 with parameters:
|
89 |
+
```
|
90 |
+
{'batch_size': 16, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
|
91 |
+
```
|
92 |
+
|
93 |
+
**Loss**:
|
94 |
+
|
95 |
+
`sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss`
|
96 |
+
|
97 |
+
Parameters of the fit()-Method:
|
98 |
+
```
|
99 |
+
{
|
100 |
+
"epochs": 20,
|
101 |
+
"evaluation_steps": 1000,
|
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": 2e-05
|
107 |
+
},
|
108 |
+
"scheduler": "WarmupLinear",
|
109 |
+
"steps_per_epoch": null,
|
110 |
+
"warmup_steps": 150,
|
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: RobertaModel
|
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 |
+
<!--- Describe where people can find more information -->
|
added_tokens.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"</s>": 2,
|
3 |
+
"<mask>": 50264,
|
4 |
+
"<pad>": 1,
|
5 |
+
"<s>": 0,
|
6 |
+
"<unk>": 3
|
7 |
+
}
|
config.json
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"Ngram_size": 32768,
|
3 |
+
"_name_or_path": "/home/ec2-user/.cache/torch/sentence_transformers/Kyleiwaniec_COS_TAPT_n_RoBERTa",
|
4 |
+
"architectures": [
|
5 |
+
"RobertaModel"
|
6 |
+
],
|
7 |
+
"attention_probs_dropout_prob": 0.1,
|
8 |
+
"block_size": 128,
|
9 |
+
"bos_token_id": 0,
|
10 |
+
"classifier_dropout": null,
|
11 |
+
"eos_token_id": 2,
|
12 |
+
"gradient_checkpointing": false,
|
13 |
+
"hidden_act": "gelu",
|
14 |
+
"hidden_dropout_prob": 0.1,
|
15 |
+
"hidden_size": 1024,
|
16 |
+
"initializer_range": 0.02,
|
17 |
+
"intermediate_size": 4096,
|
18 |
+
"layer_norm_eps": 1e-05,
|
19 |
+
"max_position_embeddings": 514,
|
20 |
+
"model_type": "roberta",
|
21 |
+
"num_attention_heads": 16,
|
22 |
+
"num_hidden_Ngram_layers": 1,
|
23 |
+
"num_hidden_layers": 24,
|
24 |
+
"pad_token_id": 1,
|
25 |
+
"position_embedding_type": "absolute",
|
26 |
+
"torch_dtype": "float32",
|
27 |
+
"transformers_version": "4.34.0",
|
28 |
+
"type_vocab_size": 1,
|
29 |
+
"use_cache": true,
|
30 |
+
"vocab_size": 50265
|
31 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "2.2.2",
|
4 |
+
"transformers": "4.34.0",
|
5 |
+
"pytorch": "2.1.0+cu121"
|
6 |
+
}
|
7 |
+
}
|
eval/similarity_evaluation_sts-dev_results.csv
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman
|
2 |
+
0,-1,0.49697139329954926,0.4825046992439753,0.5041840862236489,0.4898646503143872,0.5298679941066685,0.5194756162488348,0.415232268926104,0.4012029141638448
|
3 |
+
1,-1,0.6105816053705728,0.6259381642906058,0.6119457802391968,0.6329557920554172,0.6216162521489205,0.6310730138746142,0.5298615694784903,0.5316280935976543
|
4 |
+
2,-1,0.627889232743929,0.6257670026378056,0.6088617878512252,0.6158396267753897,0.6117585196426631,0.6158396267753897,0.5946381291534514,0.599236946453763
|
5 |
+
3,-1,0.5923863787111332,0.5997504314121638,0.5963591518282073,0.5937597735641542,0.6133336786211053,0.6124163937193842,0.5698021861330682,0.576814769936927
|
6 |
+
4,-1,0.6403088516181896,0.6408292280842298,0.6265897721841569,0.6233707394986018,0.6064451645768036,0.6062545742185742,0.6236893460206414,0.6226860928874007
|
7 |
+
5,-1,0.659583201557967,0.661368626420263,0.6454566441020214,0.6379194799866251,0.6454343114639428,0.645964077668238,0.6318123254688842,0.6363790251114226
|
8 |
+
6,-1,0.658270068736161,0.6560626151834543,0.6438323301276886,0.6356943785002216,0.642272433692988,0.642198521306632,0.6443502760756001,0.6461352393210383
|
9 |
+
7,-1,0.65964373749155,0.6586300399754584,0.6480286720463401,0.6461352393210383,0.6397026533182658,0.6425408446122326,0.6499632425608111,0.6485315024602422
|
10 |
+
8,-1,0.6724810081502879,0.677628983436289,0.6626618661312407,0.6630802429482655,0.6478148041481298,0.6449371077514364,0.6568768022655576,0.6642783745178674
|
11 |
+
9,-1,0.6571687288681491,0.658287716669858,0.653892509091242,0.6481891791546417,0.6423099987021536,0.6408292280842298,0.6435865611351708,0.6495584723770439
|
12 |
+
10,-1,0.6650969725173421,0.669584385754676,0.6590824141104659,0.6545221603082518,0.6430952496897081,0.6392887732090273,0.651594735579449,0.6487026641130424
|
13 |
+
11,-1,0.6577548003109057,0.6634225662538661,0.6539465538638317,0.6456217543626375,0.6417369524914643,0.6372348333754241,0.6441428351445646,0.6449371077514364
|
14 |
+
12,-1,0.6495604678681547,0.645964077668238,0.6397059044066449,0.6350097318890205,0.6328643706846068,0.6300460439578125,0.6406441339960222,0.6408292280842298
|
15 |
+
13,-1,0.6557075046885295,0.6546933219610521,0.6472685513761665,0.6394599348618276,0.6364113875396769,0.6336404386666183,0.6500737668697025,0.6519547355162477
|
16 |
+
14,-1,0.6611204239050532,0.6565761001418552,0.6520045144594881,0.6475045325434405,0.6401604331914832,0.6387752882506266,0.6554753492516101,0.6562337768362545
|
17 |
+
15,-1,0.6547453773324794,0.6564049384890548,0.6456277421569683,0.6432254912234336,0.6329786733946647,0.6351808935418207,0.6475071089006532,0.64716220923784
|
18 |
+
16,-1,0.6546015024673933,0.6552068069194529,0.6465170171910348,0.6420273596538317,0.6356710916166742,0.6368925100698235,0.6481358682068578,0.6476756941962408
|
19 |
+
17,-1,0.6562048442441608,0.6557202918778537,0.6460790408264685,0.6396310965146279,0.6345839539300447,0.63466740858342,0.6510543316716926,0.6500719573354447
|
20 |
+
18,-1,0.6557946409978526,0.6550356452666526,0.6459793778969569,0.6399734198202285,0.63437400947207,0.6332981153610178,0.650419573877459,0.6526393821274488
|
21 |
+
19,-1,0.6561024474465611,0.6570895851002561,0.6464077494746332,0.641513874695431,0.6352225969057199,0.6355232168474213,0.6508822963387766,0.6514412505578469
|
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:6d3071ca5c5cafe3686ead39447abf20cfcc558fb1f99045241828d5a8f774dc
|
3 |
+
size 1421571238
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 512,
|
3 |
+
"do_lower_case": false
|
4 |
+
}
|
similarity_evaluation_sts-test_results.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman
|
2 |
+
-1,-1,0.6744054047228356,0.6750742998718,0.6631685565159673,0.6599136568909711,0.6595100643715024,0.6593615183588794,0.666057660517302,0.6624310997086206
|
special_tokens_map.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": "<s>",
|
3 |
+
"cls_token": "<s>",
|
4 |
+
"eos_token": "</s>",
|
5 |
+
"mask_token": "<mask>",
|
6 |
+
"pad_token": "<pad>",
|
7 |
+
"sep_token": "</s>",
|
8 |
+
"unk_token": "<unk>"
|
9 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"Ngram_vocab_size": 32768,
|
3 |
+
"add_prefix_space": false,
|
4 |
+
"added_tokens_decoder": {
|
5 |
+
"0": {
|
6 |
+
"content": "<s>",
|
7 |
+
"lstrip": false,
|
8 |
+
"normalized": true,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false,
|
11 |
+
"special": true
|
12 |
+
},
|
13 |
+
"1": {
|
14 |
+
"content": "<pad>",
|
15 |
+
"lstrip": false,
|
16 |
+
"normalized": true,
|
17 |
+
"rstrip": false,
|
18 |
+
"single_word": false,
|
19 |
+
"special": true
|
20 |
+
},
|
21 |
+
"2": {
|
22 |
+
"content": "</s>",
|
23 |
+
"lstrip": false,
|
24 |
+
"normalized": true,
|
25 |
+
"rstrip": false,
|
26 |
+
"single_word": false,
|
27 |
+
"special": true
|
28 |
+
},
|
29 |
+
"3": {
|
30 |
+
"content": "<unk>",
|
31 |
+
"lstrip": false,
|
32 |
+
"normalized": true,
|
33 |
+
"rstrip": false,
|
34 |
+
"single_word": false,
|
35 |
+
"special": true
|
36 |
+
},
|
37 |
+
"50264": {
|
38 |
+
"content": "<mask>",
|
39 |
+
"lstrip": true,
|
40 |
+
"normalized": false,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false,
|
43 |
+
"special": true
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"additional_special_tokens": [],
|
47 |
+
"bos_token": "<s>",
|
48 |
+
"clean_up_tokenization_spaces": true,
|
49 |
+
"cls_token": "<s>",
|
50 |
+
"eos_token": "</s>",
|
51 |
+
"errors": "replace",
|
52 |
+
"mask_token": "<mask>",
|
53 |
+
"model_max_length": 512,
|
54 |
+
"pad_token": "<pad>",
|
55 |
+
"sep_token": "</s>",
|
56 |
+
"tokenizer_class": "RobertaTokenizer",
|
57 |
+
"trim_offsets": true,
|
58 |
+
"unk_token": "<unk>"
|
59 |
+
}
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|