中国語情報抽出のためのCNNベースツール

CNN4IE

プロジェクトURL: https://github.com/jiangnanboy/CNN4IE

本プロジェクトは、CNNの様々なバリエーションを用いて中国語情報抽出を実装するものです。今後、異なるモデルが継続的に追加されていきます。

CNN4IEは、CNNの各種改良版に基づき、異なるモデルブロックを融合させ、中国語情報抽出タスクに適用しています。

概要

現在の主な機能は中国語エンティティ抽出です:

学習データはB、I、O形式でアノテーションされています。

モデル

アーキテクチャ

  • MultiLayerResCNN(src/mlrescnn):マルチレイヤー残差CNN(+CRF)。

使用方法

  • パラメータ設定

config.cfgファイルを、トレーニングまたは推論時に読み込みます。

  • トレーニング(事前学習済みembeddingベクトルのロード対応)
from cnn4ie.mlrescnn.train import Train
trainer = Train()
trainer.run_training('config.cfg')

Epoch: 199 | Time: 0m 4s
  Train Loss: 228.545 | Train PPL: 1.802960293422957e+99
   Val. Loss: 433.577 |  Val. PPL: 1.9966207577208172e+188
   Val. report:               precision    recall  f1-score   support

         1       1.00      1.00      1.00      4539
         2       0.98      0.99      0.99      4926
         3       0.90      0.83      0.86       166
         4       0.74      0.98      0.84        52
         5       0.94      0.77      0.84       120
         6       0.76      0.97      0.85        39
         7       0.82      0.87      0.85        54
         8       0.93      0.74      0.82        68
         9       0.95      0.77      0.85        26
        10       1.00      0.80      0.89        10

  accuracy                           0.98     10000
  macro avg       0.90      0.87      0.88     10000
  weighted avg       0.99      0.98      0.98     10000

  • 推論
from cnn4ie.mlrescnn.predict import Predict

predictor = Predict()
predictor.load_model_vocab('config_cfg')
output = predictor.process_text('据新华社报道,安徽省六安市被评上十大易居城市!')

print(output)

[{'start': 7, 'stop': 13, 'word': '安徽省六安市', 'type': 'LOC'}, {'start': 1, 'stop': 4, 'word': '新华社', 'type': 'ORG'}]

評価

評価指標としてP、R、F1、PPLなどを使用しています。評価方法にはscikit-learnのprecision_recall_fscore_supportやclassification_reportが利用可能です。

インストール

  • インストール方法: pip install CNN4IE
  • ソースコードのダウンロード:
git clone https://github.com/jiangnanboy/CNN4IE.git
cd CNN4IE
python setup.py install

タグ: 中国語NLP 情報抽出 CNN ディープラーニング 自然言語処理

5月31日 06:45 投稿