Package: kwja
KWJA: Kyoto-Waseda Japanese Analyzer[^1][^1]: Pronunciation:/kuʒa/[Paper][Slides]KWJA is an integrated Japanese text analyzer based on foundation models.
KWJA performs many text analysis tasks, including:Typo correctionSentence segmentationWord segmentationWord normalizationMorphological analysisWord feature taggingBase phrase feature taggingNER (Named Entity Recognition)Dependency parsingPredicate-argument structure (PAS) analysisBridging reference resolutionCoreference resolutionDiscourse relation analysisRequirementsPython: 3.8+Dependencies: Seepyproject.toml.GPUs with CUDA 11.7 (optional)Getting StartedInstall KWJA with pip:$pipinstallkwjaPerform language analysis with thekwjacommand (the result is in the KNP format):# Analyze a text$kwja--text"KWJAは日本語の統合解析ツールです。汎用言語モデルを利用し、様々な言語解析を統一的な方法で解いています。"# Analyze text files and write the result to a file$kwja--filenamepath/to/file1.txt--filenamepath/to/file2.txt>path/to/analyzed.knp# Analyze texts interactively$kwja
Pleaseendyourinputwithanewlineandtype"EOD"KWJAは日本語の統合解析ツールです。汎用言語モデルを利用し、様々な言語解析を統一的な方法で解いています。
EODIf you use Windows and PowerShell, you need to setPYTHONUTF8environment variable to1:>$env:PYTHONUTF8="1">kwja...The output is in the KNP format, which looks like the following:# S-ID:202210010000-0-0 kwja:1.0.2
* 2D
+ 5D <rel type="=" target="ツール" sid="202210011918-0-0" id="5"/><体言><NE:ARTIFACT:KWJA>
KWJA ＫWＪＡ KWJA 名詞 6 固有名詞 3 * 0 * 0 <基本句-主辞>
は は は 助詞 9 副助詞 2 * 0 * 0 "代表表記:は/は" <代表表記:は/は>
* 2D
+ 2D <体言>
日本 にほん 日本 名詞 6 地名 4 * 0 * 0 "代表表記:日本/にほん 地名:国" <代表表記:日本/にほん><地名:国><基本句-主辞>
+ 4D <体言><係:ノ格>
語 ご 語 名詞 6 普通名詞 1 * 0 * 0 "代表表記:語/ご 漢字読み:音 カテゴリ:抽象物" <代表表記:語/ご><漢字読み:音><カテゴリ:抽象物><基本句-主辞>
の の の 助詞 9 接続助詞 3 * 0 * 0 "代表表記:の/の" <代表表記:の/の>
...Here are options forkwjacommand:--text: Text to be analyzed.--filename: Path to a text file to be analyzed. You can specify this option multiple times.--model-size: Model size to be used. Specify one oftiny,base(default), andlarge.--device: Device to be used. Specifycpuorgpu. If not specified, the device is automatically selected.--typo-batch-size: Batch size for typo module.--senter-batch-size: Batch size for senter module.--seq2seq-batch-size: Batch size for seq2seq module.--char-batch-size: Batch size for character module.--word-batch-size: Batch size for word module.--tasks: Tasks to be performed. Specify one or more of the following values separated by commas:typo: Typo correctionsenter: Sentence segmentationseq2seq: Word segmentation, Word normalization, Reading prediction, lemmatization, and Canonicalization.char: Word segmentation and Word normalizationword: Morphological analysis, Named entity recognition, Word feature tagging, Dependency parsing, PAS analysis, Bridging reference resolution, and Coreference resolution--config-file: Path to a custom configuration file.You can read a KNP format file withrhoknp.fromrhoknpimportDocumentwithopen("analyzed.knp")asf:parsed_document=Document.from_knp(f.read())For more details about KNP format, seeReference.Usage from PythonMake sure you havekwjacommand in your path:$whichkwja
/path/to/kwjaInstallrhoknp:$pipinstallrhoknpPerform language analysis with thekwjainstance:fromrhoknpimportKWJAkwja=KWJA()analyzed_document=kwja.apply("KWJAは日本語の統合解析ツールです。汎用言語モデルを利用し、様々な言語解析を統一的な方法で解いています。")Configurationkwjacan be configured with a configuration file to set the default options.
CheckConfig file contentfor details.Config file locationOn non-Windows systemskwjafollows theXDG Base Directory Specificationconvention for the location of the configuration file.
The configuration dirkwjauses is itself namedkwja.
In that directory it refers to a file namedconfig.yaml.
For most people it should be enough to put their config file at~/.config/kwja/config.yaml.
You can also provide a configuration file in a non-standard location with an environment variableKWJA_CONFIG_FILEor a command line option--config-file.Config file examplemodel_size:basedevice:cpunum_workers:0torch_compile:falsetypo_batch_size:1senter_batch_size:1seq2seq_batch_size:1char_batch_size:1word_batch_size:1Performance Tabletypo, senter, character, and word modulesThe performance on each task except typo correction and discourse relation analysis is the mean over all the corpora (KC, KWDLC, Fuman, and WAC) and over three runs with different random seeds.We set the learning rate of RoBERTaLARGE(word) to 2e-5 because we failed to fine-tune it with a higher learning rate.
Other hyperparameters are the same described in configs, which are tuned for DeBERTaBASE.seq2seq moduleThe performance on each task is the mean over all the corpora (KC, KWDLC, Fuman, and WAC).* denotes results of a single runScores are calculated using a separatescriptfrom the character and word modules.TaskModelv1.x base(char,word)v2.x base(char,word/seq2seq)v1.x large(char,word)v2.x large(char,word/seq2seq)Typo Correction79.076.780.883.1Sentence Segmentation-98.4-98.6Word Segmentation98.598.1 / 98.2*98.798.4 / 98.4*Word Normalization44.015.339.848.6Morphological AnalysisPOS99.399.499.399.4sub-POS98.198.598.298.5conjtype99.499.699.299.6conjform99.599.799.499.7reading95.595.4 / 96.2*90.895.6 / 96.8*lemma-- / 97.8*-- / 98.1*canon-- / 95.2*-- / 95.9*Named Entity Recognition83.084.682.185.9Linguistic Feature Taggingword98.398.698.598.6base phrase86.693.686.493.4Dependency Parsing92.993.593.893.6Pas Analysis74.276.975.377.5Bridging Reference Resolution66.567.365.267.5Coreference Resolution74.978.675.979.2Discourse Relation Analysis42.239.241.344.3Citation@InProceedings{Ueda2023a,author={Nobuhiro Ueda and Kazumasa Omura and Takashi Kodama and Hirokazu Kiyomaru and Yugo Murawaki and Daisuke Kawahara and Sadao Kurohashi},title={KWJA: A Unified Japanese Analyzer Based on Foundation Models},booktitle={Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics: System Demonstrations},year={2023},address={Toronto, Canada},}@InProceedings{植田2022,author={植田 暢大 and 大村 和正 and 児玉 貴志 and 清丸 寛一 and 村脇 有吾 and 河原 大輔 and 黒橋 禎夫},title={KWJA：汎用言語モデルに基づく日本語解析器},booktitle={第253回自然言語処理研究会},year={2022},address={京都},}@InProceedings{児玉2023,author={児玉 貴志 and 植田 暢大 and 大村 和正 and 清丸 寛一 and 村脇 有吾 and 河原 大輔 and 黒橋 禎夫},title={テキスト生成モデルによる日本語形態素解析},booktitle={言語処理学会 第29回年次大会},year={2023},address={沖縄},}LicenseThis software is released under the MIT License, seeLICENSE.ReferenceKNP format