🚀 Flair中用於德語法律文本的命名實體識別(默認模型)
本項目是基於 Flair 開發的德語法律命名實體識別(NER)模型。該模型在德語法律文本的命名實體識別任務中表現出色,能夠準確識別多種類型的實體。
模型指標
在LER德語數據集上,該模型的F1分數達到了 96.35。
可預測的標籤
該模型能夠預測19種標籤,具體如下:
標籤 |
含義 |
AN |
律師 |
EUN |
歐洲標準 |
GS |
法律 |
GRT |
法院 |
INN |
機構 |
LD |
州 |
LDS |
地區 |
LIT |
文獻 |
MRK |
品牌 |
ORG |
組織 |
PER |
個人 |
RR |
法官 |
RS |
判例法 |
ST |
城市 |
STR |
街道 |
UN |
企業 |
VO |
條例 |
VS |
規定 |
VT |
合同 |
技術基礎
該模型基於 Flair嵌入 和LSTM - CRF構建。
數據集詳情
有關法律NER數據集的更多詳細信息,請參考 此處。
🚀 快速開始
環境要求
需要安裝 Flair,可以使用以下命令進行安裝:
pip install flair
代碼示例
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/ner-german-legal")
sentence = Sentence("Herr W. verstieß gegen § 36 Abs. 7 IfSG.", use_tokenizer=False)
tagger.predict(sentence)
print(sentence)
print('The following NER tags are found:')
for entity in sentence.get_spans('ner'):
print(entity)
輸出示例
Span [2]: "W." [− Labels: PER (0.9911)]
Span [5,6,7,8,9]: "§ 36 Abs. 7 IfSG." [− Labels: GS (0.5353)]
在句子 "Herr W. verstieß gegen § 36 Abs. 7 IfSG." 中,識別出了實體 "W."(標記為 個人)和 "§ 36 Abs. 7 IfSG"(標記為 法律)。
🔧 模型訓練腳本
以下是用於訓練該模型的Flair腳本:
from flair.data import Corpus
from flair.datasets import LER_GERMAN
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
corpus: Corpus = LER_GERMAN()
tag_type = 'ner'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
WordEmbeddings('de'),
FlairEmbeddings('de-forward'),
FlairEmbeddings('de-backward'),
]
embeddings = StackedEmbeddings(embeddings=embedding_types)
from flair.models import SequenceTagger
tagger = SequenceTagger(hidden_size=256,
embeddings=embeddings,
tag_dictionary=tag_dictionary,
tag_type=tag_type)
from flair.trainers import ModelTrainer
trainer = ModelTrainer(tagger, corpus)
trainer.train('resources/taggers/ner-german-legal',
train_with_dev=True,
max_epochs=150)
📄 引用說明
使用此模型時,請引用以下論文:
@inproceedings{leitner2019fine,
author = {Elena Leitner and Georg Rehm and Julian Moreno-Schneider},
title = {{Fine-grained Named Entity Recognition in Legal Documents}},
booktitle = {Semantic Systems. The Power of AI and Knowledge
Graphs. Proceedings of the 15th International Conference
(SEMANTiCS 2019)},
year = 2019,
pages = {272--287},
pdf = {https://link.springer.com/content/pdf/10.1007%2F978-3-030-33220-4_20.pdf}}
@inproceedings{akbik2018coling,
title={Contextual String Embeddings for Sequence Labeling},
author={Akbik, Alan and Blythe, Duncan and Vollgraf, Roland},
booktitle = {{COLING} 2018, 27th International Conference on Computational Linguistics},
pages = {1638--1649},
year = {2018}
}
❓ 問題反饋
如果遇到問題,可以在 Flair問題跟蹤器 中反饋。