medmediani
commited on
Commit
·
2a9b22f
1
Parent(s):
c6ec4bb
first commit
Browse files- model/1_Pooling/config.json +7 -0
- model/README.md +126 -0
- model/config.json +25 -0
- model/config_sentence_transformers.json +7 -0
- model/eval/similarity_evaluation_results.csv +25 -0
- model/modules.json +14 -0
- model/pytorch_model.bin +3 -0
- model/sentence_bert_config.json +4 -0
- model/special_tokens_map.json +7 -0
- model/tokenizer.json +0 -0
- model/tokenizer_config.json +20 -0
- model/vocab.txt +0 -0
model/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 |
+
}
|
model/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 768 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 2301 with parameters:
|
89 |
+
```
|
90 |
+
{'batch_size': None, 'sampler': 'torch.utils.data.sampler.SequentialSampler', 'batch_sampler': 'nkwdataset.BatchNegSampler'}
|
91 |
+
```
|
92 |
+
|
93 |
+
**Loss**:
|
94 |
+
|
95 |
+
`sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss`
|
96 |
+
|
97 |
+
Parameters of the fit()-Method:
|
98 |
+
```
|
99 |
+
{
|
100 |
+
"epochs": 1,
|
101 |
+
"evaluation_steps": 100,
|
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": 100,
|
111 |
+
"weight_decay": 0.01
|
112 |
+
}
|
113 |
+
```
|
114 |
+
|
115 |
+
|
116 |
+
## Full Model Architecture
|
117 |
+
```
|
118 |
+
SentenceTransformer(
|
119 |
+
(0): Transformer({'max_seq_length': 1024, 'do_lower_case': False}) with Transformer model: BertModel
|
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 |
+
|
124 |
+
## Citing & Authors
|
125 |
+
|
126 |
+
<!--- Describe where people can find more information -->
|
model/config.json
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "aubmindlab/bert-base-arabertv02",
|
3 |
+
"architectures": [
|
4 |
+
"BertModel"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"hidden_act": "gelu",
|
9 |
+
"hidden_dropout_prob": 0.1,
|
10 |
+
"hidden_size": 768,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"intermediate_size": 3072,
|
13 |
+
"layer_norm_eps": 1e-12,
|
14 |
+
"max_position_embeddings": 512,
|
15 |
+
"model_type": "bert",
|
16 |
+
"num_attention_heads": 12,
|
17 |
+
"num_hidden_layers": 12,
|
18 |
+
"pad_token_id": 0,
|
19 |
+
"position_embedding_type": "absolute",
|
20 |
+
"torch_dtype": "float32",
|
21 |
+
"transformers_version": "4.27.4",
|
22 |
+
"type_vocab_size": 2,
|
23 |
+
"use_cache": true,
|
24 |
+
"vocab_size": 64000
|
25 |
+
}
|
model/config_sentence_transformers.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "2.2.2",
|
4 |
+
"transformers": "4.27.4",
|
5 |
+
"pytorch": "2.0.0+cu117"
|
6 |
+
}
|
7 |
+
}
|
model/eval/similarity_evaluation_results.csv
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman
|
2 |
+
0,100,-0.0014084016071803707,-0.005974646349259352,-0.0011148677844655234,-0.006823761697462621,-0.0031921576983014958,-0.008462784423718384,-0.0013527167022492263,-0.006134298479750079
|
3 |
+
0,200,-0.01439619727472125,-0.015789587420051498,-0.012616585674178301,-0.015161242838654849,-0.014894045645202003,-0.018851901064299167,-0.01659789702901683,-0.017743234505539794
|
4 |
+
0,300,-0.008738723873515358,-0.0100447544643897,-0.009797046327609193,-0.014052737089441053,-0.009526474602157036,-0.011658422628695866,-0.009112346677298289,-0.009101418491561469
|
5 |
+
0,400,-0.01313536882963247,-0.014598666539196383,-0.01593316328197991,-0.01811629200418959,-0.01672933061385762,-0.01799174910465491,-0.013151743118259781,-0.01439967997381517
|
6 |
+
0,500,-0.008869364236502473,-0.008790614520590231,-0.010174086262157392,-0.01022940726438435,-0.010878016135249292,-0.010369907390132294,-0.008818899113654025,-0.008713625544425613
|
7 |
+
0,600,-0.01363836263409382,-0.011750128164693528,-0.015303395037270587,-0.01412679926768333,-0.01703749699271561,-0.01486509395290605,-0.015494911088842647,-0.013471547951506135
|
8 |
+
0,700,-0.014600459643236731,-0.014662057250647436,-0.017164554205655037,-0.016331025037158265,-0.017270337006921908,-0.017400432885208553,-0.014055988281518,-0.014777249256824762
|
9 |
+
0,800,-0.014444018529123652,-0.014322977178515894,-0.016619473259190404,-0.017732101068072995,-0.014759393356356036,-0.014067118977203093,-0.014187340072441176,-0.014168537092308909
|
10 |
+
0,900,-0.012059366161042934,-0.00946247318806493,-0.013230994399252573,-0.012596806198439644,-0.015186059366421829,-0.01256792834710906,-0.010968171115246207,-0.009087741877910121
|
11 |
+
0,1000,-0.016443943331842334,-0.01595262486862947,-0.019305602087822143,-0.01957981682054613,-0.017488193995684364,-0.015245016038582321,-0.017474747265768326,-0.01612494672066406
|
12 |
+
0,1100,-0.020416071728638133,-0.02148368288162378,-0.021261296776430773,-0.024522533165576222,-0.020594486767758848,-0.020248150965082434,-0.0208427323676512,-0.021081160640394538
|
13 |
+
0,1200,-0.017012769979586274,-0.016410660138166833,-0.019394052196309144,-0.019055085926952306,-0.02010393619340861,-0.017694564214127836,-0.017026481886912043,-0.016061502585886536
|
14 |
+
0,1300,-0.013486619942277862,-0.012099696435853461,-0.015135997923372509,-0.015821911853236614,-0.017733783338205085,-0.015674052236071614,-0.013124888965812546,-0.012261346698411378
|
15 |
+
0,1400,-0.014441627263798508,-0.011455310368016792,-0.015927679742322686,-0.015247395943780537,-0.016586389912067852,-0.012854957288182142,-0.014352019025621271,-0.0113602548307323
|
16 |
+
0,1500,-0.02077603461024176,-0.01710888452574343,-0.019979384928271213,-0.021134742597521836,-0.022214899094120978,-0.0165309200178185,-0.020667259854019248,-0.01742850041980119
|
17 |
+
0,1600,-0.02198034359783125,-0.02119235835883809,-0.02243668213380327,-0.02359528327966424,-0.021657520619871418,-0.019147644113161326,-0.02240726677808149,-0.021254780447558932
|
18 |
+
0,1700,-0.020417976276599283,-0.016966399859052565,-0.02095824982049848,-0.021055550786257607,-0.02195026237359019,-0.017707957897320572,-0.020353056162476957,-0.016732389555688888
|
19 |
+
0,1800,-0.020990097092713357,-0.01911667438317952,-0.02172250613608771,-0.022940819572541866,-0.022214673669246003,-0.018708375874130656,-0.020740607214797924,-0.018620962268669983
|
20 |
+
0,1900,-0.021400268891744206,-0.017907803727339883,-0.02155435083718565,-0.021807415114090713,-0.02165165545936554,-0.01766511672327363,-0.020884045931872916,-0.017178921483798574
|
21 |
+
0,2000,-0.0206320959150904,-0.01787171265489736,-0.0221929530985392,-0.021354589346700287,-0.021605489099969614,-0.01814777376481024,-0.02039922693742446,-0.01783710600153296
|
22 |
+
0,2100,-0.019802237769944137,-0.016445749043551332,-0.020892064963634077,-0.02024704449503452,-0.020499812514340496,-0.017191359154443267,-0.01991631913362716,-0.016848062506809428
|
23 |
+
0,2200,-0.01939068287472302,-0.014535049360356227,-0.02020889988479752,-0.018989008603544237,-0.020027487013542136,-0.01539548588862228,-0.019217594681193696,-0.01451343654992022
|
24 |
+
0,2300,-0.019515997505572594,-0.01445528622513276,-0.020416274630010528,-0.018983438147986097,-0.020459416083599302,-0.015753158839636242,-0.01935326935442082,-0.014398178058104286
|
25 |
+
0,-1,-0.019516074040339688,-0.01445404042532921,-0.02041634605574272,-0.018983085613887368,-0.020459412230105216,-0.01575297396948282,-0.01935335432409336,-0.014399991239273631
|
model/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 |
+
]
|
model/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bd99a84a7b0b8d74d212f8e9f29a3c7b86f3185948b490afe389eed25c194a43
|
3 |
+
size 540844589
|
model/sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 1024,
|
3 |
+
"do_lower_case": false
|
4 |
+
}
|
model/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 |
+
}
|
model/tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
model/tokenizer_config.json
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"do_basic_tokenize": true,
|
4 |
+
"do_lower_case": false,
|
5 |
+
"mask_token": "[MASK]",
|
6 |
+
"max_len": 512,
|
7 |
+
"model_max_length": 512,
|
8 |
+
"never_split": [
|
9 |
+
"[بريد]",
|
10 |
+
"[مستخدم]",
|
11 |
+
"[رابط]"
|
12 |
+
],
|
13 |
+
"pad_token": "[PAD]",
|
14 |
+
"sep_token": "[SEP]",
|
15 |
+
"special_tokens_map_file": null,
|
16 |
+
"strip_accents": null,
|
17 |
+
"tokenize_chinese_chars": true,
|
18 |
+
"tokenizer_class": "BertTokenizer",
|
19 |
+
"unk_token": "[UNK]"
|
20 |
+
}
|
model/vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|