Skip to content
forked from hankcs/HanLP

中文分词 词性标注 命名实体识别 依存句法分析 成分句法分析 语义依存分析 语义角色标注 指代消解 风格转换 语义相似度 新词发现 关键词短语提取 自动摘要 文本分类聚类 拼音简繁转换 自然语言处理

License

Notifications You must be signed in to change notification settings

Fakerycoder/HanLP

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HanLP: Han Language Processing

English | 中文 | docs | 1.x | forum | Open In Colab

研究者や企業向けの多言語NLPライブラリで、PyTorchとTensorFlow 2.xをベースに構築されており、学術界と産業界の両方で最先端の深層学習技術を発展させるためのものです。HanLPは初日から、効率的で使いやすく、拡張性があるように設計されています。

Universal DependenciesやOntoNotesのようなオープンアクセスのコーパスのおかげで、HanLP 2.1は104言語の共同タスクを提供しています:形態素解析、係り受け解析、句構造解析、述語項構造、意味的依存性解析、抽象的意味表現(AMR)解析。

エンドユーザに対しては、HanLPは軽量なRESTful APIとネイティブなPython APIを提供します。

RESTful APIs

アジャイル開発やモバイルアプリケーションのための、数KBの小さなパッケージです。匿名での利用も可能ですが、認証キーの使用が推奨されており、CC BY-NC-SA 4.0ライセンスのもと、フリーで使用できます。

Python

pip install hanlp_restful

まずはAPI URLとあなたの認証キーでクライアントを作成します。

from hanlp_restful import HanLPClient
HanLP = HanLPClient('https://hanlp.hankcs.com/api', auth=None, language='mul')

Java

以下の依存関係をpom.xmlに挿入します。

<dependency>
  <groupId>com.hankcs.hanlp.restful</groupId>
  <artifactId>hanlp-restful</artifactId>
  <version>0.0.7</version>
</dependency>

まずはAPI URLとあなたの認証キーでクライアントを作成します。

HanLPClient HanLP = new HanLPClient("https://hanlp.hankcs.com/api", null, "mul");

Quick Start

どの言語を使っていても、同じインターフェースで言語を解析することができます。

HanLP.parse("In 2021, HanLPv2.1 delivers state-of-the-art multilingual NLP techniques to production environments. 2021年、HanLPv2.1は次世代の最先端多言語NLP技術を本番環境に導入します。2021年 HanLPv2.1为生产环境带来次世代最先进的多语种NLP技术。")

視覚化、アノテーションのガイドライン、その他の詳細については、この説明を参照してください。

Native APIs

pip install hanlp

HanLPにはPython 3.6以降が必要です。GPU/TPUが推奨されていますが、必須ではありません

Quick Start

import hanlp
HanLP = hanlp.load(hanlp.pretrained.mtl.NPCMJ_UD_KYOTO_TOK_POS_CON_BERT_BASE_CHAR_JA)
print(HanLP(['2021年、HanLPv2.1は次世代の最先端多言語NLP技術を本番環境に導入します。',
             '奈須きのこは1973年11月28日に千葉県円空山で生まれ、ゲーム制作会社「ノーツ」の設立者だ。',]))

特に、PythonのHanLPClientは、同じセマンティクスに従って呼び出し可能な関数としても使用できます。視覚化、アノテーションのガイドライン、および詳細については、この説明を参照してください。

自分のモデル

DLモデルを書くことは難しくありませんが、本当に難しいのは、論文のスコアを再現できるモデルを書くことです。下記のスニペットは、6分で最先端のトークナイザーを超える方法を示しています。

tokenizer = TransformerTaggingTokenizer()
save_dir = 'data/model/cws/sighan2005_pku_bert_base_96.70'
tokenizer.fit(
    SIGHAN2005_PKU_TRAIN_ALL,
    SIGHAN2005_PKU_TEST,  # Conventionally, no devset is used. See Tian et al. (2020).
    save_dir,
    'bert-base-chinese',
    max_seq_len=300,
    char_level=True,
    hard_constraint=True,
    sampler_builder=SortingSamplerBuilder(batch_size=32),
    epochs=3,
    adam_epsilon=1e-6,
    warmup_steps=0.1,
    weight_decay=0.01,
    word_dropout=0.1,
    seed=1609836303,
)
tokenizer.evaluate(SIGHAN2005_PKU_TEST, save_dir)

ランダムフィードが固定されているため、結果は96.70であることが保証されています。いくつかの過大評価されている論文やプロジェクトとは異なり、HanLPはスコアの一桁ごとに再現性があることを約束します。再現性に問題がある場合は、最優先で致命的なバグとして扱われ、解決されます。

パフォーマンス

langcorporamodeltokposnerdepconsrlsdplemfeaamr
finecoarsectbpku863udpkumsraontonotesSemEval16DMPASPSD
mulUD2.7
OntoNotes5
small98.62----93.23--74.4279.1076.8570.63-91.1993.6785.3487.7184.51-
base99.67----96.51--80.7687.6480.5877.22-94.3896.1086.6494.3791.60-
zhopensmall97.25-96.66-----95.0084.5787.6273.4084.57------
base97.50-97.07-----96.0487.1189.8477.7887.11------
closesmall96.7095.9396.8797.5695.05-96.2295.7476.7984.4488.1375.8174.28------
base97.5296.4496.9997.5995.29-96.4895.7277.7785.2988.5776.5273.76------
  • AMRモデルは、論文が採択された時点で公開されます。

Citing

あなたの研究でHanLPを使用する場合は、このリポジトリを引用してください。

@inproceedings{he-choi-2021-stem,
    title = "The Stem Cell Hypothesis: Dilemma behind Multi-Task Learning with Transformer Encoders",
    author = "He, Han and Choi, Jinho D.",
    booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing",
    month = nov,
    year = "2021",
    address = "Online and Punta Cana, Dominican Republic",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2021.emnlp-main.451",
    pages = "5555--5577",
    abstract = "Multi-task learning with transformer encoders (MTL) has emerged as a powerful technique to improve performance on closely-related tasks for both accuracy and efficiency while a question still remains whether or not it would perform as well on tasks that are distinct in nature. We first present MTL results on five NLP tasks, POS, NER, DEP, CON, and SRL, and depict its deficiency over single-task learning. We then conduct an extensive pruning analysis to show that a certain set of attention heads get claimed by most tasks during MTL, who interfere with one another to fine-tune those heads for their own objectives. Based on this finding, we propose the Stem Cell Hypothesis to reveal the existence of attention heads naturally talented for many tasks that cannot be jointly trained to create adequate embeddings for all of those tasks. Finally, we design novel parameter-free probes to justify our hypothesis and demonstrate how attention heads are transformed across the five tasks during MTL through label analysis.",
}

License

Codes

HanLPは、Apache License 2.0でライセンスされています。HanLPは、お客様の商用製品に無料でお使いいただけます。あなたのウェブサイトにHanLPへのリンクを追加していただければ幸いです。

Models

特に断りのない限り、HanLPのすべてのモデルは、CC BY-NC-SA 4.0でライセンスされています。

References

https://hanlp.hankcs.com/docs/references.html

About

中文分词 词性标注 命名实体识别 依存句法分析 成分句法分析 语义依存分析 语义角色标注 指代消解 风格转换 语义相似度 新词发现 关键词短语提取 自动摘要 文本分类聚类 拼音简繁转换 自然语言处理

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.5%
  • Java 1.5%