docs: update readme
Browse files
README.md
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: ko
|
3 |
+
---
|
4 |
+
|
5 |
+
# KoELECTRA v3 (Base Discriminator)
|
6 |
+
|
7 |
+
Pretrained ELECTRA Language Model for Korean (`koelectra-base-v3-discriminator`)
|
8 |
+
|
9 |
+
For more detail, please see [original repository](https://github.com/monologg/KoELECTRA/blob/master/README_EN.md).
|
10 |
+
|
11 |
+
## Usage
|
12 |
+
|
13 |
+
### Load model and tokenizer
|
14 |
+
|
15 |
+
```python
|
16 |
+
>>> from transformers import ElectraModel, ElectraTokenizer
|
17 |
+
|
18 |
+
>>> model = ElectraModel.from_pretrained("monologg/koelectra-base-v3-discriminator")
|
19 |
+
>>> tokenizer = ElectraTokenizer.from_pretrained("monologg/koelectra-base-v3-discriminator")
|
20 |
+
```
|
21 |
+
|
22 |
+
### Tokenizer example
|
23 |
+
|
24 |
+
```python
|
25 |
+
>>> from transformers import ElectraTokenizer
|
26 |
+
>>> tokenizer = ElectraTokenizer.from_pretrained("monologg/koelectra-base-v3-discriminator")
|
27 |
+
>>> tokenizer.tokenize("[CLS] 한국어 ELECTRA를 공유합니다. [SEP]")
|
28 |
+
['[CLS]', '한국어', 'EL', '##EC', '##TRA', '##를', '공유', '##합니다', '.', '[SEP]']
|
29 |
+
>>> tokenizer.convert_tokens_to_ids(['[CLS]', '한국어', 'EL', '##EC', '##TRA', '##를', '공유', '##합니다', '.', '[SEP]'])
|
30 |
+
[2, 11229, 29173, 13352, 25541, 4110, 7824, 17788, 18, 3]
|
31 |
+
```
|
32 |
+
|
33 |
+
## Example using ElectraForPreTraining
|
34 |
+
|
35 |
+
```python
|
36 |
+
import torch
|
37 |
+
from transformers import ElectraForPreTraining, ElectraTokenizer
|
38 |
+
|
39 |
+
discriminator = ElectraForPreTraining.from_pretrained("monologg/koelectra-base-v3-discriminator")
|
40 |
+
tokenizer = ElectraTokenizer.from_pretrained("monologg/koelectra-base-v3-discriminator")
|
41 |
+
|
42 |
+
sentence = "나는 방금 밥을 먹었다."
|
43 |
+
fake_sentence = "나는 내일 밥을 먹었다."
|
44 |
+
|
45 |
+
fake_tokens = tokenizer.tokenize(fake_sentence)
|
46 |
+
fake_inputs = tokenizer.encode(fake_sentence, return_tensors="pt")
|
47 |
+
|
48 |
+
discriminator_outputs = discriminator(fake_inputs)
|
49 |
+
predictions = torch.round((torch.sign(discriminator_outputs[0]) + 1) / 2)
|
50 |
+
|
51 |
+
print(list(zip(fake_tokens, predictions.tolist()[1:-1])))
|
52 |
+
```
|