ku-nlp / rhoknp

Yet another Python binding for Juman++/KNP/KWJA

Home Page:https://rhoknp.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KWJAに於いてオプション指定がうまくいかない

YasuOhara opened this issue · comments

環境

Google Colab(CPU)

$ pip install kwja
$ pip install torch==1.13.1+cu116 -f https://download.pytorch.org/whl/torch_stable.html

二行目のtorchの再インストールは、KWJAのpip installのままだと以下のエラーが出て動かないため暫定的に実行しています。

$ kwja --tasks typo --text "人口知能"
/usr/local/lib/python3.8/dist-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: libtorch_cuda_cu.so: cannot open shared object file: No such file or directory
  warn(f"Failed to load image Python extension: {e}")
2023-03-02 09:11:24.580523: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
free(): invalid pointer

本題&実行例

KWJAをオプション付きで実行する際に、直接KWJAを叩けば結果は得られます。
しかしながらrhoknpを使用すると結果が得られません。
実行方法に誤り等があればご教示いただけますと幸いです。

  • KWJA(オプション付き)
$ kwja --tasks typo --text "人口知能"
"人工知能"
  • rhoknp(オプション付き)
$ from rhoknp import KWJA
$ kwja = KWJA(options=["--tasks", "typo"])
$ # kwja = KWJA(options=["--tasks typo"])  # 1行上と同結果
$ analyzed_document = kwja.apply(
$     "人口知能"
$ )
$ analyzed_document.text
""
  • rhoknp(オプションなし)
$ from rhoknp import KWJA
$ kwja = KWJA()
$ analyzed_document = kwja.apply(
$     "人口知能"
$ )
$ analyzed_document.text
"人工知能"

rhoknp.KWJA の実装が KWJA で単語レベルの解析まで行うこと(言い換えれば --tasksword が指定されること)を前提としていることが原因です。近日中に対応します。

ご確認いただきありがとうございます。
確かに、KWJA(options=["--tasks", "typo,char,word"])とすると動きました。
何卒よろしくお願いいたします。

この問題を解決した rhoknp v1.2.1 をリリースしました.

所望のオプションで実行することができました。
ご対応いただきありがとうございます。