kiwipiepy Model
kiwipiepy-model provides the language models necessary for kiwipiepy, a fast and accurate Korean morphological analyzer. It is a data-only package, implicitly installed as a dependency when you install kiwipiepy. The current version is 0.23.0, and it generally updates in lockstep with major versions of the core kiwipiepy library to provide the latest model improvements.
Common errors
-
ModuleNotFoundError: No module named 'kiwipiepy'
cause You likely installed `kiwipiepy-model` but not `kiwipiepy` itself, or have not installed either.fixInstall the main library: `pip install kiwipiepy`. -
TypeError: Kiwi() got an unexpected keyword argument 'typo_correct_options'
cause In kiwipiepy v0.23.0+, `typo_correct_options` is no longer a constructor argument. It's now passed to analysis methods.fixPass `typo_correct_options` to `kiwi.tokenize()`, `kiwi.split_into_sentences()`, etc., instead of `Kiwi()`. -
TypeError: Kiwi() got an unexpected keyword argument 'oov_score_mode'
cause In kiwipiepy v0.23.0+, OOV handling is configured via the `oov_handling` parameter, replacing older arguments like `oov_score_mode`.fixRemove `oov_score_mode` from the `Kiwi` constructor. Use the new `oov_handling` parameter (e.g., `oov_handling='ngram'`) when initializing `Kiwi()` or in analysis methods.
Warnings
- breaking The `typo_correct_options` parameter for typo correction has been moved from the `Kiwi` constructor to the `tokenize`, `split_into_sentences`, etc., methods.
- breaking The way to specify OOV (Out-Of-Vocabulary) handling has changed from boolean flags or simple modes to a more flexible `oov_handling` parameter that accepts specific string values or configurations in the `Kiwi` constructor.
- gotcha The `kiwipiepy-model` package only provides the model files. You must install and import from the `kiwipiepy` package to use the morphological analyzer.
Install
-
pip install kiwipiepy -
pip install kiwipiepy-model
Imports
- Kiwi
from kiwipiepy_model import Kiwi
from kiwipiepy import Kiwi
Quickstart
from kiwipiepy import Kiwi
# Initialize Kiwi with default model (loaded from kiwipiepy-model)
kiwi = Kiwi(oov_handling='ngram') # Example with new oov_handling
text = "안녕하세요, 저는 키위입니다."
tokens = kiwi.tokenize(text)
for token in tokens:
print(f"Word: {token.form}, Tag: {token.tag}, Start: {token.start}, End: {token.end}")
sentences = kiwi.split_into_sentences("어제는 비가 왔어요. 오늘은 맑을 예정입니다.")
for sentence in sentences:
print(f"Sentence: {sentence.text}")
for token in sentence.tokens:
print(f" {token.form}/{token.tag}")