Ahmet commited on
Commit
27a1a08
1 Parent(s): cf41efe

upload files

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 512,
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,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - tr
4
+ pipeline_tag: sentence-similarity
5
+ tags:
6
+ - sentence-transformers
7
+ - feature-extraction
8
+ - sentence-similarity
9
+ - transformers
10
+ datasets:
11
+ - nli_tr
12
+ - emrecan/stsb-mt-turkish
13
+ license: mit
14
+ ---
15
+
16
+ # turkish-medium-bert-uncased-mean-nli-stsb-tr
17
+
18
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 512 dimensional dense vector space and can be used for tasks like clustering or semantic search.
19
+
20
+ This model was adapted from [ytu-ce-cosmos/turkish-medium-bert-uncased](https://huggingface.co/ytu-ce-cosmos/turkish-medium-bert-uncased) and fine-tuned on these datasets:
21
+ - [nli_tr](https://huggingface.co/datasets/nli_tr)
22
+ - [emrecan/stsb-mt-turkish](https://huggingface.co/datasets/emrecan/stsb-mt-turkish)
23
+
24
+ ## Usage (Sentence-Transformers)
25
+
26
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
27
+
28
+ ```
29
+ pip install -U sentence-transformers
30
+ ```
31
+
32
+ Then you can use the model like this:
33
+
34
+ ```python
35
+ from sentence_transformers import SentenceTransformer
36
+ sentences = ["Bu örnek bir cümle", "Her cümle dönüştürülür"]
37
+
38
+ model = SentenceTransformer('atasoglu/turkish-medium-bert-uncased-mean-nli-stsb-tr')
39
+ embeddings = model.encode(sentences)
40
+ print(embeddings)
41
+ ```
42
+
43
+
44
+
45
+ ## Usage (HuggingFace Transformers)
46
+ 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.
47
+
48
+ ```python
49
+ from transformers import AutoTokenizer, AutoModel
50
+ import torch
51
+
52
+
53
+ #Mean Pooling - Take attention mask into account for correct averaging
54
+ def mean_pooling(model_output, attention_mask):
55
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
56
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
57
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
58
+
59
+
60
+ # Sentences we want sentence embeddings for
61
+ sentences = ["Bu örnek bir cümle", "Her cümle dönüştürülür"]
62
+
63
+ # Load model from HuggingFace Hub
64
+ tokenizer = AutoTokenizer.from_pretrained('atasoglu/turkish-medium-bert-uncased-mean-nli-stsb-tr')
65
+ model = AutoModel.from_pretrained('atasoglu/turkish-medium-bert-uncased-mean-nli-stsb-tr')
66
+
67
+ # Tokenize sentences
68
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
69
+
70
+ # Compute token embeddings
71
+ with torch.no_grad():
72
+ model_output = model(**encoded_input)
73
+
74
+ # Perform pooling. In this case, mean pooling.
75
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
76
+
77
+ print("Sentence embeddings:")
78
+ print(sentence_embeddings)
79
+ ```
80
+
81
+
82
+
83
+ ## Evaluation Results
84
+
85
+ Achieved results on the [STS-b](https://huggingface.co/datasets/emrecan/stsb-mt-turkish) test split are given below:
86
+
87
+ ```txt
88
+ Cosine-Similarity : Pearson: 0.7358 Spearman: 0.7235
89
+ Manhattan-Distance: Pearson: 0.7088 Spearman: 0.7116
90
+ Euclidean-Distance: Pearson: 0.7089 Spearman: 0.7116
91
+ Dot-Product-Similarity: Pearson: 0.7021 Spearman: 0.6887
92
+ ```
93
+
94
+
95
+ ## Training
96
+ The model was trained with the parameters:
97
+
98
+ **DataLoader**:
99
+
100
+ `torch.utils.data.dataloader.DataLoader` of length 90 with parameters:
101
+ ```
102
+ {'batch_size': 64, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
103
+ ```
104
+
105
+ **Loss**:
106
+
107
+ `sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss`
108
+
109
+ Parameters of the fit()-Method:
110
+ ```
111
+ {
112
+ "epochs": 5,
113
+ "evaluation_steps": 45,
114
+ "evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
115
+ "max_grad_norm": 1,
116
+ "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
117
+ "optimizer_params": {
118
+ "lr": 2e-05
119
+ },
120
+ "scheduler": "WarmupLinear",
121
+ "steps_per_epoch": null,
122
+ "warmup_steps": 45,
123
+ "weight_decay": 0.01
124
+ }
125
+ ```
126
+
127
+
128
+ ## Full Model Architecture
129
+ ```
130
+ SentenceTransformer(
131
+ (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel
132
+ (1): Pooling({'word_embedding_dimension': 512, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
133
+ )
134
+ ```
135
+
136
+ ## Citing & Authors
137
+
138
+ <!--- Describe where people can find more information -->
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "e5_b64_turkish_medium_bert_uncased-mean-nli/",
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": 512,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 2048,
13
+ "layer_norm_eps": 1e-12,
14
+ "max_position_embeddings": 512,
15
+ "model_type": "bert",
16
+ "num_attention_heads": 8,
17
+ "num_hidden_layers": 8,
18
+ "pad_token_id": 0,
19
+ "position_embedding_type": "absolute",
20
+ "torch_dtype": "float32",
21
+ "transformers_version": "4.28.0",
22
+ "type_vocab_size": 2,
23
+ "use_cache": true,
24
+ "vocab_size": 32000
25
+ }
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.1.0+cu121"
6
+ }
7
+ }
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:98aa42bef61e98aad67e5c2bdbdd5e39b1671908c7e1ef476228101827f388b6
3
+ size 168569642
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 256,
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,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clean_up_tokenization_spaces": true,
3
+ "cls_token": "[CLS]",
4
+ "do_basic_tokenize": true,
5
+ "do_lower_case": false,
6
+ "mask_token": "[MASK]",
7
+ "max_len": 512,
8
+ "model_max_length": 512,
9
+ "never_split": null,
10
+ "pad_token": "[PAD]",
11
+ "sep_token": "[SEP]",
12
+ "strip_accents": null,
13
+ "tokenize_chinese_chars": true,
14
+ "tokenizer_class": "BertTokenizer",
15
+ "truncation": true,
16
+ "unk_token": "[UNK]"
17
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff