$ show lovit/soynlp
soynlp is a pure-Python library for unsupervised Korean natural language processing, providing statistical methods for tokenization, noun extraction, POS tagging, lemmatization, and text normalization. The architecture is modular, with subpackages for hangle (Hangul decomposition/composition), lemmatizer, normalizer, noun extraction (v1, v2, news), POS tagging (dictionary-based and LR-template-based), tokenization (LTokenizer, MaxScoreTokenizer, RegexTokenizer), vectorization (TF-IDF-like), word extraction (cohesion, branching entropy), and utility data structures (LRGraph, EojeolCounter). Key entry points include WordExtractor, LRNounExtractor_v2, LTokenizer, MaxScoreTokenizer, BaseVectorizer, and DoublespaceLineCorpus. Data flows typically involve reading a corpus of double-space-separated sentences, building LR substring frequency graphs, extracting word/noun scores, and then using those scores for tokenization or tagging. External dependencies are limited to numpy and scikit-learn (older versions). The repository also includes research-oriented tutorials (Jupyter notebooks) and pre-built linguistic resources (frequency dictionaries, trained noun predictors), making it a hybrid of a production library and a research codebase. The unsupervised approach is well-suited for homogeneous document collections where domain-specific adaptation is needed.
The LLM identified 4 files worth highlighting for reuse:
Contains LRGraph and EojeolCounter classes that build and query left-right substring frequency graphs from a corpus. This is a core data structure used across noun extraction, word extraction, and POS tagging. It is self-contained, requires only basic Python, and can be extracted for any substring frequency analysis task (e.g., collocation detection, morpheme segmentation). The implementation demonstrates non-obvious skill in efficient graph construction and traversal for unsupervised morphological analysis.
Provides functions to decompose and compose Hangul syllables into initial, medial, and final jamo (phonemes). This is a clean, self-contained utility that handles Unicode Hangul syllable blocks (U+AC00–U+D7A3). It can be reused in any Korean text processing project for tasks like normalization, sorting, or phonetic analysis. The implementation is efficient and well-documented, demonstrating deep understanding of the Hangul syllable structure.
Contains functions for normalizing Korean text: emoticon_normalize, repeat_normalize, only_hangle, and others. These are isolated, parameterized routines that solve common text cleaning problems (repeated characters, emoticon handling, filtering non-Hangul). They can be extracted and applied to any Korean text dataset with minimal adaptation. The code is concise and demonstrates practical data cleaning patterns.
Implements BaseVectorizer, a TF-IDF-like document vectorizer that supports fit-to-file for large corpora (streaming from disk) and encode/decode for bag-of-words representations. It is self-contained, parameterized (min_tf, max_tf, min_df, max_df), and can be reused for any text vectorization task. The fit-to-file pattern is a non-obvious optimization for memory-constrained environments, demonstrating good data engineering practice.