Ahmet commited on
Commit
34e72e4
·
1 Parent(s): ff1a017

update README.md

Browse files
Files changed (1) hide show
  1. README.md +135 -1
README.md CHANGED
@@ -1,3 +1,137 @@
1
  ---
2
- license: mit
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  ---
14
+
15
+ # turkish-tiny-bert-uncased-mean-nli-stsb-tr
16
+
17
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 128 dimensional dense vector space and can be used for tasks like clustering or semantic search.
18
+
19
+ This model was adapted from [ytu-ce-cosmos/turkish-tiny-bert-uncased](https://huggingface.co/ytu-ce-cosmos/turkish-tiny-bert-uncased) and fine-tuned on these datasets:
20
+ - [nli_tr](https://huggingface.co/datasets/nli_tr)
21
+ - [emrecan/stsb-mt-turkish](https://huggingface.co/datasets/emrecan/stsb-mt-turkish)
22
+
23
+ ## Usage (Sentence-Transformers)
24
+
25
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
26
+
27
+ ```
28
+ pip install -U sentence-transformers
29
+ ```
30
+
31
+ Then you can use the model like this:
32
+
33
+ ```python
34
+ from sentence_transformers import SentenceTransformer
35
+ sentences = ["Bu örnek bir cümle", "Her cümle dönüştürülür"]
36
+
37
+ model = SentenceTransformer('atasoglu/turkish-tiny-bert-uncased-mean-nli-stsb-tr')
38
+ embeddings = model.encode(sentences)
39
+ print(embeddings)
40
+ ```
41
+
42
+
43
+
44
+ ## Usage (HuggingFace Transformers)
45
+ 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.
46
+
47
+ ```python
48
+ from transformers import AutoTokenizer, AutoModel
49
+ import torch
50
+
51
+
52
+ #Mean Pooling - Take attention mask into account for correct averaging
53
+ def mean_pooling(model_output, attention_mask):
54
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
55
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
56
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
57
+
58
+
59
+ # Sentences we want sentence embeddings for
60
+ sentences = ["Bu örnek bir cümle", "Her cümle dönüştürülür"]
61
+
62
+ # Load model from HuggingFace Hub
63
+ tokenizer = AutoTokenizer.from_pretrained('atasoglu/turkish-tiny-bert-uncased-mean-nli-stsb-tr')
64
+ model = AutoModel.from_pretrained('atasoglu/turkish-tiny-bert-uncased-mean-nli-stsb-tr')
65
+
66
+ # Tokenize sentences
67
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
68
+
69
+ # Compute token embeddings
70
+ with torch.no_grad():
71
+ model_output = model(**encoded_input)
72
+
73
+ # Perform pooling. In this case, mean pooling.
74
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
75
+
76
+ print("Sentence embeddings:")
77
+ print(sentence_embeddings)
78
+ ```
79
+
80
+
81
+
82
+ ## Evaluation Results
83
+
84
+ Achieved results on the [STS-b](https://huggingface.co/datasets/emrecan/stsb-mt-turkish) test split are given below:
85
+
86
+ ```txt
87
+ Cosine-Similarity : Pearson: 0.6587 Spearman: 0.6370
88
+ Manhattan-Distance: Pearson: 0.6293 Spearman: 0.6151
89
+ Euclidean-Distance: Pearson: 0.6335 Spearman: 0.6186
90
+ Dot-Product-Similarity: Pearson: 0.5972 Spearman: 0.5756
91
+ ```
92
+
93
+
94
+ ## Training
95
+ The model was trained with the parameters:
96
+
97
+ **DataLoader**:
98
+
99
+ `torch.utils.data.dataloader.DataLoader` of length 45 with parameters:
100
+ ```
101
+ {'batch_size': 128, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
102
+ ```
103
+
104
+ **Loss**:
105
+
106
+ `sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss`
107
+
108
+ Parameters of the fit()-Method:
109
+ ```
110
+ {
111
+ "epochs": 10,
112
+ "evaluation_steps": 22,
113
+ "evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
114
+ "max_grad_norm": 1,
115
+ "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
116
+ "optimizer_params": {
117
+ "lr": 2e-05
118
+ },
119
+ "scheduler": "WarmupLinear",
120
+ "steps_per_epoch": null,
121
+ "warmup_steps": 45,
122
+ "weight_decay": 0.01
123
+ }
124
+ ```
125
+
126
+
127
+ ## Full Model Architecture
128
+ ```
129
+ SentenceTransformer(
130
+ (0): Transformer({'max_seq_length': 75, 'do_lower_case': False}) with Transformer model: BertModel
131
+ (1): Pooling({'word_embedding_dimension': 128, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
132
+ )
133
+ ```
134
+
135
+ ## Citing & Authors
136
+
137
+ <!--- Describe where people can find more information -->