ner bert
1.0.0
이 아키텍처를 기반으로하는 두 가지 솔루션이 있습니다.
이 저장소에는 논문 Bert와 함께 출시 된 Bert 모델에 대한 Google의 Tensorflow 저장소의 Pytorch 재 구현에 기반한 NER 작업 솔루션이 포함되어 있습니다. Jacob Devlin, Ming-Wei Chang, Kenton Lee 및 Kristina Toutanova의 언어 이해를위한 깊은 양방향 변압기의 사전 훈련.
이 구현은 BERT (특히 Google의 미리 훈련 된 모델)에 대해 미리 훈련 된 Tensorflow 체크 포인트를로드 할 수 있습니다.
이전 버전은 "오래된"지점에 있습니다.
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)
우리는 최고의 매개 변수를 검색하지 않았고 다음 결과를 얻었습니다.
| 모델 | 데이터 세트 | Dev F1 토크 | Dev F1 스팬 | F1 토크를 테스트하십시오 | F1 스팬을 테스트하십시오 |
|---|---|---|---|---|---|
| 우리 것 | |||||
| M-Bertcrf-Io | Factrueval | - | - | 0.8543 | 0.8409 |
| m-bertncrf-io | Factrueval | - | - | 0.8637 | 0.8516 |
| m-bertbilstmcrf-io | Factrueval | - | - | 0.8835 | 0.8718 |
| m-bertbilstmncrf-io | Factrueval | - | - | 0.8632 | 0.8510 |
| M-Bertattncrf-Io | Factrueval | - | - | 0.8503 | 0.8346 |
| m-bertbilstmattncrf-io | Factrueval | - | - | 0.8839 | 0.8716 |
| m-bertbilstmattnncrf-io | Factrueval | - | - | 0.8807 | 0.8680 |
| m-bertbilstmattncrf-fit_bert-io | Factrueval | - | - | 0.8823 | 0.8709 |
| m-bertbilstmattnncrf-fit_bert-io | Factrueval | - | - | 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 | - |
| 현재 소타 | |||||
| DeepPavlov-Rubert-oner | Factrueval | - | - | - | 0.8266 |
| CSE | Conll-2003 | - | - | 0.931 | - |
| 베르트 라지 | Conll-2003 | 0.966 | - | 0.928 | - |
| 버트베이스 | Conll-2003 | 0.964 | - | 0.924 | - |