jhgan
commited on
Commit
•
ed3a97b
1
Parent(s):
db39b99
init
Browse files- 1_Pooling/config.json +7 -0
- README.md +153 -0
- config.json +29 -0
- config_sentence_transformers.json +7 -0
- eval/similarity_evaluation_sts-dev_results.csv +6 -0
- modules.json +14 -0
- pytorch_model.bin +3 -0
- sentence_bert_config.json +4 -0
- similarity_evaluation_sts-test_results.csv +2 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +1 -0
- vocab.txt +0 -0
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,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
pipeline_tag: sentence-similarity
|
3 |
+
tags:
|
4 |
+
- sentence-transformers
|
5 |
+
- feature-extraction
|
6 |
+
- sentence-similarity
|
7 |
+
- transformers
|
8 |
+
---
|
9 |
+
|
10 |
+
# ko-sroberta-multitask
|
11 |
+
|
12 |
+
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.
|
13 |
+
|
14 |
+
<!--- Describe your model here -->
|
15 |
+
|
16 |
+
## Usage (Sentence-Transformers)
|
17 |
+
|
18 |
+
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
19 |
+
|
20 |
+
```
|
21 |
+
pip install -U sentence-transformers
|
22 |
+
```
|
23 |
+
|
24 |
+
Then you can use the model like this:
|
25 |
+
|
26 |
+
```python
|
27 |
+
from sentence_transformers import SentenceTransformer
|
28 |
+
sentences = ["안녕하세요?", "한국어 문장 임베딩을 위한 버트 모델입니다."]
|
29 |
+
|
30 |
+
model = SentenceTransformer('ko-sroberta-multitask')
|
31 |
+
embeddings = model.encode(sentences)
|
32 |
+
print(embeddings)
|
33 |
+
```
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
## Usage (HuggingFace Transformers)
|
38 |
+
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.
|
39 |
+
|
40 |
+
```python
|
41 |
+
from transformers import AutoTokenizer, AutoModel
|
42 |
+
import torch
|
43 |
+
|
44 |
+
|
45 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
46 |
+
def mean_pooling(model_output, attention_mask):
|
47 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
48 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
49 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
50 |
+
|
51 |
+
|
52 |
+
# Sentences we want sentence embeddings for
|
53 |
+
sentences = ['This is an example sentence', 'Each sentence is converted']
|
54 |
+
|
55 |
+
# Load model from HuggingFace Hub
|
56 |
+
tokenizer = AutoTokenizer.from_pretrained('jhgan/ko-sroberta-multitask')
|
57 |
+
model = AutoModel.from_pretrained('jhgan/ko-sroberta-multitask')
|
58 |
+
|
59 |
+
# Tokenize sentences
|
60 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
61 |
+
|
62 |
+
# Compute token embeddings
|
63 |
+
with torch.no_grad():
|
64 |
+
model_output = model(**encoded_input)
|
65 |
+
|
66 |
+
# Perform pooling. In this case, mean pooling.
|
67 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
68 |
+
|
69 |
+
print("Sentence embeddings:")
|
70 |
+
print(sentence_embeddings)
|
71 |
+
```
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
## Evaluation Results
|
76 |
+
|
77 |
+
<!--- Describe how your model was evaluated -->
|
78 |
+
|
79 |
+
KorSTS, KorNLI 학습 데이터셋으로 멀티 태스크 학습을 진행한 후 KorSTS 평가 데이터셋으로 평가한 결과입니다.
|
80 |
+
|
81 |
+
- Cosine Pearson: 84.77
|
82 |
+
- Cosine Spearman: 85.60
|
83 |
+
- Euclidean Pearson: 83.71
|
84 |
+
- Euclidean Spearman: 84.40
|
85 |
+
- Manhattan Pearson: 83.70
|
86 |
+
- Manhattan Spearman: 84.38
|
87 |
+
- Dot Pearson: 82.42
|
88 |
+
- Dot Spearman: 82.33
|
89 |
+
|
90 |
+
## Training
|
91 |
+
The model was trained with the parameters:
|
92 |
+
|
93 |
+
**DataLoader**:
|
94 |
+
|
95 |
+
`sentence_transformers.datasets.NoDuplicatesDataLoader.NoDuplicatesDataLoader` of length 8885 with parameters:
|
96 |
+
```
|
97 |
+
{'batch_size': 64}
|
98 |
+
```
|
99 |
+
|
100 |
+
**Loss**:
|
101 |
+
|
102 |
+
`sentence_transformers.losses.MultipleNegativesRankingLoss.MultipleNegativesRankingLoss` with parameters:
|
103 |
+
```
|
104 |
+
{'scale': 20.0, 'similarity_fct': 'cos_sim'}
|
105 |
+
```
|
106 |
+
|
107 |
+
**DataLoader**:
|
108 |
+
|
109 |
+
`torch.utils.data.dataloader.DataLoader` of length 719 with parameters:
|
110 |
+
```
|
111 |
+
{'batch_size': 8, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
|
112 |
+
```
|
113 |
+
|
114 |
+
**Loss**:
|
115 |
+
|
116 |
+
`sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss`
|
117 |
+
|
118 |
+
Parameters of the fit()-Method:
|
119 |
+
```
|
120 |
+
{
|
121 |
+
"epochs": 5,
|
122 |
+
"evaluation_steps": 1000,
|
123 |
+
"evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
|
124 |
+
"max_grad_norm": 1,
|
125 |
+
"optimizer_class": "<class 'transformers.optimization.AdamW'>",
|
126 |
+
"optimizer_params": {
|
127 |
+
"lr": 2e-05
|
128 |
+
},
|
129 |
+
"scheduler": "WarmupLinear",
|
130 |
+
"steps_per_epoch": null,
|
131 |
+
"warmup_steps": 360,
|
132 |
+
"weight_decay": 0.01
|
133 |
+
}
|
134 |
+
```
|
135 |
+
|
136 |
+
|
137 |
+
## Full Model Architecture
|
138 |
+
```
|
139 |
+
SentenceTransformer(
|
140 |
+
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: RobertaModel
|
141 |
+
(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})
|
142 |
+
)
|
143 |
+
```
|
144 |
+
|
145 |
+
## Citing & Authors
|
146 |
+
|
147 |
+
<!--- Describe where people can find more information -->
|
148 |
+
- Ham, J., Choe, Y. J., Park, K., Choi, I., & Soh, H. (2020). Kornli and korsts: New benchmark datasets for korean natural language understanding. arXiv
|
149 |
+
preprint arXiv:2004.03289
|
150 |
+
- Reimers, Nils and Iryna Gurevych. “Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks.” ArXiv abs/1908.10084 (2019)
|
151 |
+
- Reimers, Nils and Iryna Gurevych. “Making Monolingual Sentence Embeddings Multilingual Using Knowledge Distillation.” EMNLP (2020).
|
152 |
+
|
153 |
+
|
config.json
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "klue/roberta-base",
|
3 |
+
"architectures": [
|
4 |
+
"RobertaModel"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"bos_token_id": 0,
|
8 |
+
"classifier_dropout": null,
|
9 |
+
"eos_token_id": 2,
|
10 |
+
"gradient_checkpointing": false,
|
11 |
+
"hidden_act": "gelu",
|
12 |
+
"hidden_dropout_prob": 0.1,
|
13 |
+
"hidden_size": 768,
|
14 |
+
"initializer_range": 0.02,
|
15 |
+
"intermediate_size": 3072,
|
16 |
+
"layer_norm_eps": 1e-05,
|
17 |
+
"max_position_embeddings": 514,
|
18 |
+
"model_type": "roberta",
|
19 |
+
"num_attention_heads": 12,
|
20 |
+
"num_hidden_layers": 12,
|
21 |
+
"pad_token_id": 1,
|
22 |
+
"position_embedding_type": "absolute",
|
23 |
+
"tokenizer_class": "BertTokenizer",
|
24 |
+
"torch_dtype": "float32",
|
25 |
+
"transformers_version": "4.13.0",
|
26 |
+
"type_vocab_size": 1,
|
27 |
+
"use_cache": true,
|
28 |
+
"vocab_size": 32000
|
29 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "2.1.0",
|
4 |
+
"transformers": "4.13.0",
|
5 |
+
"pytorch": "1.7.0+cu110"
|
6 |
+
}
|
7 |
+
}
|
eval/similarity_evaluation_sts-dev_results.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman
|
2 |
+
0,-1,0.8603829184143664,0.8634439808588751,0.8520373126043029,0.8582637518032019,0.8519665769908871,0.8582077748963437,0.8305067668652699,0.8297689706234703
|
3 |
+
1,-1,0.8738941526987756,0.8732814736395488,0.8572646949316028,0.8637278623258947,0.8572464105288398,0.863677852383028,0.8453502241053964,0.8435598021802103
|
4 |
+
2,-1,0.8696573041220188,0.8715316450173949,0.8582154646347402,0.8656908761326176,0.8576657264057793,0.8649860002025886,0.8390346407149374,0.8374201573846959
|
5 |
+
3,-1,0.8750163944562664,0.8760740592164935,0.8614311434759245,0.8692434586491514,0.8606418133936148,0.8685416716892201,0.8461674597377774,0.8451364687459089
|
6 |
+
4,-1,0.8751659863714976,0.8759995162362965,0.8613002432395667,0.8694394249762125,0.860629998153408,0.8687313337414789,0.8472061320718693,0.8454604049119452
|
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:e0143341f5e4653b7ece14cf0685f5fbf5b68a3926beed43754a498947c3bd77
|
3 |
+
size 442558967
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 128,
|
3 |
+
"do_lower_case": false
|
4 |
+
}
|
similarity_evaluation_sts-test_results.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman
|
2 |
+
-1,-1,0.8477045280392909,0.8559956140722809,0.8370636752767797,0.8440079435411166,0.8370234533153658,0.8438439443425015,0.8241822253054464,0.8233260855548581
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "[CLS]", "eos_token": "[SEP]", "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"do_lower_case": false, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "do_basic_tokenize": true, "never_split": null, "bos_token": "[CLS]", "eos_token": "[SEP]", "model_max_length": 512, "special_tokens_map_file": "/home/jhgan/.cache/huggingface/transformers/9d0c87e44b00acfbfbae931b2e4068eb6311a0c3e71e23e5400bdf57cab4bfbf.70c17d6e4d492c8f24f5bb97ab56c7f272e947112c6faf9dd846da42ba13eb23", "name_or_path": "klue/roberta-base", "tokenizer_class": "BertTokenizer"}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|