GithubHelp home page GithubHelp logo

ikegami-yukino / rakutenma-python Goto Github PK

View Code? Open in Web Editor NEW
21.0 5.0 1.0 24.63 MB

Rakuten MA (Python version)

License: Apache License 2.0

Python 100.00%
nlp python word-segmentation japanese-language chinese part-of-speech-tagger pos-tagging

rakutenma-python's Introduction

Rakuten MA Python

travis-ci.org coveralls.io pyversion latest version Code Health license

Rakuten MA Python (morphological analyzer) is a Python version of Rakuten MA (word segmentor + PoS Tagger) for Chinese and Japanese.

For details about Rakuten MA, See https://github.com/rakuten-nlp/rakutenma

See also http://qiita.com/yukinoi/items/925bc238185aa2fad8a7 (In Japanese)

Contributions are welcome!

Installation

pip install rakutenma

Example

from rakutenma import RakutenMA

# Initialize a RakutenMA instance with an empty model
# the default ja feature set is set already
rma = RakutenMA()

# Let's analyze a sample sentence (from http://tatoeba.org/jpn/sentences/show/103809)
# With a disastrous result, since the model is empty!
print(rma.tokenize("彼は新しい仕事できっと成功するだろう。"))

# Feed the model with ten sample sentences from tatoeba.com
# "tatoeba.json" is available at https://github.com/rakuten-nlp/rakutenma
import json
tatoeba = json.load(open("tatoeba.json"))
for i in tatoeba:
    rma.train_one(i)

# Now what does the result look like?
print(rma.tokenize("彼は新しい仕事できっと成功するだろう。"))

# Initialize a RakutenMA instance with a pre-trained model
rma = RakutenMA(phi=1024, c=0.007812)  # Specify hyperparameter for SCW (for demonstration purpose)
rma.load("model_ja.json")

# Set the feature hash function (15bit)
rma.hash_func = rma.create_hash_func(15)

# Tokenize one sample sentence
print(rma.tokenize("うらにわにはにわにわとりがいる"));

# Re-train the model feeding the right answer (pairs of [token, PoS tag])
res = rma.train_one(
       [["うらにわ","N-nc"],
        ["に","P-k"],
        ["は","P-rj"],
        ["にわ","N-n"],
        ["にわとり","N-nc"],
        ["が","P-k"],
        ["いる","V-c"]])
# The result of train_one contains:
#   sys: the system output (using the current model)
#   ans: answer fed by the user
#   update: whether the model was updated
print(res)

# Now what does the result look like?
print(rma.tokenize("うらにわにはにわにわとりがいる"))

NOTE

Added API

As compared to original RakutenMA, following methods are added:

  • RakutenMA::load(model_path) - Load model from JSON file
  • RakutenMA::save(model_path) - Save model to path

misc

As initial setting, following values are set:

  • rma.featset = CTYPE_JA_PATTERNS # RakutenMA.default_featset_ja
  • rma.hash_func = rma.create_hash_func(15)
  • rma.tag_scheme = "SBIEO" # if using Chinese, set "IOB2"

LICENSE

Apache License version 2.0

Copyright

Rakuten MA Python (c) 2015- Yukino Ikegami. All Rights Reserved.

Rakuten MA (original) (c) 2014 Rakuten NLP Project. All Rights Reserved.

rakutenma-python's People

Contributors

ikegami-yukino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

pombredanne

rakutenma-python's Issues

Chinese analysis problem

Hello.
I just ran a simple lines like this, but it does not shows good results like demo page.

from rakutenma import RakutenMA


rma = RakutenMA()
rma.load("model_zh.min.json")

print(rma.tokenize("我把我的成功归功于他。"))

=>

[['我把我的成功归功', 'VV'], ['于', 'NR'], ['他', ''], ['。', '']]

Is there something more I have to do?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.