{"id":13535178,"url":"https://github.com/ai-forever/ner-bert","last_synced_at":"2025-04-06T06:11:23.871Z","repository":{"id":49778320,"uuid":"158529372","full_name":"ai-forever/ner-bert","owner":"ai-forever","description":"BERT-NER (nert-bert) with google bert https://github.com/google-research.","archived":false,"fork":false,"pushed_at":"2020-02-03T13:30:37.000Z","size":487,"stargazers_count":407,"open_issues_count":3,"forks_count":98,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-30T05:06:47.417Z","etag":null,"topics":["atis","attention","bert","bert-model","bilstm-crf","classification","conll-2003","elmo","factrueval","joint-models","ner","ner-task","nlp","nmt","python","python3","pytorch","pytorch-model","transfer-learning"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ai-forever.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-21T10:15:33.000Z","updated_at":"2025-03-13T14:52:55.000Z","dependencies_parsed_at":"2022-09-14T08:41:43.137Z","dependency_job_id":null,"html_url":"https://github.com/ai-forever/ner-bert","commit_stats":null,"previous_names":["sberbank-ai/ner-bert","king-menin/ner-bert"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-forever%2Fner-bert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-forever%2Fner-bert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-forever%2Fner-bert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-forever%2Fner-bert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ai-forever","download_url":"https://codeload.github.com/ai-forever/ner-bert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441053,"owners_count":20939239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["atis","attention","bert","bert-model","bilstm-crf","classification","conll-2003","elmo","factrueval","joint-models","ner","ner-task","nlp","nmt","python","python3","pytorch","pytorch-model","transfer-learning"],"created_at":"2024-08-01T08:00:50.829Z","updated_at":"2025-04-06T06:11:23.852Z","avatar_url":"https://github.com/ai-forever.png","language":"Jupyter Notebook","funding_links":[],"categories":["BERT  NER  task:"],"sub_categories":[],"readme":"## 0. Papers\nThere are two solutions based on this architecture.\n1. [BSNLP 2019 ACL workshop](http://bsnlp.cs.helsinki.fi/shared_task.html): [solution](https://github.com/king-menin/slavic-ner) and [paper](https://arxiv.org/abs/1906.09978) on multilingual shared task.\n2. The second place [solution](https://github.com/king-menin/AGRR-2019) of [Dialogue AGRR-2019](https://github.com/dialogue-evaluation/AGRR-2019) task and [paper](http://www.dialog-21.ru/media/4679/emelyanov-artemova-gapping_parsing_using_pretrained_embeddings__attention_mechanisn_and_ncrf.pdf).\n\n## Description\nThis repository contains solution of NER task based on PyTorch [reimplementation](https://github.com/huggingface/pytorch-pretrained-BERT) of [Google's TensorFlow repository for the BERT model](https://github.com/google-research/bert) that was released together with the paper [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://arxiv.org/abs/1810.04805) by Jacob Devlin, Ming-Wei Chang, Kenton Lee and Kristina Toutanova.\n\nThis implementation can load any pre-trained TensorFlow checkpoint for BERT (in particular [Google's pre-trained models](https://github.com/google-research/bert)).\n\nOld version is in \"old\" branch.\n\n## 2. Usage\n### 2.1 Create data\n```\nfrom modules.data import bert_data\ndata = bert_data.LearnData.create(\n    train_df_path=train_df_path,\n    valid_df_path=valid_df_path,\n    idx2labels_path=\"/path/to/vocab\",\n    clear_cache=True\n)\n```\n\n### 2.2 Create model\n```\nfrom modules.models.bert_models import BERTBiLSTMAttnCRF\nmodel = BERTBiLSTMAttnCRF.create(len(data.train_ds.idx2label))\n```\n\n### 2.3 Create Learner\n```\nfrom modules.train.train import NerLearner\nnum_epochs = 100\nlearner = NerLearner(\n    model, data, \"/path/for/save/best/model\", t_total=num_epochs * len(data.train_dl))\n```\n\n### 2.4 Predict\n```\nfrom modules.data.bert_data import get_data_loader_for_predict\nlearner.load_model()\ndl = get_data_loader_for_predict(data, df_path=\"/path/to/df/for/predict\")\npreds = learner.predict(dl)\n```\n\n### 2.5 Evaluate\n```\nfrom sklearn_crfsuite.metrics import flat_classification_report\nfrom modules.analyze_utils.utils import bert_labels2tokens, voting_choicer\nfrom modules.analyze_utils.plot_metrics import get_bert_span_report\nfrom modules.analyze_utils.main_metrics import precision_recall_f1\n\n\npred_tokens, pred_labels = bert_labels2tokens(dl, preds)\ntrue_tokens, true_labels = bert_labels2tokens(dl, [x.bert_labels for x in dl.dataset])\ntokens_report = flat_classification_report(true_labels, pred_labels, digits=4)\nprint(tokens_report)\n\nresults = precision_recall_f1(true_labels, pred_labels)\n```\n\n## 3. Results\nWe didn't search best parametres and obtained the following results.\n\n| Model | Data set | Dev F1 tok | Dev F1 span | Test F1 tok | Test F1 span\n|-|-|-|-|-|-|\n|**OURS**||||||\n| M-BERTCRF-IO | [FactRuEval](https://github.com/dialogue-evaluation/factRuEval-2016) | - | - | 0.8543 | 0.8409\n| M-BERTNCRF-IO | [FactRuEval](https://github.com/dialogue-evaluation/factRuEval-2016) | - | - | 0.8637 | 0.8516\n| M-BERTBiLSTMCRF-IO | [FactRuEval](https://github.com/dialogue-evaluation/factRuEval-2016) | - | - | 0.8835 | **0.8718**\n| M-BERTBiLSTMNCRF-IO | [FactRuEval](https://github.com/dialogue-evaluation/factRuEval-2016) | - | - | 0.8632 | 0.8510\n| M-BERTAttnCRF-IO | [FactRuEval](https://github.com/dialogue-evaluation/factRuEval-2016) | - | - | 0.8503 | 0.8346\n| M-BERTBiLSTMAttnCRF-IO | [FactRuEval](https://github.com/dialogue-evaluation/factRuEval-2016) | - | - | **0.8839** | 0.8716\n| M-BERTBiLSTMAttnNCRF-IO | [FactRuEval](https://github.com/dialogue-evaluation/factRuEval-2016) | - | - | 0.8807 | 0.8680\n| M-BERTBiLSTMAttnCRF-fit_BERT-IO | [FactRuEval](https://github.com/dialogue-evaluation/factRuEval-2016) | - | - |  0.8823 | 0.8709\n| M-BERTBiLSTMAttnNCRF-fit_BERT-IO | [FactRuEval](https://github.com/dialogue-evaluation/factRuEval-2016) | - | - |  0.8583 | 0.8456\n|-|-|-|-|-|-|\n| BERTBiLSTMCRF-IO | [CoNLL-2003](https://github.com/synalp/NER/tree/master/corpus/CoNLL-2003) | 0.9629 | - | 0.9221 | -\n| B-BERTBiLSTMCRF-IO | [CoNLL-2003](https://github.com/synalp/NER/tree/master/corpus/CoNLL-2003) | 0.9635 | - | 0.9229 | -\n| B-BERTBiLSTMAttnCRF-IO | [CoNLL-2003](https://github.com/synalp/NER/tree/master/corpus/CoNLL-2003) | 0.9614 | - | 0.9237 | -\n| B-BERTBiLSTMAttnNCRF-IO | [CoNLL-2003](https://github.com/synalp/NER/tree/master/corpus/CoNLL-2003) | 0.9631 | - | **0.9249** | -\n|**Current SOTA**||||||\n| DeepPavlov-RuBERT-NER | [FactRuEval](https://github.com/dialogue-evaluation/factRuEval-2016) | - | - | - | **0.8266**\n| CSE | [CoNLL-2003](https://github.com/synalp/NER/tree/master/corpus/CoNLL-2003) | - | - | **0.931** | -\n| BERT-LARGE | [CoNLL-2003](https://github.com/synalp/NER/tree/master/corpus/CoNLL-2003) | 0.966 | - | 0.928 | -\n| BERT-BASE | [CoNLL-2003](https://github.com/synalp/NER/tree/master/corpus/CoNLL-2003) | 0.964 | - | 0.924 | -\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fai-forever%2Fner-bert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fai-forever%2Fner-bert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fai-forever%2Fner-bert/lists"}