Shilong Dai
commited on
Commit
•
dede09f
1
Parent(s):
6996058
Adds files
Browse files- 1_Pooling/config.json +7 -0
- README.md +126 -0
- config.json +32 -0
- config_sentence_transformers.json +7 -0
- eval/.ipynb_checkpoints/Information-Retrieval_evaluation_results-checkpoint.csv +2 -0
- eval/Information-Retrieval_evaluation_results.csv +11 -0
- modules.json +14 -0
- pytorch_model.bin +3 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +64 -0
- vocab.txt +0 -0
1_Pooling/config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 1024,
|
3 |
+
"pooling_mode_cls_token": true,
|
4 |
+
"pooling_mode_mean_tokens": false,
|
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 |
+
def cls_pooling(model_output, attention_mask):
|
47 |
+
return model_output[0][:,0]
|
48 |
+
|
49 |
+
|
50 |
+
# Sentences we want sentence embeddings for
|
51 |
+
sentences = ['This is an example sentence', 'Each sentence is converted']
|
52 |
+
|
53 |
+
# Load model from HuggingFace Hub
|
54 |
+
tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
|
55 |
+
model = AutoModel.from_pretrained('{MODEL_NAME}')
|
56 |
+
|
57 |
+
# Tokenize sentences
|
58 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
59 |
+
|
60 |
+
# Compute token embeddings
|
61 |
+
with torch.no_grad():
|
62 |
+
model_output = model(**encoded_input)
|
63 |
+
|
64 |
+
# Perform pooling. In this case, cls pooling.
|
65 |
+
sentence_embeddings = cls_pooling(model_output, encoded_input['attention_mask'])
|
66 |
+
|
67 |
+
print("Sentence embeddings:")
|
68 |
+
print(sentence_embeddings)
|
69 |
+
```
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
## Evaluation Results
|
74 |
+
|
75 |
+
<!--- Describe how your model was evaluated -->
|
76 |
+
|
77 |
+
For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name={MODEL_NAME})
|
78 |
+
|
79 |
+
|
80 |
+
## Training
|
81 |
+
The model was trained with the parameters:
|
82 |
+
|
83 |
+
**DataLoader**:
|
84 |
+
|
85 |
+
`torch.utils.data.dataloader.DataLoader` of length 707 with parameters:
|
86 |
+
```
|
87 |
+
{'batch_size': 40, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
|
88 |
+
```
|
89 |
+
|
90 |
+
**Loss**:
|
91 |
+
|
92 |
+
`sentence_transformers.losses.MultipleNegativesRankingLoss.MultipleNegativesRankingLoss` with parameters:
|
93 |
+
```
|
94 |
+
{'scale': 20.0, 'similarity_fct': 'cos_sim'}
|
95 |
+
```
|
96 |
+
|
97 |
+
Parameters of the fit()-Method:
|
98 |
+
```
|
99 |
+
{
|
100 |
+
"epochs": 10,
|
101 |
+
"evaluation_steps": 0,
|
102 |
+
"evaluator": "sentence_transformers.evaluation.InformationRetrievalEvaluator.InformationRetrievalEvaluator",
|
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": 100,
|
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': True}) with Transformer model: BertModel
|
120 |
+
(1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, '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 -->
|
config.json
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/root/.cache/torch/sentence_transformers/llmrails_ember-v1/",
|
3 |
+
"architectures": [
|
4 |
+
"BertModel"
|
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": 1024,
|
12 |
+
"id2label": {
|
13 |
+
"0": "LABEL_0"
|
14 |
+
},
|
15 |
+
"initializer_range": 0.02,
|
16 |
+
"intermediate_size": 4096,
|
17 |
+
"label2id": {
|
18 |
+
"LABEL_0": 0
|
19 |
+
},
|
20 |
+
"layer_norm_eps": 1e-12,
|
21 |
+
"max_position_embeddings": 512,
|
22 |
+
"model_type": "bert",
|
23 |
+
"num_attention_heads": 16,
|
24 |
+
"num_hidden_layers": 24,
|
25 |
+
"pad_token_id": 0,
|
26 |
+
"position_embedding_type": "absolute",
|
27 |
+
"torch_dtype": "float32",
|
28 |
+
"transformers_version": "4.34.1",
|
29 |
+
"type_vocab_size": 2,
|
30 |
+
"use_cache": true,
|
31 |
+
"vocab_size": 30522
|
32 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "2.2.2",
|
4 |
+
"transformers": "4.28.1",
|
5 |
+
"pytorch": "1.13.0+cu117"
|
6 |
+
}
|
7 |
+
}
|
eval/.ipynb_checkpoints/Information-Retrieval_evaluation_results-checkpoint.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
epoch,steps,cos_sim-Accuracy@2,cos_sim-Accuracy@3,cos_sim-Precision@2,cos_sim-Recall@2,cos_sim-Precision@3,cos_sim-Recall@3,cos_sim-MRR@2,cos_sim-MRR@3,cos_sim-NDCG@2,cos_sim-NDCG@3,cos_sim-MAP@2,cos_sim-MAP@3,dot_score-Accuracy@2,dot_score-Accuracy@3,dot_score-Precision@2,dot_score-Recall@2,dot_score-Precision@3,dot_score-Recall@3,dot_score-MRR@2,dot_score-MRR@3,dot_score-NDCG@2,dot_score-NDCG@3,dot_score-MAP@2,dot_score-MAP@3
|
2 |
+
0,-1,0.786,0.836,0.725,0.41561682557208873,0.632,0.5025919050247998,0.761,0.7776666666666665,0.7274892382408401,0.7234027733369421,0.7125,0.6920555555555555,0.798,0.842,0.728,0.4199918255720887,0.6273333333333333,0.5010919050247997,0.768,0.7826666666666665,0.7302629438553092,0.7215898868321315,0.713,0.6884444444444444
|
eval/Information-Retrieval_evaluation_results.csv
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
epoch,steps,cos_sim-Accuracy@2,cos_sim-Accuracy@3,cos_sim-Precision@2,cos_sim-Recall@2,cos_sim-Precision@3,cos_sim-Recall@3,cos_sim-MRR@2,cos_sim-MRR@3,cos_sim-NDCG@2,cos_sim-NDCG@3,cos_sim-MAP@2,cos_sim-MAP@3,dot_score-Accuracy@2,dot_score-Accuracy@3,dot_score-Precision@2,dot_score-Recall@2,dot_score-Precision@3,dot_score-Recall@3,dot_score-MRR@2,dot_score-MRR@3,dot_score-NDCG@2,dot_score-NDCG@3,dot_score-MAP@2,dot_score-MAP@3
|
2 |
+
0,-1,0.786,0.836,0.725,0.41561682557208873,0.632,0.5025919050247998,0.761,0.7776666666666665,0.7274892382408401,0.7234027733369421,0.7125,0.6920555555555555,0.798,0.842,0.728,0.4199918255720887,0.6273333333333333,0.5010919050247997,0.768,0.7826666666666665,0.7302629438553092,0.7215898868321315,0.713,0.6884444444444444
|
3 |
+
1,-1,0.792,0.844,0.722,0.4120584922387554,0.6253333333333333,0.5017419050247998,0.769,0.786333333333333,0.7274310652527419,0.7214298121189583,0.7105,0.6867222222222221,0.794,0.854,0.715,0.41153349223875535,0.6233333333333334,0.49912523835813305,0.764,0.7839999999999998,0.7192995933250874,0.7161653355461067,0.7,0.6788333333333334
|
4 |
+
2,-1,0.792,0.834,0.723,0.41603349223875535,0.624,0.49796690502479973,0.769,0.7829999999999999,0.7282047708672111,0.7196515586578535,0.7115,0.6868333333333334,0.784,0.834,0.721,0.41703349223875535,0.622,0.49793357169146646,0.761,0.7776666666666664,0.7248470045540256,0.7167630710706907,0.7095,0.6841111111111111
|
5 |
+
3,-1,0.79,0.832,0.718,0.40955015890542207,0.6226666666666666,0.4977335716914664,0.764,0.7779999999999998,0.7225258877106183,0.7163430927842974,0.705,0.6825,0.776,0.83,0.706,0.4021334922387554,0.6193333333333333,0.4941002383581331,0.761,0.7789999999999998,0.7150517754212367,0.7133938756354776,0.6985,0.6786666666666668
|
6 |
+
4,-1,0.788,0.832,0.72,0.4083168255720887,0.624,0.4968002383581331,0.766,0.7806666666666666,0.7254310652527419,0.718241191059222,0.709,0.6845,0.78,0.822,0.713,0.406500158905422,0.6153333333333333,0.48854190502479977,0.763,0.7769999999999999,0.7204677147225202,0.7108012281050157,0.7045,0.6773888888888889
|
7 |
+
5,-1,0.794,0.842,0.716,0.41035849223875537,0.622,0.49775023835813303,0.762,0.7779999999999999,0.7191681213974328,0.7146432262568708,0.7,0.6785555555555556,0.794,0.842,0.713,0.409150158905422,0.616,0.4938057939136887,0.769,0.7849999999999998,0.7200151259514584,0.7126128614760423,0.7005,0.6751666666666665
|
8 |
+
6,-1,0.776,0.82,0.705,0.40117238112764425,0.612,0.4905696828025775,0.755,0.7696666666666665,0.7115625371803966,0.7058558458165342,0.6945,0.6716666666666666,0.782,0.82,0.707,0.40187238112764423,0.6093333333333334,0.48663079391368863,0.759,0.7716666666666665,0.7135625371803966,0.7040330941931987,0.6955,0.6694444444444444
|
9 |
+
7,-1,0.774,0.828,0.71,0.4034501589054221,0.614,0.49326412724702196,0.752,0.7699999999999998,0.7145258877106182,0.7075484037989945,0.699,0.6727777777777777,0.778,0.826,0.711,0.4061168255720887,0.614,0.4934307939136886,0.755,0.7709999999999999,0.7157521820961493,0.7083807661100918,0.6995,0.6739444444444443
|
10 |
+
8,-1,0.786,0.816,0.717,0.40840015890542203,0.614,0.48805579391368864,0.766,0.7759999999999999,0.7235625371803965,0.7105357528291434,0.707,0.6781111111111111,0.784,0.818,0.71,0.4055057144609776,0.6146666666666666,0.48976412724702195,0.764,0.7753333333333332,0.7176940091080513,0.7098669640688429,0.7,0.6768333333333333
|
11 |
+
9,-1,0.786,0.828,0.71,0.4060057144609776,0.6173333333333333,0.4930641272470219,0.764,0.7779999999999999,0.7172414203369893,0.7122232228174816,0.699,0.6771111111111111,0.794,0.822,0.715,0.40917238112764426,0.614,0.4899807939136886,0.769,0.7783333333333333,0.7215625371803965,0.710337521081645,0.7025,0.6763888888888889
|
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:74ad1b39955b087a6b578ba0db790af95707e28e16feda07e72d62cdc2a3022e
|
3 |
+
size 1340699369
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 512,
|
3 |
+
"do_lower_case": true
|
4 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"mask_token": "[MASK]",
|
4 |
+
"pad_token": "[PAD]",
|
5 |
+
"sep_token": "[SEP]",
|
6 |
+
"unk_token": "[UNK]"
|
7 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"added_tokens_decoder": {
|
3 |
+
"0": {
|
4 |
+
"content": "[PAD]",
|
5 |
+
"lstrip": false,
|
6 |
+
"normalized": false,
|
7 |
+
"rstrip": false,
|
8 |
+
"single_word": false,
|
9 |
+
"special": true
|
10 |
+
},
|
11 |
+
"100": {
|
12 |
+
"content": "[UNK]",
|
13 |
+
"lstrip": false,
|
14 |
+
"normalized": false,
|
15 |
+
"rstrip": false,
|
16 |
+
"single_word": false,
|
17 |
+
"special": true
|
18 |
+
},
|
19 |
+
"101": {
|
20 |
+
"content": "[CLS]",
|
21 |
+
"lstrip": false,
|
22 |
+
"normalized": false,
|
23 |
+
"rstrip": false,
|
24 |
+
"single_word": false,
|
25 |
+
"special": true
|
26 |
+
},
|
27 |
+
"102": {
|
28 |
+
"content": "[SEP]",
|
29 |
+
"lstrip": false,
|
30 |
+
"normalized": false,
|
31 |
+
"rstrip": false,
|
32 |
+
"single_word": false,
|
33 |
+
"special": true
|
34 |
+
},
|
35 |
+
"103": {
|
36 |
+
"content": "[MASK]",
|
37 |
+
"lstrip": false,
|
38 |
+
"normalized": false,
|
39 |
+
"rstrip": false,
|
40 |
+
"single_word": false,
|
41 |
+
"special": true
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"clean_up_tokenization_spaces": true,
|
45 |
+
"cls_token": "[CLS]",
|
46 |
+
"do_basic_tokenize": true,
|
47 |
+
"do_lower_case": true,
|
48 |
+
"mask_token": "[MASK]",
|
49 |
+
"max_length": 512,
|
50 |
+
"model_max_length": 512,
|
51 |
+
"never_split": null,
|
52 |
+
"pad_to_multiple_of": null,
|
53 |
+
"pad_token": "[PAD]",
|
54 |
+
"pad_token_type_id": 0,
|
55 |
+
"padding_side": "right",
|
56 |
+
"sep_token": "[SEP]",
|
57 |
+
"stride": 0,
|
58 |
+
"strip_accents": null,
|
59 |
+
"tokenize_chinese_chars": true,
|
60 |
+
"tokenizer_class": "BertTokenizer",
|
61 |
+
"truncation_side": "right",
|
62 |
+
"truncation_strategy": "longest_first",
|
63 |
+
"unk_token": "[UNK]"
|
64 |
+
}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|