|
--- |
|
language: ko |
|
datasets: |
|
- mc4 |
|
license: apache-2.0 |
|
--- |
|
|
|
# ByT5-Korean - base |
|
|
|
ByT5-Korean is a Korean specific extension of Google's [ByT5](https://github.com/google-research/byt5). |
|
|
|
A Korean syllable has three components (called Jamo): a beginning consonant, a middle vowel, and an optional final consonant; they are like individual characters of alphabet. |
|
While the ByT5's utf-8 encoding allows generic encoding for multiple languages, it is unnatural for Korean because it splits the bits representation of each Jamo in the middle. |
|
|
|
ByT5-Korean extends ByT5's utf-8 encoding with special care for Korean syllables; each Jamo is represented with a extra token. |
|
ByT5-Korean was pre-trained on [mC4](https://www.tensorflow.org/datasets/catalog/c4#c4multilingual) with 70% Korean and 30% English. |
|
|
|
## Encoding Scheme |
|
```text |
|
id: token |
|
0: <pad> |
|
1: <eos> |
|
2: <unk> |
|
3~258: utf-8 encoding |
|
259~277: beginning consonants(μ΄μ±), 19κ°(γ±γ²γ΄γ·γΈγΉγ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
) |
|
278~298: middle vowel(μ€μ±), 21κ°(γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
‘γ
’γ
£) |
|
299~326: final consonant(μ’
μ±), 무μ’
μ±+27κ°(γ±γ²γ³γ΄γ΅γΆγ·γΉγΊγ»γΌγ½γΎγΏγ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
) |
|
327~384: from <extra_id_0> to <extra_id_57> |
|
``` |
|
|
|
## Example Inference |
|
|
|
```python |
|
import torch |
|
from tokenizer import ByT5KoreanTokenizer # https://huggingface.co/everdoubling/byt5-Korean-base/blob/main/tokenizer.py |
|
from transformers import T5ForConditionalGeneration |
|
|
|
tokenizer_jamo = ByT5KoreanTokenizer() |
|
model = T5ForConditionalGeneration.from_pretrained('everdoubling/byt5-Korean-base') |
|
|
|
input_sentence = 'νκ΅μ΄ μν€λ°±κ³Ό(μμ΄: Korean Wikipedia)λ νκ΅μ΄λ‘ μ΄μλλ μν€λ°±κ³Όμ λ€μΈμ΄ν κ°μ΄λ° νλλ‘μ, 2002λ
10μ 11μΌμ <extra_id_0>. λν νμ¬ νκ΅μ΄ μν€λ°±κ³Όμλ λ겨주기, ν λ‘ , κ·Έλ¦Ό λ± νμ΄μ§λ‘ λΆλ¦¬λ λͺ¨λ λ¬Έμλ₯Ό ν¬ν¨νλ©΄ μ΄ 2,629,860κ°κ° <extra_id_1>λμ΄ μμΌλ©°, λ겨주기λ₯Ό ν¬ν¨ν μΌλ° λ¬Έμ μλ 1,278,560κ°,[1] κ·Έμ€ λ겨주기, λ§λ€λ₯Έ λ¬Έμλ₯Ό μ μΈν μΌλ° λ¬Έμ μλ 573,149κ°μ΄λ€.' |
|
|
|
input_ids_jamo = tokenizer_jamo(input_sentence).input_ids |
|
outputs_jamo = model_jamo.generate(torch.tensor([input_ids_jamo])) |
|
print(tokenizer_jamo.decode(outputs_jamo[0])) |
|
# <pad><extra_id_0>μ€λ¦½λμλ€<extra_id_1>ΔΔ |
|
``` |
|
|
|
Additional information coming soon... |
|
|