• Stars
    star
    216
  • Rank 176,536 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

g2pK: g2p module for Korean

image image image

g2pK: g2p module for Korean

g2p means a task that converts graphemes to phonemes. Hangul, the main script for Korean, is phonetic, but the pronunciation rules are notoriously complicated. So it is never easy to learn how to read a text in Korean. That's why g2p is necessary in various nlp tasks like TTS. . There's a open source g2p library for Korean, KoG2P. It is simple and works well, but I think we need a better one. Please read through the following section (main features and usage) to understand the philosophy of g2pK and how to use g2pK. We know it is not perfect in present. That's one of the reasons your contributions are more than welcome.

Requirements

Installation

pip install g2pk

Main features & Usage

  • Returns text as it is pronounced, keeping punctuations.
>>> from g2pk import G2p
>>> g2p = G2p()
>>> g2p("์–ด์ œ๋Š” ๋‚ ์”จ๊ฐ€ ๋ง‘์•˜๋Š”๋ฐ, ์˜ค๋Š˜์€ ํ๋ฆฌ๋‹ค.")
์–ด์ œ๋Š” ๋‚ ์”จ๊ฐ€ ๋ง๊ฐ„๋Š”๋ฐ, ์˜ค๋Š๋ฅธ ํ๋ฆฌ๋‹ค.
  • Determines pronunciation seeing context, thanks to Mecab, a morphological analyzer. In the following example, note that the first and second ์‹ ๊ณ  are pronounced differently.
>>> g2p("์‹ ์„ ์‹ ๊ณ  ์–ผ๋ฅธ ๋™์‚ฌ๋ฌด์†Œ์— ๊ฐ€์„œ ํ˜ผ์ธ ์‹ ๊ณ  ํ•ด๋ผ")
์‹œ๋Š˜ ์‹ ๊ผฌ ์–ผ๋ฅธ ๋™์‚ฌ๋ฌด์†Œ์— ๊ฐ€์„œ ํ˜ธ๋‹Œ ์‹ ๊ณ  ํ•ด๋ผ
  • Returns two types of results, that is, prescriptive (default) and descriptive (with the option descriptive=True) pronunciation. For example, josa ์˜ is pronounced ์˜ in principle, but in real life, it is often pronounced ์—. Also, ๊ณ„ is much more often pronounced ๊ฒŒ.
>>> sent = "๋‚˜์˜ ์นœ๊ตฌ๋Š” ๊ณ„์‚ฐ์ด ์•„์ฃผ ๋น ๋ฅด๋‹ค"
>>> g2p(sent)
๋‚˜์˜ ์นœ๊ตฌ๋Š” ๊ณ„์‚ฌ๋‹ˆ ์•„์ฃผ ๋น ๋ฅด๋‹ค
>>> g2p(sent, descriptive=True)
๋‚˜์— ์นœ๊ตฌ๋Š” ๊ฒŒ์‚ฌ๋‹ˆ ์•„์ฃผ ๋น ๋ฅด๋‹ค
  • This distinction becomes more obvious if you set group_vowels=True. In contemporary colloquial speech, some vowels are hard to distinguish from each other. For example, in the example below, the vowel ใ…’ is normalized to ใ…–.
>>> sent = "์ €๋Š” ์˜ˆ์ „์— ๊ทธ ์–˜๊ธฐ๋ฅผ ๋“ค์€ ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค"
>>> g2p(sent)
์ €๋Š ๋…œ์ €๋„ค ๊ทธ ์–˜๊ธฐ๋ฅผ ๋“œ๋ฅธ ์ €๊ธฐ ์ป์”€๋‹ˆ๋‹ค
>>> g2p(sent, group_vowels=True)
์ €๋Š ๋…œ์ €๋„ค ๊ทธ ์˜ˆ๊ธฐ๋ฅผ ๋“œ๋ฅธ ์ €๊ธฐ ์ป์”€๋‹ˆ๋‹ค
  • By default, it returns the standard Korean script, where letters are assembled to form a syllable. If you set to_syl=False, however, it returns Hangul letters or jamo. This can be useful for many applications like speech synthesis. *Depending on the font you are using, the two results below may look the same, but actually they are not.
>>> sent = "์–ด์ œ๋Š” ๋‚ ์”จ๊ฐ€ ๋ง‘์•˜๋Š”๋ฐ, ์˜ค๋Š˜์€ ํ๋ฆฌ๋‹ค."
>>> g2p(sent)
์–ด์ œ๋Š” ๋‚ ์”จ๊ฐ€ ๋ง๊ฐ„๋Š”๋ฐ, ์˜ค๋Š๋ฅธ ํ๋ฆฌ๋‹ค.
>>> g2p(sent, to_syl=False)
แ„‹แ…ฅแ„Œแ…ฆแ„‚แ…ณแ†ซ แ„‚แ…กแ†ฏแ„Šแ…ตแ„€แ…ก แ„†แ…กแ†ฏแ„€แ…กแ†ซแ„‚แ…ณแ†ซแ„ƒแ…ฆ, แ„‹แ…ฉแ„‚แ…ณแ„…แ…ณแ†ซ แ„’แ…ณแ„…แ…ตแ„ƒแ…ก.
>>> sent = "๊ทธ ์‚ฌ๋žŒ์€ ์ข€, old school ๊ฐ™์•„"
>>> g2p(sent)
๊ทธ ์‚ฌ๋ผ๋ฏ„ ์ข€, ์˜ฌ๋“œ ์Šค์ฟจ ๊ฐ€ํƒ€
  • Arabic numbers are spelled out to their context. Note that the first 12 is pronounced ์—ด๋‘, whereas the second 12 is pronounced ์‹ญ์ด.
>>> sent = "์ง€๊ธˆ ์‹œ๊ฐ์€ 12์‹œ 12๋ถ„์ž…๋‹ˆ๋‹ค"
>>> g2p(sent)
์ง€๊ธˆ ์‹œ๊ฐ€๊ทธ ๋…ˆ๋‘์‹œ ์‹œ๋น„๋ถ€๋‹˜๋‹ˆ๋‹ค
  • It is natural that rules can NOT cover every single case. Add special idioms to idioms.txt.
  • If you set verbose=True, you will see the conversion processes with relevant information.
>>> sent = "ํ•™๊ต์— ๊ฐ”๋‹ค ์™€์„œ, ์—„๋งˆ๊ฐ€ ํ•ด ์ฃผ์‹  ๋ฐฅ์„ ๋จน์—ˆ๋‹ค."
>>> g2p(sent, verbose=True)
ํ•™๊ต์— ๊ฐ”๋‹ค ์™€์„œ, ์—„๋งˆ๊ฐ€ ํ•ด ์ฃผ์‹  ๋ฐฅ์„ ๋จน์—ˆ๋‹ค. -> ํ•™๊พœ์— ๊ฐ”๋‹ค ์™€์„œ, ์—„๋งˆ๊ฐ€ ํ•ด ์ฃผ์‹  ๋ฐฅ์„ ๋จน์—ˆ๋‹ค.
 ์ œ23ํ•ญใ€€๋ฐ›์นจ 'ใ„ฑ(ใ„ฒ, ใ…‹, ใ„ณ, ใ„บ), ใ„ท(ใ……, ใ…†, ใ…ˆ, ใ…Š, ใ…Œ), ใ…‚(ใ…, ใ„ผ, ใ„ฟ, ใ…„)' ๋’ค์— ์—ฐ๊ฒฐ๋˜๋Š” 'ใ„ฑ, ใ„ท, ใ…‚, ใ……, ใ…ˆ'์€ ๋œ์†Œ๋ฆฌ๋กœ ๋ฐœ์Œํ•œ๋‹ค.
-> ๊ตญ๋ฐฅ[๊ตญ๋นฑ], ๊นŽ๋‹ค[๊น๋”ฐ], ๋„‘๋ฐ›์ด[๋„‰๋น ์ง€], ์‚ฏ๋ˆ[์‚ญ๋˜”]
-> ๋‹ญ์žฅ[๋‹ฅ์งฑ], ์นก๋ฒ”[์น™๋ป ], ๋ป—๋Œ€๋‹ค[๋ป—๋•Œ๋‹ค], ์˜ท๊ณ ๋ฆ„[์˜ซ๊ผฌ๋ฆ„]
-> ์žˆ๋˜[์ป๋–ค], ๊ฝ‚๊ณ [๊ผณ๊ผฌ], ๊ฝƒ๋‹ค๋ฐœ[๊ผณ๋”ฐ๋ฐœ], ๋‚ฏ์„ค๋‹ค[๋‚Ÿ์ฐ๋‹ค]
-> ๋ฐญ๊ฐˆ์ด[๋ฐ›๊นŒ๋ฆฌ], ์†ฅ์ „[์†“์ฉ], ๊ณฑ๋Œ[๊ณฑ๋˜˜], ๋ฎ๊ฐœ[๋ฅ๊นจ]
-> ์˜†์ง‘[์—ฝ์ฐ], ๋„“์ฃฝํ•˜๋‹ค[๋„™์ญˆ์นด๋‹ค], ์Š์กฐ๋ฆฌ๋‹ค[์์ชผ๋ฆฌ๋‹ค], ๊ฐ’์ง€๋‹ค[๊ฐ‘์ฐŒ๋‹ค] 
ํ•™๊พœ์— ๊ฐ”๋‹ค ์™€์„œ, ์—„๋งˆ๊ฐ€ ํ•ด ์ฃผ์‹  ๋ฐฅ์„ ๋จน์—ˆ๋‹ค. -> ํ•™๊พœ์— ๊ฐ‡๋”ฐ ์™€์„œ, ์—„๋งˆ๊ฐ€ ํ•ด ์ฃผ์‹  ๋ฐฅ์„ ๋จน์–ป๋”ฐ.
 ์ œ9ํ•ญใ€€๋ฐ›์นจ 'ใ„ฒ, ใ…‹', 'ใ……, ใ…†, ใ…ˆ, ใ…Š, ใ…Œ', 'ใ…'์€ ์–ด๋ง ๋˜๋Š” ์ž์Œ ์•ž์—์„œ ๊ฐ๊ฐ ๋Œ€ํ‘œ์Œ [ใ„ฑ, ใ„ท, ใ…‚]์œผ๋กœ ๋ฐœ์Œํ•œ๋‹ค.
-> ๋‹ฆ๋‹ค[๋‹ฅ๋”ฐ], ํ‚ค์”[ํ‚ค์œฝ], ํ‚ค์”๊ณผ[ํ‚ค์œฝ๊ฝˆ], ์˜ท[์˜ซ]
-> ์›ƒ๋‹ค[์šท๋”ฐ], ์žˆ๋‹ค[์ป๋”ฐ], ์ –[์ ‡], ๋นš๋‹ค[๋น‹๋”ฐ]
-> ๊ฝƒ[๊ผณ], ์ซ“๋‹ค[์ซƒ๋”ฐ], ์†ฅ[์†“], ๋ฑ‰๋‹ค[๋ฐท๋”ฐ]
-> ์•ž[์••], ๋ฎ๋‹ค[๋ฅ๋”ฐ]
์ œ23ํ•ญใ€€๋ฐ›์นจ 'ใ„ฑ(ใ„ฒ, ใ…‹, ใ„ณ, ใ„บ), ใ„ท(ใ……, ใ…†, ใ…ˆ, ใ…Š, ใ…Œ), ใ…‚(ใ…, ใ„ผ, ใ„ฟ, ใ…„)' ๋’ค์— ์—ฐ๊ฒฐ๋˜๋Š” 'ใ„ฑ, ใ„ท, ใ…‚, ใ……, ใ…ˆ'์€ ๋œ์†Œ๋ฆฌ๋กœ ๋ฐœ์Œํ•œ๋‹ค.
-> ๊ตญ๋ฐฅ[๊ตญ๋นฑ], ๊นŽ๋‹ค[๊น๋”ฐ], ๋„‘๋ฐ›์ด[๋„‰๋น ์ง€], ์‚ฏ๋ˆ[์‚ญ๋˜”]
-> ๋‹ญ์žฅ[๋‹ฅ์งฑ], ์นก๋ฒ”[์น™๋ป ], ๋ป—๋Œ€๋‹ค[๋ป—๋•Œ๋‹ค], ์˜ท๊ณ ๋ฆ„[์˜ซ๊ผฌ๋ฆ„]
-> ์žˆ๋˜[์ป๋–ค], ๊ฝ‚๊ณ [๊ผณ๊ผฌ], ๊ฝƒ๋‹ค๋ฐœ[๊ผณ๋”ฐ๋ฐœ], ๋‚ฏ์„ค๋‹ค[๋‚Ÿ์ฐ๋‹ค]
-> ๋ฐญ๊ฐˆ์ด[๋ฐ›๊นŒ๋ฆฌ], ์†ฅ์ „[์†“์ฉ], ๊ณฑ๋Œ[๊ณฑ๋˜˜], ๋ฎ๊ฐœ[๋ฅ๊นจ]
-> ์˜†์ง‘[์—ฝ์ฐ], ๋„“์ฃฝํ•˜๋‹ค[๋„™์ญˆ์นด๋‹ค], ์Š์กฐ๋ฆฌ๋‹ค[์์ชผ๋ฆฌ๋‹ค], ๊ฐ’์ง€๋‹ค[๊ฐ‘์ฐŒ๋‹ค] 
ํ•™๊พœ์— ๊ฐ‡๋”ฐ ์™€์„œ, ์—„๋งˆ๊ฐ€ ํ•ด ์ฃผ์‹  ๋ฐฅ์„ ๋จน์–ป๋”ฐ. -> ํ•™๊พœ์— ๊ฐ‡๋”ฐ ์™€์„œ, ์—„๋งˆ๊ฐ€ ํ•ด ์ฃผ์‹  ๋ฐ”๋ธ” ๋จธ๊ฑท๋”ฐ.
 ์ œ13ํ•ญใ€€ํ™‘๋ฐ›์นจ์ด๋‚˜ ์Œ๋ฐ›์นจ์ด ๋ชจ์Œ์œผ๋กœ ์‹œ์ž‘๋œ ์กฐ์‚ฌ๋‚˜ ์–ด๋ฏธ, ์ ‘๋ฏธ์‚ฌ์™€ ๊ฒฐํ•ฉ๋˜๋Š” ๊ฒฝ์šฐ์—๋Š”, ์ œ ์Œ๊ฐ€๋Œ€๋กœ ๋’ค ์Œ์ ˆ ์ฒซ์†Œ๋ฆฌ๋กœ ์˜ฎ๊ฒจ ๋ฐœ์Œํ•œ๋‹ค.
-> ๊นŽ์•„[๊นŒ๊นŒ], ์˜ท์ด[์˜ค์‹œ], ์žˆ์–ด[์ด์จ], ๋‚ฎ์ด[๋‚˜์ง€]
-> ๊ฝ‚์•„[๊ผฌ์ž], ๊ฝƒ์„[๊ผฌ์ธจ], ์ซ“์•„[์ชผ์ฐจ], ๋ฐญ์—[๋ฐ”ํ…Œ]
-> ์•ž์œผ๋กœ[์•„ํ”„๋กœ], ๋ฎ์ด๋‹ค[๋”ํ”ผ๋‹ค] 

References

If you use our software for research, please cite:

@misc{park2019g2pk,
  author = {Park, Kyubyong},
  title = {g2pK},
  year = {2019},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/Kyubyong/g2pk}}
}

More Repositories

1

transformer

A TensorFlow Implementation of the Transformer: Attention Is All You Need
Python
4,126
star
2

nlp_tasks

Natural Language Processing Tasks and References
3,018
star
3

wordvectors

Pre-trained word vectors of 30+ languages
Python
2,199
star
4

tacotron

A TensorFlow Implementation of Tacotron: A Fully End-to-End Text-To-Speech Synthesis Model
Python
1,818
star
5

numpy_exercises

Numpy exercises.
Python
1,672
star
6

dc_tts

A TensorFlow Implementation of DC-TTS: yet another text-to-speech model
Python
1,147
star
7

sudoku

Can Neural Networks Crack Sudoku?
Python
821
star
8

g2p

g2p: English Grapheme To Phoneme Conversion
Python
734
star
9

tensorflow-exercises

TensorFlow Exercises - focusing on the comparison with NumPy.
Python
535
star
10

deepvoice3

Tensorflow Implementation of Deep Voice 3
Python
452
star
11

css10

CSS10: A Collection of Single Speaker Speech Datasets for 10 Languages
HTML
440
star
12

neural_chinese_transliterator

Can CNNs transliterate Pinyin into Chinese characters correctly?
Python
330
star
13

pytorch_exercises

Jupyter Notebook
312
star
14

bert_ner

Ner with Bert
Python
278
star
15

word_prediction

Word Prediction using Convolutional Neural Networks
Python
251
star
16

nlp_made_easy

Explains nlp building blocks in a simple manner.
Jupyter Notebook
247
star
17

g2pC

g2pC: A Context-aware Grapheme-to-Phoneme Conversion module for Chinese
Python
231
star
18

expressive_tacotron

Tensorflow Implementation of Expressive Tacotron
Python
196
star
19

speaker_adapted_tts

Making a TTS model with 1 minute of speech samples within 10 minutes
184
star
20

neural_japanese_transliterator

Can neural networks transliterate Romaji into Japanese correctly?
Python
173
star
21

tacotron_asr

Speech Recognition Using Tacotron
Python
165
star
22

quasi-rnn

Character-level Neural Translation using Quasi-RNNs
Python
134
star
23

label_smoothing

Corrupted labels and label smoothing
Jupyter Notebook
127
star
24

bert-token-embeddings

Jupyter Notebook
97
star
25

mtp

Multi-lingual Text Processing
95
star
26

cross_vc

Cross-lingual Voice Conversion
Python
94
star
27

name2nat

name2nat: a Python package for nationality prediction from a name
Python
89
star
28

pron_dictionaries

pronunciation dictionaries for multiple languages
Python
79
star
29

msg_reply

a simple message reply suggestion system
Python
78
star
30

word_ordering

Can neural networks order a scramble of words correctly?
Python
74
star
31

kss

Python
70
star
32

neural_tokenizer

Tokenize English sentences using neural networks.
Python
64
star
33

bytenet_translation

A TensorFlow Implementation of Machine Translation In Neural Machine Translation in Linear Time
Python
60
star
34

KoParadigm

KoParadigm: Korean Inflectional Paradigm Generator
Python
54
star
35

specAugment

Tensor2tensor experiment with SpecAugment
Python
46
star
36

vq-vae

A Tensorflow Implementation of VQ-VAE Speaker Conversion
Python
43
star
37

lm_finetuning

Language Model Fine-tuning for Moby Dick
Python
42
star
38

texture_generation

An Implementation of 'Texture Synthesis Using Convolutional Neural Networks' with Kylberg Texture Dataset
Python
33
star
39

integer_sequence_learning

RNN Approaches to Integer Sequence Learning--the famous Kaggle competition
Python
27
star
40

cjk_trans

Pre-trained Machine Translation Models of Korean from/to ECJ
27
star
41

h2h_converter

Convert Sino-Korean words written in Hangul to Chinese characters, which is called hanja in Korean, using neural networks
Python
25
star
42

up_and_running_with_Tensorflow

A simple tutorial of TensorFlow + TensorFlow / NumPy exercises
Jupyter Notebook
13
star
43

neurobind

Yet Another Model Using Neural Networks for Predicting Binding Preferences of for Test DNA Sequences
Python
11
star
44

kollocate

Collocation Search of Korean
Python
9
star
45

kyubyong

9
star
46

WhereAmI

Where Am I? - If you want to meet me.
5
star
47

spam_detection

Spam Dectection Under Semi-supervised settings
5
star
48

helo_word

A Neural Grammatical Error Correction System Built On Better Pre-training and Sequential Transfer Learning
Python
2
star