Views
No views yet
| tag | meaning |
|---|---|
| AN | Anwalt |
| EUN | Europäische Norm |
| GS | Gesetz |
| GRT | Gericht |
| INN | Institution |
| LD | Land |
| LDS | Landschaft |
| LIT | Literatur |
| MRK | Marke |
| ORG | Organisation |
| PER | Person |
| RR | Richter |
| RS | Rechtssprechung |
| ST | Stadt |
| STR | Straße |
| UN | Unternehmen |
| VO | Verordnung |
| VS | Vorschrift |
| VT | Vertrag |
pip install flair)1from flair.data import Sentence
2from flair.models import SequenceTagger
3
4# load tagger
5tagger = SequenceTagger.load("flair/ner-german-legal")
6
7# make example sentence (don't use tokenizer since Rechtstexte are badly handled)
8sentence = Sentence("Herr W. verstieß gegen § 36 Abs. 7 IfSG.", use_tokenizer=False)
9
10
11# predict NER tags
12tagger.predict(sentence)
13
14# print sentence
15print(sentence)
16
17# print predicted NER spans
18print('The following NER tags are found:')
19# iterate over entities and print
20for entity in sentence.get_spans('ner'):
21 print(entity)
22Span [2]: "W." [− Labels: PER (0.9911)]
Span [5,6,7,8,9]: "§ 36 Abs. 7 IfSG." [− Labels: GS (0.5353)]
1from flair.data import Corpus
2from flair.datasets import LER_GERMAN
3from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
4
5# 1. get the corpus
6corpus: Corpus = LER_GERMAN()
7
8# 2. what tag do we want to predict?
9tag_type = 'ner'
10
11# 3. make the tag dictionary from the corpus
12tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
13
14# 4. initialize each embedding we use
15embedding_types = [
16
17 # GloVe embeddings
18 WordEmbeddings('de'),
19
20 # contextual string embeddings, forward
21 FlairEmbeddings('de-forward'),
22
23 # contextual string embeddings, backward
24 FlairEmbeddings('de-backward'),
25]
26
27# embedding stack consists of Flair and GloVe embeddings
28embeddings = StackedEmbeddings(embeddings=embedding_types)
29
30# 5. initialize sequence tagger
31from flair.models import SequenceTagger
32
33tagger = SequenceTagger(hidden_size=256,
34 embeddings=embeddings,
35 tag_dictionary=tag_dictionary,
36 tag_type=tag_type)
37
38# 6. initialize trainer
39from flair.trainers import ModelTrainer
40
41trainer = ModelTrainer(tagger, corpus)
42
43# 7. run training
44trainer.train('resources/taggers/ner-german-legal',
45 train_with_dev=True,
46 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}
}