by taishi-i

taishi-i / nagisa

A Japanese tokenizer based on recurrent neural networks

234 Stars 16 Forks Last release: 4 months ago (0.2.7) MIT License 152 Commits 9 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Codacy Badge Build Status Build status Coverage Status Documentation Status PyPI Downloads

Nagisa is a python module for Japanese word segmentation/POS-tagging. It is designed to be a simple and easy-to-use tool.

This tool has the following features. - Based on recurrent neural networks. - The word segmentation model uses character- and word-level features [池田+]. - The POS-tagging model uses tag dictionary information [Inoue+].

For more details refer to the following links. - The slides at PyCon JP 2019 is available here. - The article in Japanese is available here. - The documentation is available here.


Python 2.7.x or 3.5+ is required. This tool uses DyNet (the Dynamic Neural Network Toolkit) to calcucate neural networks. You can install nagisa by using the following command.

pip install nagisa
For Windows users, please run it with python 3.6 or 3.7 (64bit).

Basic usage

Sample of word segmentation and POS-tagging for Japanese.

import nagisa

text = 'Pythonで簡単に使えるツールです' words = nagisa.tagging(text) print(words) #=> Python/名詞 で/助詞 簡単/形状詞 に/助動詞 使える/動詞 ツール/名詞 です/助動詞

Get a list of words

print(words.words) #=> ['Python', 'で', '簡単', 'に', '使える', 'ツール', 'です']

Get a list of POS-tags

print(words.postags) #=> ['名詞', '助詞', '形状詞', '助動詞', '動詞', '名詞', '助動詞']

Post-processing functions

Filter and extarct words by the specific POS tags. ```python

Filter the words of the specific POS tags.

words = nagisa.filter(text, filter_postags=['助詞', '助動詞']) print(words)

=> Python/名詞 簡単/形状詞 使える/動詞 ツール/名詞

Extarct only nouns.

words = nagisa.extract(text, extract_postags=['名詞']) print(words)

=> Python/名詞 ツール/名詞

This is a list of available POS-tags in nagisa.


=> ['補助記号', '名詞', ... , 'URL']

Add the user dictionary in easy way.
# default
text = "3月に見た「3月のライオン」"
#=> 3/名詞 月/名詞 に/助詞 見/動詞 た/助動詞 「/補助記号 3/名詞 月/名詞 の/助詞 ライオン/名詞 」/補助記号

If a word ("3月のライオン") is included in the single_word_list, it is recognized as a single word.

new_tagger = nagisa.Tagger(single_word_list=['3月のライオン']) print(new_tagger.tagging(text)) #=> 3/名詞 月/名詞 に/助詞 見/動詞 た/助動詞 「/補助記号 3月のライオン/名詞 」/補助記号

Train a model

Nagisa (v0.2.0+) provides a simple train method for a joint word segmentation and sequence labeling (e.g, POS-tagging, NER) model.

The format of the train/dev/test files is tsv. Each line is

and one line is represented by
. Note that you put EOS between sentences. Refer to sample datasets and tutorial (Train a model for Universal Dependencies).
$ cat sample.train
唯一  NOUN
趣味  NOU
料理  NOUN
とても   ADV
おいしかっ ADJ
です  AUX
ドル  NOUN
主要  ADJ
通貨  NOUN
# After finish training, save the three model files (*.vocabs, *.params, *.hp)."sample.train", dev_file="", test_file="sample.test", model_name="sample")

Build the tagger by loading the trained model files.

sample_tagger = nagisa.Tagger(vocabs='sample.vocabs', params='sample.params', hp='sample.hp')

text = "福岡・博多の観光情報" words = sample_tagger.tagging(text) print(words) #> 福岡/PROPN ・/SYM 博多/PROPN の/ADP 観光/NOUN 情報/NOUN

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.