ner bert
1.0.0
มีสองวิธีที่อิงตามสถาปัตยกรรมนี้
พื้นที่เก็บข้อมูลนี้มีวิธีแก้ปัญหาของงาน NER โดยใช้การปรับปรุงใหม่ของ Pytorch Reimplementation ของที่เก็บ tensorflow ของ Google สำหรับโมเดล Bert ที่ปล่อยออกมาพร้อมกับ Paper Bert: การฝึกอบรมหม้อแปลงแบบสองทิศทางลึกสำหรับการทำความเข้าใจภาษาโดย Jacob Devlin, Ming-Wei Chang, Kenton Lee และ Kristina Toutanova
การใช้งานนี้สามารถโหลดจุดตรวจสอบ TensorFlow ที่ผ่านการฝึกอบรมมาล่วงหน้าสำหรับ BERT (โดยเฉพาะอย่างยิ่งโมเดลที่ผ่านการฝึกอบรมมาก่อนของ Google)
เวอร์ชันเก่าอยู่ในสาขา "เก่า"
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 tok | dev f1 span | ทดสอบ F1 TOK | ทดสอบ F1 ช่วง |
|---|---|---|---|---|---|
| ของเรา | |||||
| M-bertcrf-io | สิ่งที่ต้องทำ | - | - | 0.8543 | 0.8409 |
| m-bertncrf-io | สิ่งที่ต้องทำ | - | - | 0.8637 | 0.8516 |
| m-bertbilstmcrf-io | สิ่งที่ต้องทำ | - | - | 0.8835 | 0.8718 |
| m-bertbilstmncrf-io | สิ่งที่ต้องทำ | - | - | 0.8632 | 0.8510 |
| M-bertattncrf-io | สิ่งที่ต้องทำ | - | - | 0.8503 | 0.8346 |
| m-bertbilstmattncrf-io | สิ่งที่ต้องทำ | - | - | 0.8839 | 0.8716 |
| m-bertbilstmattnnncrf-io | สิ่งที่ต้องทำ | - | - | 0.8807 | 0.8680 |
| m-bertbilstmattncrf-fit_bert-io | สิ่งที่ต้องทำ | - | - | 0.8823 | 0.8709 |
| m-bertbilstmattnnncrf-fit_bert-io | สิ่งที่ต้องทำ | - | - | 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-bertbilstmattnnncrf-io | Conll-2003 | 0.9631 | - | 0.9249 | - |
| SOTA ปัจจุบัน | |||||
| Deeppavlov-Rubert-ner | สิ่งที่ต้องทำ | - | - | - | 0.8266 |
| CSE | Conll-2003 | - | - | 0.931 | - |
| เบิร์ตขนาดใหญ่ | Conll-2003 | 0.966 | - | 0.928 | - |
| เบิร์ตเบส | Conll-2003 | 0.964 | - | 0.924 | - |