CocoRoF commited on
Commit
07b93fd
ยท
verified ยท
1 Parent(s): 34b994f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +83 -19
README.md CHANGED
@@ -1,34 +1,98 @@
1
  ---
2
  library_name: transformers
3
  license: apache-2.0
4
- base_model: x2bee/KoModernBERT-base-mlm-v02-ckp02
5
- tags:
6
- - generated_from_trainer
7
  model-index:
8
  - name: KoModernBERT-base-mlm-v02-ckp02
9
  results: []
 
 
10
  ---
11
 
12
- <!-- This model card has been generated automatically according to the information the Trainer had access to. You
13
- should probably proofread and complete it, then remove this comment. -->
14
 
15
- # KoModernBERT-base-mlm-v02-ckp02
 
 
 
 
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
- ## Model description
22
-
23
- More information needed
24
-
25
- ## Intended uses & limitations
26
-
27
- More information needed
28
-
29
- ## Training and evaluation data
30
-
31
- More information needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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