Update README.md
Browse files
README.md
CHANGED
@@ -1,34 +1,98 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
license: apache-2.0
|
4 |
-
base_model:
|
5 |
-
tags:
|
6 |
-
- generated_from_trainer
|
7 |
model-index:
|
8 |
- name: KoModernBERT-base-mlm-v02-ckp02
|
9 |
results: []
|
|
|
|
|
10 |
---
|
11 |
|
12 |
-
|
13 |
-
should probably proofread and complete it, then remove this comment. -->
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
This model is a fine-tuned version of [x2bee/KoModernBERT-base-mlm-v02-ckp02](https://huggingface.co/x2bee/KoModernBERT-base-mlm-v02-ckp02) on the None dataset.
|
18 |
It achieves the following results on the evaluation set:
|
19 |
- Loss: 1.6437
|
20 |
|
21 |
-
##
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
## Training procedure
|
34 |
|
@@ -70,4 +134,4 @@ The following hyperparameters were used during training:
|
|
70 |
- Transformers 4.48.0
|
71 |
- Pytorch 2.5.1+cu124
|
72 |
- Datasets 3.2.0
|
73 |
-
- Tokenizers 0.21.0
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
license: apache-2.0
|
4 |
+
base_model: answerdotai/ModernBERT-base
|
|
|
|
|
5 |
model-index:
|
6 |
- name: KoModernBERT-base-mlm-v02-ckp02
|
7 |
results: []
|
8 |
+
language:
|
9 |
+
- ko
|
10 |
---
|
11 |
|
12 |
+
# KoModernBERT-base-mlm-v02
|
|
|
13 |
|
14 |
+
This model is a fine-tuned version of [answerdotai/ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base) <br>
|
15 |
+
|
16 |
+
* Flash-Attention 2
|
17 |
+
* StabelAdamW
|
18 |
+
* Unpadding & Sequence Packing
|
19 |
|
|
|
20 |
It achieves the following results on the evaluation set:
|
21 |
- Loss: 1.6437
|
22 |
|
23 |
+
## Example Use
|
24 |
+
```python
|
25 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
26 |
+
from huggingface_hub import HfApi, login
|
27 |
+
with open('./api_key/HGF_TOKEN.txt', 'r') as hgf:
|
28 |
+
login(token=hgf.read())
|
29 |
+
api = HfApi()
|
30 |
+
|
31 |
+
model_id = "x2bee/KoModernBERT-base-mlm-v01"
|
32 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
33 |
+
model = AutoModelForMaskedLM.from_pretrained(model_id).to("cuda")
|
34 |
+
|
35 |
+
def modern_bert_convert_with_multiple_masks(text: str, top_k: int = 1, select_method:str = "Logit") -> str:
|
36 |
+
if "[MASK]" not in text:
|
37 |
+
raise ValueError("MLM Model should include '[MASK]' in the sentence")
|
38 |
+
|
39 |
+
while "[MASK]" in text:
|
40 |
+
inputs = tokenizer(text, return_tensors="pt").to("cuda")
|
41 |
+
outputs = model(**inputs)
|
42 |
+
|
43 |
+
input_ids = inputs["input_ids"][0].tolist()
|
44 |
+
mask_indices = [i for i, token_id in enumerate(input_ids) if token_id == tokenizer.mask_token_id]
|
45 |
+
|
46 |
+
current_mask_index = mask_indices[0]
|
47 |
+
|
48 |
+
logits = outputs.logits[0, current_mask_index]
|
49 |
+
|
50 |
+
top_k_tokens = logits.topk(top_k).indices.tolist()
|
51 |
+
top_k_logits, top_k_indices = logits.topk(top_k)
|
52 |
+
|
53 |
+
if select_method == "Logit":
|
54 |
+
probabilities = torch.softmax(top_k_logits, dim=0).tolist()
|
55 |
+
predicted_token_id = random.choices(top_k_indices.tolist(), weights=probabilities, k=1)[0]
|
56 |
+
predicted_token = tokenizer.decode([predicted_token_id]).strip()
|
57 |
+
|
58 |
+
elif select_method == "Random":
|
59 |
+
predicted_token_id = random.choice(top_k_tokens)
|
60 |
+
predicted_token = tokenizer.decode([predicted_token_id]).strip()
|
61 |
+
|
62 |
+
elif select_method == "Best":
|
63 |
+
predicted_token_id = top_k_tokens[0]
|
64 |
+
predicted_token = tokenizer.decode([predicted_token_id]).strip()
|
65 |
+
|
66 |
+
else:
|
67 |
+
raise ValueError("select_method should be one of ['Logit', 'Random', 'Best']")
|
68 |
+
|
69 |
+
text = text.replace("[MASK]", predicted_token, 1)
|
70 |
+
|
71 |
+
print(f"Predicted: {predicted_token} | Current text: {text}")
|
72 |
+
|
73 |
+
return text
|
74 |
+
```
|
75 |
+
|
76 |
+
```
|
77 |
+
text = "30์ผ ์ ๋จ ๋ฌด์๊ตญ์ [MASK] ํ์ฃผ๋ก์ ์ ๋ ๋ฐ์ํ ์ ์ฃผํญ๊ณต [MASK] ๋น์ ๊ธฐ์ฒด๊ฐ [MASK]์ฐฉ๋ฅํ๋ฉด์ ๊ฐํ ๋ง์ฐฐ๋ก ์๊ธด ํ์ ์ด ๋จ์ ์๋ค. ์ด ์ฐธ์ฌ๋ก [MASK]๊ณผ ์น๋ฌด์ 181๋ช
์ค 179๋ช
์ด ์จ์ง๊ณ [MASK]๋ ํ์ฒด๋ฅผ ์์๋ณผ ์ ์์ด [MASK]๋๋ค. [MASK] ๊ท๋ชจ์ [MASK] ์์ธ ๋ฑ์ ๋ํด ๋ค์ํ [MASK]์ด ์ ๊ธฐ๋๊ณ ์๋ ๊ฐ์ด๋ฐ [MASK]์ ์ค์น๋ [MASK](์ฐฉ๋ฅ ์ ๋ ์์ ์์ค)๊ฐ [MASK]๋ฅผ ํค์ ๋ค๋ [MASK]์ด ๋์ค๊ณ ์๋ค."
|
78 |
+
result = mbm.modern_bert_convert_with_multiple_masks(text, top_k=1)
|
79 |
+
|
80 |
+
'30์ผ ์ ๋จ ๋ฌด์๊ตญ์ ํฐ๋ฏธ๋ ํ์ฃผ๋ก์ ์ ๋ ๋ฐ์ํ ์ ์ฃผํญ๊ณต ์ฌ๊ณ ๋น์ ๊ธฐ์ฒด๊ฐ ๋ฌด๋จ์ฐฉ๋ฅํ๋ฉด์ ๊ฐํ ๋ง์ฐฐ๋ก ์๊ธด ํ์ ์ด ๋จ์ ์๋ค. ์ด ์ฐธ์ฌ๋ก ์น๊ฐ๊ณผ ์น๋ฌด์ 181๋ช
์ค 179๋ช
์ด ์จ์ง๊ณ ์ผ๋ถ๋ ํ์ฒด๋ฅผ ์์๋ณผ ์ ์์ด ์ค์ข
๋๋ค. ์ฌ๊ณ ๊ท๋ชจ์ ์ฌ๊ณ ์์ธ ๋ฑ์ ๋ํด ๋ค์ํ ์ํน์ด ์ ๊ธฐ๋๊ณ ์๋ ๊ฐ์ด๋ฐ ๊ธฐ๋ด์ ์ค์น๋ ESC(์ฐฉ๋ฅ ์ ๋ ์์ ์์ค)๊ฐ ์ฌ๊ณ ๋ฅผ ํค์ ๋ค๋ ์ฃผ์ฅ์ด ๋์ค๊ณ ์๋ค.'
|
81 |
+
```
|
82 |
+
|
83 |
+
```
|
84 |
+
text = "์ค๊ตญ์ ์๋๋ [MASK]์ด๋ค"
|
85 |
+
result = mbm.modern_bert_convert_with_multiple_masks(text, top_k=1)
|
86 |
+
'์ค๊ตญ์ ์๋๋ ๋ฒ ์ด์ง์ด๋ค'
|
87 |
+
|
88 |
+
text = "์ผ๋ณธ์ ์๋๋ [MASK]์ด๋ค"
|
89 |
+
result = mbm.modern_bert_convert_with_multiple_masks(text, top_k=1)
|
90 |
+
'์ผ๋ณธ์ ์๋๋ ๋์ฟ์ด๋ค'
|
91 |
+
|
92 |
+
text = "๋ํ๋ฏผ๊ตญ์ ๊ฐ์ฅ ํฐ ๋์๋ [MASK]์ด๋ค"
|
93 |
+
result = mbm.modern_bert_convert_with_multiple_masks(text, top_k=1)
|
94 |
+
'๋ํ๋ฏผ๊ตญ์ ๊ฐ์ฅ ํฐ ๋์๋ ์ธ์ฒ์ด๋ค'
|
95 |
+
```
|
96 |
|
97 |
## Training procedure
|
98 |
|
|
|
134 |
- Transformers 4.48.0
|
135 |
- Pytorch 2.5.1+cu124
|
136 |
- Datasets 3.2.0
|
137 |
+
- Tokenizers 0.21.0
|