ner bert
1.0.0
Es gibt zwei Lösungen, die auf dieser Architektur basieren.
Dieses Repository enthält eine Lösung der NER-Aufgabe, die auf der Pytorch-Neuauflagen des Tensorflow-Repositorys von Google für das Bert-Modell zusammen mit dem Papierbert veröffentlicht wurde: Vorausbildung von tiefen bidirektionalen Transformatoren für das Sprachverständnis von Jacob Devlin, Ming-Wei, Kenton Lee und Kristina Toutanova.
Diese Implementierung kann jeden vorgeborenen Tensorflow-Checkpoint für Bert (insbesondere Google-Modelle von Google) laden.
Die alte Version ist in "Old" -Ast.
from modules.data import bert_data
data = bert_data.LearnData.create(
train_df_path=train_df_path,
valid_df_path=valid_df_path,
idx2labels_path="/path/to/vocab",
clear_cache=True
)
from modules.models.bert_models import BERTBiLSTMAttnCRF
model = BERTBiLSTMAttnCRF.create(len(data.train_ds.idx2label))
from modules.train.train import NerLearner
num_epochs = 100
learner = NerLearner(
model, data, "/path/for/save/best/model", t_total=num_epochs * len(data.train_dl))
from modules.data.bert_data import get_data_loader_for_predict
learner.load_model()
dl = get_data_loader_for_predict(data, df_path="/path/to/df/for/predict")
preds = learner.predict(dl)
from sklearn_crfsuite.metrics import flat_classification_report
from modules.analyze_utils.utils import bert_labels2tokens, voting_choicer
from modules.analyze_utils.plot_metrics import get_bert_span_report
from modules.analyze_utils.main_metrics import precision_recall_f1
pred_tokens, pred_labels = bert_labels2tokens(dl, preds)
true_tokens, true_labels = bert_labels2tokens(dl, [x.bert_labels for x in dl.dataset])
tokens_report = flat_classification_report(true_labels, pred_labels, digits=4)
print(tokens_report)
results = precision_recall_f1(true_labels, pred_labels)
Wir haben nicht die besten Parameter gesucht und die folgenden Ergebnisse erzielt.
| Modell | Datensatz | Dev F1 TOK | Dev F1 Span | Testen Sie F1 TOK | Test F1 Span |
|---|---|---|---|---|---|
| UNSERE | |||||
| M-Bertcrf-io | Spackrueval | - - | - - | 0,8543 | 0,8409 |
| M-Berbercrf-io | Spackrueval | - - | - - | 0,8637 | 0,8516 |
| M-Bertbilstmcrf-io | Spackrueval | - - | - - | 0,8835 | 0,8718 |
| M-Bertbilstmncrf-io | Spackrueval | - - | - - | 0,8632 | 0,8510 |
| M-Berberattncrf-io | Spackrueval | - - | - - | 0,8503 | 0,8346 |
| M-Bertbilstmattncrf-io | Spackrueval | - - | - - | 0,8839 | 0,8716 |
| M-Bertbilstmattnncrf-io | Spackrueval | - - | - - | 0,8807 | 0,8680 |
| M-Bertbilstmattncrf-fit_bert-io | Spackrueval | - - | - - | 0,8823 | 0,8709 |
| M-Bertbilstmattnncrf-fit_bert-io | Spackrueval | - - | - - | 0,8583 | 0,8456 |
| - - | - - | - - | - - | - - | - - |
| Bertbilstmcrf-io | Conll-2003 | 0,9629 | - - | 0,9221 | - - |
| B-Bertbilstmcrf-io | Conll-2003 | 0,9635 | - - | 0,9229 | - - |
| B-Bertbilstmattncrf-io | Conll-2003 | 0,9614 | - - | 0,9237 | - - |
| B-Bertbilstmattnncrf-io | Conll-2003 | 0,9631 | - - | 0,9249 | - - |
| Aktueller Sota | |||||
| Deeppavlov-rubert-nun | Spackrueval | - - | - - | - - | 0,8266 |
| CSE | Conll-2003 | - - | - - | 0,931 | - - |
| Bert-Large | Conll-2003 | 0,966 | - - | 0,928 | - - |
| Bert-Base | Conll-2003 | 0,964 | - - | 0,924 | - - |