d1mitriz commited on
Commit
29878be
1 Parent(s): cc2c981

Greek Media SBERT upload to hub

Browse files
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,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - el
4
+ pipeline_tag: sentence-similarity
5
+ tags:
6
+ - sentence-transformers
7
+ - feature-extraction
8
+ - sentence-similarity
9
+ - transformers
10
+ metrics:
11
+ - accuracy_cosinus
12
+ - accuracy_euclidean
13
+ - accuracy_manhattan
14
+ model-index:
15
+ - name: st-greek-media-bert-base-uncased
16
+ results: [
17
+ {name: STSbenchmark, value: 0.9563965089445283, limit: 0.0, unit: "%", metric: accuracy_cosinus},
18
+ {name: STSbenchmark, value: 0.9566394253292384, limit: 0.0, unit: "%", metric: accuracy_euclidean},
19
+ {name: STSbenchmark, value: 0.9565353183072198, limit: 0.0, unit: "%", metric: accuracy_manhattan}
20
+ ]
21
+ ---
22
+
23
+ # Greek Media SBERT (uncased)
24
+ ## Sentence Transformer
25
+
26
+ This is a [sentence-transformers](https://www.SBERT.net) based on the [Greek Media BERT (uncased)](https://huggingface.co/dimitriz/greek-media-bert-base-uncased) model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
27
+
28
+ <!--- Describe your model here -->
29
+
30
+ ## Usage (Sentence-Transformers)
31
+
32
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
33
+
34
+ ```
35
+ pip install -U sentence-transformers
36
+ ```
37
+
38
+ Then you can use the model like this:
39
+
40
+ ```python
41
+ from sentence_transformers import SentenceTransformer
42
+ sentences = ["This is an example sentence", "Each sentence is converted"]
43
+
44
+ model = SentenceTransformer('dimitriz/st-greek-media-bert-base-uncased')
45
+ embeddings = model.encode(sentences)
46
+ print(embeddings)
47
+ ```
48
+
49
+
50
+
51
+ ## Usage (HuggingFace Transformers)
52
+ 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.
53
+
54
+ ```python
55
+ from transformers import AutoTokenizer, AutoModel
56
+ import torch
57
+
58
+
59
+ #Mean Pooling - Take attention mask into account for correct averaging
60
+ def mean_pooling(model_output, attention_mask):
61
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
62
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
63
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
64
+
65
+
66
+ # Sentences we want sentence embeddings for
67
+ sentences = ['This is an example sentence', 'Each sentence is converted']
68
+
69
+ # Load model from HuggingFace Hub
70
+ tokenizer = AutoTokenizer.from_pretrained('dimitriz/st-greek-media-bert-base-uncased')
71
+ model = AutoModel.from_pretrained('dimitriz/st-greek-media-bert-base-uncased')
72
+
73
+ # Tokenize sentences
74
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
75
+
76
+ # Compute token embeddings
77
+ with torch.no_grad():
78
+ model_output = model(**encoded_input)
79
+
80
+ # Perform pooling. In this case, mean pooling.
81
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
82
+
83
+ print("Sentence embeddings:")
84
+ print(sentence_embeddings)
85
+ ```
86
+
87
+
88
+
89
+ ## Evaluation Results
90
+
91
+ <!--- Describe how your model was evaluated -->
92
+
93
+ For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name=dimitriz/st-greek-media-bert-base-uncased)
94
+
95
+
96
+ ## Training
97
+ The model was trained on a custom dataset containing triplets from the **combined** Greek 'internet', 'social-media' and 'press' domains, described in the paper [DACL](https://...).
98
+ - The dataset was created by sampling triplets of sentences from the same domain, where the first two sentences are more similar than the third one.
99
+ - Training objective was to maximize the similarity between the first two sentences and minimize the similarity between the first and the third sentence.
100
+ - The model was trained for 3 epochs with a batch size of 16 and a maximum sequence length of 512 tokens.
101
+ - The model was trained on a single NVIDIA RTX A6000 GPU with 48GB of memory.
102
+
103
+ The model was trained with the parameters:
104
+
105
+ **DataLoader**:
106
+
107
+ `torch.utils.data.dataloader.DataLoader` of length 10807 with parameters:
108
+ ```
109
+ {'batch_size': 16, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
110
+ ```
111
+
112
+ **Loss**:
113
+
114
+ `sentence_transformers.losses.TripletLoss.TripletLoss` with parameters:
115
+ ```
116
+ {'distance_metric': 'TripletDistanceMetric.EUCLIDEAN', 'triplet_margin': 5}
117
+ ```
118
+
119
+ Parameters of the fit()-Method:
120
+ ```
121
+ {
122
+ "epochs": 3,
123
+ "evaluation_steps": 1000,
124
+ "evaluator": "sentence_transformers.evaluation.TripletEvaluator.TripletEvaluator",
125
+ "max_grad_norm": 1,
126
+ "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
127
+ "optimizer_params": {
128
+ "lr": 2e-05
129
+ },
130
+ "scheduler": "WarmupLinear",
131
+ "steps_per_epoch": null,
132
+ "warmup_steps": 17290,
133
+ "weight_decay": 0.01
134
+ }
135
+ ```
136
+
137
+
138
+ ## Full Model Architecture
139
+ ```
140
+ SentenceTransformer(
141
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
142
+ (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})
143
+ )
144
+ ```
145
+
146
+ ## Citing & Authors
147
+
148
+ ```@inproceedings{...,
149
+ title={DACL},
150
+ author={Zaikis et al.},
151
+ booktitle={...},
152
+ year={2023}
153
+ }
154
+ ```
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/home/dimitriz/.cache/torch/sentence_transformers/dimitriz_greek-media-bert-base-uncased",
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
+ "output_past": true,
19
+ "pad_token_id": 0,
20
+ "position_embedding_type": "absolute",
21
+ "torch_dtype": "float32",
22
+ "transformers_version": "4.28.0",
23
+ "type_vocab_size": 2,
24
+ "use_cache": true,
25
+ "vocab_size": 35000
26
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.2.2",
4
+ "transformers": "4.28.0",
5
+ "pytorch": "2.0.0+cu118"
6
+ }
7
+ }
eval/triplet_evaluation_results.csv ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ epoch,steps,accuracy_cosinus,accuracy_manhattan,accuracy_euclidean
2
+ 0,1000,0.7708083910259746,0.7698714278278069,0.7704960699599188
3
+ 0,2000,0.8108375409921399,0.8136310794163066,0.8141342633560633
4
+ 0,3000,0.8408897680148526,0.8418961358943661,0.8424166710044593
5
+ 0,4000,0.8605312928357017,0.8604792393246925,0.8606874533687298
6
+ 0,5000,0.8751930317699929,0.8756268110284039,0.875748269220759
7
+ 0,6000,0.8834695400204744,0.8842503426856142,0.8839553727898947
8
+ 0,7000,0.8923706904030677,0.8926656602987871,0.8926309579581143
9
+ 0,8000,0.8975413391633266,0.897714850866691,0.8978016067183732
10
+ 0,9000,0.9009248173789323,0.901983238769455,0.9020526434508007
11
+ 0,10000,0.9048461818749675,0.9053146634740513,0.9053493658147242
12
+ 0,-1,0.9095483490361425,0.9099994794648899,0.9103812052122916
13
+ 1,1000,0.9107976333003661,0.9109190914927212,0.9110405496850763
14
+ 1,2000,0.9121857269272813,0.912255131608627,0.9129491784220846
15
+ 1,3000,0.9159335797199522,0.9166102753630733,0.9167317335554284
16
+ 1,4000,0.9201499141117069,0.9200458070896882,0.9203234258150712
17
+ 1,5000,0.9212950913539119,0.9217982752936685,0.9219197334860236
18
+ 1,6000,0.9216421147606406,0.9218503288046779,0.9219891381673694
19
+ 1,7000,0.9259278538337411,0.9261013655371054,0.9262575260701335
20
+ 1,8000,0.9295889507747298,0.9296063019450662,0.9296236531154026
21
+ 1,9000,0.9333715059080735,0.9337011781444658,0.9337185293148023
22
+ 1,10000,0.9384727499869866,0.9389585827564069,0.9390106362674162
23
+ 1,-1,0.9391494456301077,0.9394444155258272,0.9396873319105373
24
+ 2,1000,0.9392014991411171,0.9394097131851543,0.9397046830808738
25
+ 2,2000,0.942081793416966,0.9421338469279753,0.9422726562906668
26
+ 2,3000,0.9455173251435809,0.9454305692918987,0.9456214321655996
27
+ 2,4000,0.9474433050509257,0.9475821144136172,0.9477209237763087
28
+ 2,5000,0.9499245224090365,0.9500980341124009,0.9503583016674475
29
+ 2,6000,0.9523883885968109,0.9523189839154651,0.9525271979595024
30
+ 2,7000,0.9531171377509413,0.9530824354102684,0.953342702965315
31
+ 2,8000,0.9544358266965107,0.9545225825481929,0.9545919872295386
32
+ 2,9000,0.9547307965922301,0.9550778199989589,0.9551298735099683
33
+ 2,10000,0.9560494855377996,0.9562403484115004,0.9563097530928462
34
+ 2,-1,0.9563965089445283,0.9565353183072198,0.9566394253292384
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:6ea4bbca9a18265ab75010ac3747902c628356f065bae71b87ac50ac597566fe
3
+ size 451756589
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 512,
3
+ "do_lower_case": false
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,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clean_up_tokenization_spaces": true,
3
+ "cls_token": "[CLS]",
4
+ "do_basic_tokenize": true,
5
+ "do_lower_case": true,
6
+ "mask_token": "[MASK]",
7
+ "model_max_length": 1000000000000000019884624838656,
8
+ "never_split": null,
9
+ "pad_token": "[PAD]",
10
+ "sep_token": "[SEP]",
11
+ "strip_accents": null,
12
+ "tokenize_chinese_chars": true,
13
+ "tokenizer_class": "BertTokenizer",
14
+ "unk_token": "[UNK]"
15
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff