SpanNER: Named EntityRe-/Recognition as Span Prediction

Overview

SpanNER: Named EntityRe-/Recognition as Span Prediction

Overview | Demo | Installation | Preprocessing | Prepare Models | Running | System Combination | Bib

This repository contains the code for our paper SpanNER: Named EntityRe-/Recognition as Span Prediction (ACL 2021).

The model designed in this work has been deployed into ExplainaBoard.

Overview

We investigate complementary advantages of systems based on different paradigms: span prediction model and sequence labeling framework. We then reveal that span prediction, simultaneously, can serve as a system combiner to re-recognize named entities from different systems’ outputs. We experimentally implement 154 systems on 11 datasets, covering three languages, comprehensive results show the effectiveness of span prediction models that both serve as base NER systems and system combiners.

d

Demo

We deploy SpanNER into the ExplainaBoard.

Quick Installation

  • python3
  • PyTorch
  • pytorch-lightning

Run the following script to install the dependencies,

pip3 install -r requirements.txt

Data Preprocessing

The dataset needs to be preprocessed, before running the model. We provide dataprocess/bio2spannerformat.py for reference, which gives the CoNLL-2003 as an example. First, you need to download datasets, and then convert them into BIO2 tagging format. We provided the CoNLL-2003 dataset with BIO format in data/conll03_bio folder, and its preprocessed format dataset in data/conll03 folder.

The download links of the datasets used in this work are shown as follows:

Prepare Models

For English Datasets, we use BERT-Large.

For Dutch and Spanish Datasets, we use BERT-Multilingual-Base.

How to Run?

Here, we give CoNLL-2003 as an example. You may need to change the DATA_DIR, PRETRAINED, dataname, n_class to your own dataset path, pre-trained model path, dataset name, and the number of labels in the dataset, respectively.

./run_conll03_spanner.sh

System Combination

Base Model

We provided 12 base models (result-files) of CoNLL-2003 dataset in combination/results. More base model (result-files) can be download from ExplainaBoard-download.

Combination

Put your different base models (result-files) in the data/results folder, then run:

python comb_voting.py

Here, we provided four system combination methods, including:

  • SpanNER,
  • Majority voting (VM),
  • Weighted voting base on overall F1-score (VOF1),
  • Weighted voting base on class F1-score (VCF1).

Results at a Glance

d

Bib

@article{fu2021spanner,
  title={SpanNer: Named Entity Re-/Recognition as Span Prediction},
  author={Fu, Jinlan and Huang, Xuanjing and Liu, Pengfei},
  journal={arXiv preprint arXiv:2106.00641},
  year={2021}
}
You might also like...
[EMNLP 2021] Distantly-Supervised Named Entity Recognition with Noise-Robust Learning and Language Model Augmented Self-Training

RoSTER The source code used for Distantly-Supervised Named Entity Recognition with Noise-Robust Learning and Language Model Augmented Self-Training, p

“Data Augmentation for Cross-Domain Named Entity Recognition” (EMNLP 2021)
“Data Augmentation for Cross-Domain Named Entity Recognition” (EMNLP 2021)

Data Augmentation for Cross-Domain Named Entity Recognition Authors: Shuguang Chen, Gustavo Aguilar, Leonardo Neves and Thamar Solorio This repository

GLaRA: Graph-based Labeling Rule Augmentation for Weakly Supervised Named Entity Recognition
GLaRA: Graph-based Labeling Rule Augmentation for Weakly Supervised Named Entity Recognition

GLaRA: Graph-based Labeling Rule Augmentation for Weakly Supervised Named Entity Recognition

Example Of Fine-Tuning BERT For Named-Entity Recognition Task And Preparing For Cloud Deployment Using Flask, React, And Docker
Example Of Fine-Tuning BERT For Named-Entity Recognition Task And Preparing For Cloud Deployment Using Flask, React, And Docker

Example Of Fine-Tuning BERT For Named-Entity Recognition Task And Preparing For Cloud Deployment Using Flask, React, And Docker This repository contai

An elaborate and exhaustive paper list for Named Entity Recognition (NER)

Named-Entity-Recognition-NER-Papers by Pengfei Liu, Jinlan Fu and other contributors. An elaborate and exhaustive paper list for Named Entity Recognit

Price-Prediction-For-a-Dream-Home - A machine learning based linear regression trained model for house price prediction.
Price-Prediction-For-a-Dream-Home - A machine learning based linear regression trained model for house price prediction.

Price-Prediction-For-a-Dream-Home ROADMAP TO THIS LINEAR REGRESSION BASED HOUSE PRICE PREDICTION PREDICTION MODEL Import all the dependencies of the p

Doge-Prediction - Coding Club prediction ig

Doge-Prediction Coding Club prediction ig Basically: Create an application that

Joint detection and tracking model named DEFT, or ``Detection Embeddings for Tracking.
Joint detection and tracking model named DEFT, or ``Detection Embeddings for Tracking.

DEFT: Detection Embeddings for Tracking DEFT: Detection Embeddings for Tracking, Mohamed Chaabane, Peter Zhang, J. Ross Beveridge, Stephen O'Hara

Weakly supervised medical named entity classification

Trove Trove is a research framework for building weakly supervised (bio)medical named entity recognition (NER) and other entity attribute classifiers

Comments
  • TypeError: iteration over a 0-d tensor

    TypeError: iteration over a 0-d tensor

    您好,我在运行的时候出现如下的错误: Traceback (most recent call last): File "trainer.py", line 598, in main() File "trainer.py", line 592, in main trainer.fit(model) File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 552, in fit self._run(model) File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 917, in _run self._dispatch() File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 985, in _dispatch self.accelerator.start_training(self) File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/accelerators/accelerator.py", line 92, in start_training self.training_type_plugin.start_training(trainer) File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/plugins/training_type/training_type_plugin.py", line 161, in start_training self._results = trainer.run_stage() File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 995, in run_stage return self._run_train() File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1030, in _run_train self._run_sanity_check(self.lightning_module) File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1114, in _run_sanity_check self._evaluation_loop.run() File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/loops/base.py", line 118, in run output = self.on_run_end() File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/loops/dataloader/evaluation_loop.py", line 132, in on_run_end self.evaluation_epoch_end(outputs) File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/loops/dataloader/evaluation_loop.py", line 242, in evaluation_epoch_end model.validation_epoch_end(outputs) File "trainer.py", line 342, in validation_epoch_end correct_pred, total_pred, total_golden = all_counts File "/home/sdd/jsun/anaconda3/envs/py38/lib/python3.8/site-packages/torch/tensor.py", line 450, in iter raise TypeError('iteration over a 0-d tensor') TypeError: iteration over a 0-d tensor 我的pytorch-lightning的版本是最新版本,对pytorch-lightning不太熟悉,请问该如何解决?谢谢您

    opened by BeerTai 1
  • Something wrong with

    Something wrong with "clean_overlapping_span"

    Hi, clean_overlapping_span in eval_metrics.py seems to always keep the last non-O span, which is not right in some scenarios. For example, running the toy example below yields[(1, 2), (1, 4)], where only (1,2) should have been kept.

    idxs_list = [(1,2), (1,3), (1,4)]
    nonO_idxs2prob = {(1,2):0.7, (1,3):0.5, (1,4):0.6}
    print(clean_overlapping_span(idxs_list,nonO_idxs2prob))
    
    #[(1, 2), (1, 4)]
    

    This seems to be a result of the following lines. https://github.com/neulab/SpanNER/blob/dc9af161f54a9f866fddbba3f24bd54b3808b99a/eval_metric.py#L154-L158 What's the logic behind them? It looks wierd particularly because didxs is a list of bools but idxs_list[-1] is an index tuple?

    Once again, thanks for the great effort on this fantastic implementation.

    opened by RandyZhouRan 0
  • 多卡运行错误

    多卡运行错误

    您好,我单卡运行没有问题,多卡运行的时候就会出现这样的问题,希望能够得到您的解答 File "trainer.py", line 611, in main() File "trainer.py", line 605, in main trainer.fit(model) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/pytorch_lightning/trainer/states.py", line 48, in wrapped_fn result = fn(self, *args, **kwargs) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 1064, in fit results = self.accelerator_backend.train() File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/pytorch_lightning/accelerators/dp_backend.py", line 97, in train results = self.trainer.run_pretrain_routine(model) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 1224, in run_pretrain_routine self._run_sanity_check(ref_model, model) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 1257, in _run_sanity_check eval_results = self._evaluate(model, self.val_dataloaders, max_batches, False) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/pytorch_lightning/trainer/evaluation_loop.py", line 331, in _evaluate output = self.evaluation_forward(model, batch, batch_idx, dataloader_idx, test_mode) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/pytorch_lightning/trainer/evaluation_loop.py", line 661, in evaluation_forward output = model(*args) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/pytorch_lightning/overrides/data_parallel.py", line 83, in forward outputs = self.parallel_apply(replicas, inputs, kwargs) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/pytorch_lightning/overrides/data_parallel.py", line 147, in parallel_apply return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)]) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/pytorch_lightning/overrides/data_parallel.py", line 288, in parallel_apply raise output File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/pytorch_lightning/overrides/data_parallel.py", line 251, in _worker output = module.validation_step(*input, **kwargs) File "trainer.py", line 311, in validation_step all_span_rep = self.forward(loadall,all_span_lens,all_span_idxs_ltoken, tokens, attention_mask, token_type_ids) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/torch/cuda/amp/autocast_mode.py", line 135, in decorate_autocast return func(*args, **kwargs) File "trainer.py", line 201, in forward return self.model(loadall,all_span_lens,all_span_idxs_ltoken,input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/home/work/dev/wxp/SpanNER-main/models/bert_model_spanner.py", line 92, in forward bert_outputs = self.bert(input_ids, token_type_ids=token_type_ids, attention_mask=attention_mask) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/transformers/modeling_bert.py", line 753, in forward input_ids=input_ids, position_ids=position_ids, token_type_ids=token_type_ids, inputs_embeds=inputs_embeds File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/transformers/modeling_bert.py", line 178, in forward inputs_embeds = self.word_embeddings(input_ids) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/torch/nn/modules/sparse.py", line 126, in forward self.norm_type, self.scale_grad_by_freq, self.sparse) File "/home/work/anaconda3/envs/wxp_torch/lib/python3.7/site-packages/torch/nn/functional.py", line 1814, in embedding return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse) RuntimeError: arguments are located on different GPUs at /opt/conda/conda-bld/pytorch_1595629403081/work/aten/src/THC/generic/THCTensorIndex.cu:403

    opened by AlexXx-Wu 1
Owner
NeuLab
Graham Neubig's Lab at LTI/CMU
NeuLab
ReConsider is a re-ranking model that re-ranks the top-K (passage, answer-span) predictions of an Open-Domain QA Model like DPR (Karpukhin et al., 2020).

ReConsider ReConsider is a re-ranking model that re-ranks the top-K (passage, answer-span) predictions of an Open-Domain QA Model like DPR (Karpukhin

Facebook Research 47 Jul 26, 2022
The code for two papers: Feedback Transformer and Expire-Span.

transformer-sequential This repo contains the code for two papers: Feedback Transformer Expire-Span The training code is structured for long sequentia

Facebook Research 125 Dec 25, 2022
A sample pytorch Implementation of ACL 2021 research paper "Learning Span-Level Interactions for Aspect Sentiment Triplet Extraction".

Span-ASTE-Pytorch This repository is a pytorch version that implements Ali's ACL 2021 research paper Learning Span-Level Interactions for Aspect Senti

来自丹麦的天籁 10 Dec 6, 2022
An Easy-to-use, Modular and Prolongable package of deep-learning based Named Entity Recognition Models.

DeepNER An Easy-to-use, Modular and Prolongable package of deep-learning based Named Entity Recognition Models. This repository contains complex Deep

Derrick 9 May 30, 2022
Chinese clinical named entity recognition using pre-trained BERT model

Chinese clinical named entity recognition (CNER) using pre-trained BERT model Introduction Code for paper Chinese clinical named entity recognition wi

Xiangyang Li 109 Dec 14, 2022
Code for Two-stage Identifier: "Locate and Label: A Two-stage Identifier for Nested Named Entity Recognition"

Code for Two-stage Identifier: "Locate and Label: A Two-stage Identifier for Nested Named Entity Recognition", accepted at ACL 2021. For details of the model and experiments, please see our paper.

tricktreat 87 Dec 16, 2022
[ACL-IJCNLP 2021] Improving Named Entity Recognition by External Context Retrieving and Cooperative Learning

CLNER The code is for our ACL-IJCNLP 2021 paper: Improving Named Entity Recognition by External Context Retrieving and Cooperative Learning CLNER is a

null 71 Dec 8, 2022
Named Entity Recognition with Small Strongly Labeled and Large Weakly Labeled Data

Named Entity Recognition with Small Strongly Labeled and Large Weakly Labeled Data arXiv This is the code base for weakly supervised NER. We provide a

Amazon 92 Jan 4, 2023
Simple and Effective Few-Shot Named Entity Recognition with Structured Nearest Neighbor Learning

structshot Code and data for paper "Simple and Effective Few-Shot Named Entity Recognition with Structured Nearest Neighbor Learning", Yi Yang and Arz

ASAPP Research 47 Dec 27, 2022
Source Code For Template-Based Named Entity Recognition Using BART

Template-Based NER Source Code For Template-Based Named Entity Recognition Using BART Training Training train.py Inference inference.py Corpus ATIS (h

null 174 Dec 19, 2022