TingChenChang
commited on
Commit
•
2825053
1
Parent(s):
a1faf76
Add new SentenceTransformer model.
Browse files- .gitattributes +3 -0
- 1_Pooling/config.json +7 -0
- README.md +129 -0
- config.json +26 -0
- config_sentence_transformers.json +7 -0
- eval/similarity_evaluation_sts-dev_results.csv +27 -0
- modules.json +14 -0
- pytorch_model.bin +3 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +15 -0
- tokenizer.json +3 -0
- tokenizer_config.json +23 -0
- unigram.json +3 -0
.gitattributes
CHANGED
@@ -30,3 +30,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
30 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
31 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
32 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
30 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
31 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
32 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
33 |
+
unigram.json filter=lfs diff=lfs merge=lfs -text
|
34 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
35 |
+
pytorch_model.bin filter=lfs diff=lfs merge=lfs -text
|
1_Pooling/config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 384,
|
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,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 384 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 2166 with parameters:
|
89 |
+
```
|
90 |
+
{'batch_size': 128, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
|
91 |
+
```
|
92 |
+
|
93 |
+
**Loss**:
|
94 |
+
|
95 |
+
`sentence_transformers.losses.MultipleNegativesRankingLoss.MultipleNegativesRankingLoss` with parameters:
|
96 |
+
```
|
97 |
+
{'scale': 20.0, 'similarity_fct': 'cos_sim'}
|
98 |
+
```
|
99 |
+
|
100 |
+
Parameters of the fit()-Method:
|
101 |
+
```
|
102 |
+
{
|
103 |
+
"epochs": 10,
|
104 |
+
"evaluation_steps": 216,
|
105 |
+
"evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
|
106 |
+
"max_grad_norm": 1,
|
107 |
+
"optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
|
108 |
+
"optimizer_params": {
|
109 |
+
"lr": 1e-06
|
110 |
+
},
|
111 |
+
"scheduler": "WarmupLinear",
|
112 |
+
"steps_per_epoch": null,
|
113 |
+
"warmup_steps": 2166,
|
114 |
+
"weight_decay": 0.01
|
115 |
+
}
|
116 |
+
```
|
117 |
+
|
118 |
+
|
119 |
+
## Full Model Architecture
|
120 |
+
```
|
121 |
+
SentenceTransformer(
|
122 |
+
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: BertModel
|
123 |
+
(1): Pooling({'word_embedding_dimension': 384, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
|
124 |
+
)
|
125 |
+
```
|
126 |
+
|
127 |
+
## Citing & Authors
|
128 |
+
|
129 |
+
<!--- Describe where people can find more information -->
|
config.json
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "models/ocnli-cnsd-multi-MiniLM-v2/",
|
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": 384,
|
12 |
+
"initializer_range": 0.02,
|
13 |
+
"intermediate_size": 1536,
|
14 |
+
"layer_norm_eps": 1e-12,
|
15 |
+
"max_position_embeddings": 512,
|
16 |
+
"model_type": "bert",
|
17 |
+
"num_attention_heads": 12,
|
18 |
+
"num_hidden_layers": 12,
|
19 |
+
"pad_token_id": 0,
|
20 |
+
"position_embedding_type": "absolute",
|
21 |
+
"torch_dtype": "float32",
|
22 |
+
"transformers_version": "4.21.1",
|
23 |
+
"type_vocab_size": 2,
|
24 |
+
"use_cache": true,
|
25 |
+
"vocab_size": 250037
|
26 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "2.0.0",
|
4 |
+
"transformers": "4.7.0",
|
5 |
+
"pytorch": "1.9.0+cu102"
|
6 |
+
}
|
7 |
+
}
|
eval/similarity_evaluation_sts-dev_results.csv
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman
|
2 |
+
0,216,0.8420036101577641,0.8477162107433588,0.8106965591576962,0.8197193414495011,0.8092609853788798,0.8179553411674493,0.7519864808899812,0.7683260519465919
|
3 |
+
0,432,0.8432265936136198,0.8483197014011108,0.8101926464070567,0.8195105193229808,0.8088002504514279,0.8178336707955142,0.7549897264280511,0.7714115354031804
|
4 |
+
0,648,0.8434345875217619,0.8482651041535004,0.8089602546769898,0.8186237755489868,0.8075672403936979,0.8169398536370678,0.7547271215808249,0.7714713019056929
|
5 |
+
0,864,0.841563052174142,0.8466586879616355,0.8061854312834752,0.8155760104650602,0.8050221966401055,0.81420357349539,0.7524086876443303,0.7695845866190143
|
6 |
+
0,1080,0.840230142733557,0.8448760714801591,0.8041759077478932,0.8134109659186369,0.8030426976035514,0.8121704893947274,0.7505250411417995,0.7680108492313532
|
7 |
+
0,1296,0.8380605379479314,0.8424778411488563,0.8014610340574587,0.8104476502016563,0.8003918710447693,0.8094873487887786,0.7477365986807009,0.7650037663370429
|
8 |
+
0,1512,0.8376050393895086,0.8424599545199523,0.7996646572060943,0.8089466844464998,0.7984183105808597,0.8076428907633734,0.7465113350704993,0.7625443619135865
|
9 |
+
0,1728,0.8361534651882101,0.8410234838670125,0.7970869905726814,0.8059571775388996,0.7959217125946396,0.8049193849503605,0.7430154396959366,0.7600955273544253
|
10 |
+
0,1944,0.8313883603926658,0.8360067332610265,0.7910333888212726,0.8006052272056177,0.7902262687161201,0.799594049431932,0.7366869047533736,0.7535218699233902
|
11 |
+
0,2160,0.827235455326802,0.8320015987055898,0.7891203197566264,0.7980345555713426,0.7886810385810262,0.7973118645055062,0.735358221690519,0.750991384502041
|
12 |
+
0,-1,0.8271390695731811,0.8318854763479596,0.7890627399177387,0.797960311930541,0.7886143808634505,0.7972159753397546,0.7352887047940263,0.7507858130002387
|
13 |
+
0,216,0.8411487843824286,0.8471253374297658,0.8106198720523566,0.8195390424212514,0.8091869387162447,0.8178213716677323,0.7503583049382798,0.7666419720212299
|
14 |
+
0,432,0.8414797568536371,0.8473193390435743,0.8107387096436172,0.81964881240095,0.8093124524759123,0.8180574317798547,0.7510447955130188,0.7674027583994651
|
15 |
+
0,648,0.8419278217382398,0.8476730379066542,0.8108296026119635,0.8197674982456907,0.8094082076401231,0.8180509474131725,0.7519958712741737,0.768305186885048
|
16 |
+
0,864,0.8424022408104653,0.8480086456615539,0.8108375660687243,0.8198357700708442,0.8094117294221671,0.818091405475969,0.7530686001231317,0.7694163909534381
|
17 |
+
0,1080,0.8428292301211644,0.8482082855538595,0.8107186124632874,0.8198796151558223,0.8092799846091845,0.8181619602091681,0.7543208572432004,0.7706462863074403
|
18 |
+
0,1296,0.8432072860356189,0.8483129298014214,0.810514497094325,0.8199485196441711,0.8090981923686018,0.8181567739736365,0.7554612720996471,0.771767485492661
|
19 |
+
0,1512,0.8432884800123164,0.8481762340030274,0.8099578464895437,0.8195109488774277,0.8085581738244885,0.8177522186097962,0.7558723044936776,0.772553447025959
|
20 |
+
0,1728,0.8431016207569118,0.8478487320395043,0.8091551871590602,0.8186812821067967,0.8077527817558212,0.8171157137028975,0.7557509793761882,0.7724219200798936
|
21 |
+
0,1944,0.843000078208571,0.8477134256038226,0.8086256500788442,0.8181226485362433,0.8072662160745225,0.816605528171153,0.7556463363865691,0.7724639280512333
|
22 |
+
0,2160,0.8429364841906399,0.8475202999475956,0.8080915119461467,0.8176306136310965,0.8067522189544144,0.8160559791992851,0.7557201174053868,0.7724887095307975
|
23 |
+
0,-1,0.8429261427476151,0.8475312992326165,0.8080984155907812,0.817652580430085,0.8067576384161439,0.8160996622602396,0.7556737386454906,0.7724511857423662
|
24 |
+
1,216,0.8425177003749148,0.8470659329167659,0.8078989364228251,0.8173012100290717,0.8065825193488042,0.8158453278286679,0.7551257172477217,0.7717541511733772
|
25 |
+
1,432,0.8422631479234384,0.8467123898118666,0.8072056673608483,0.8165424295375284,0.8059439830734247,0.8151952321806387,0.7552834670030084,0.7718855101715042
|
26 |
+
1,648,0.8418332208801085,0.8463782769598794,0.8065002062185747,0.8158357619098844,0.8053030031620603,0.8145536864613482,0.7547273079803445,0.77173195758822
|
27 |
+
1,864,0.8416471304313258,0.8461856489048937,0.8059927638452845,0.8151941592896871,0.8048280341059416,0.8140796765247217,0.7546506823090642,0.771890422154738
|
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:caa829c4756bb62e66a31398a54b2d84a6f97054b1656bd3c60d7f70b2ef6401
|
3 |
+
size 470684465
|
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,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b60b6b43406a48bf3638526314f3d232d97058bc93472ff2de930d43686fa441
|
3 |
+
size 17082913
|
tokenizer_config.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": "<s>",
|
3 |
+
"cls_token": "<s>",
|
4 |
+
"do_lower_case": true,
|
5 |
+
"eos_token": "</s>",
|
6 |
+
"mask_token": {
|
7 |
+
"__type": "AddedToken",
|
8 |
+
"content": "<mask>",
|
9 |
+
"lstrip": true,
|
10 |
+
"normalized": true,
|
11 |
+
"rstrip": false,
|
12 |
+
"single_word": false
|
13 |
+
},
|
14 |
+
"model_max_length": 512,
|
15 |
+
"name_or_path": "models/ocnli-cnsd-multi-MiniLM-v2/",
|
16 |
+
"pad_token": "<pad>",
|
17 |
+
"sep_token": "</s>",
|
18 |
+
"special_tokens_map_file": null,
|
19 |
+
"strip_accents": null,
|
20 |
+
"tokenize_chinese_chars": true,
|
21 |
+
"tokenizer_class": "BertTokenizer",
|
22 |
+
"unk_token": "<unk>"
|
23 |
+
}
|
unigram.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:71b44701d7efd054205115acfa6ef126c5d2f84bd3affe0c59e48163674d19a6
|
3 |
+
size 14763234
|