Package: adapted-NERDA
NERDANot only isNERDAa mesmerizing muppet-like character.NERDAis also
a python package, that offers a slick easy-to-use interface for fine-tuning
pretrained transformers for Named Entity Recognition
(=NER) tasks.You can also utilizeNERDAto access a selection ofprecookedNERDAmodels,
that you can use right off the shelf for NER tasks.NERDAis built onhuggingfacetransformersand the popularpytorchframework.Installation guideNERDAcan be installed fromPyPIwithpip install NERDAIf you want the development version then install directly fromGitHub.Named-Entity Recogntion tasksNamed-entity recognition (NER) (also known as (named) entity identification,
entity chunking, and entity extraction) is a subtask of information extraction
that seeks to locate and classify named entities mentioned in unstructured
text into pre-defined categories such as person names, organizations, locations, medical codes, time expressions, quantities, monetary values, percentages, etc.1Example Task:TaskIdentify person names and organizations in text:Jim bought 300 shares of Acme Corp.SolutionNamed EntityType'Jim'Person'Acme Corp.'OrganizationRead more about NER onWikipedia.Train Your OwnNERDAModelSay, we want to fine-tune a pretrainedMultilingual BERTtransformer for NER in English.Load package.fromNERDA.modelsimportNERDAInstantiate aNERDAmodel (with default settings) for theCoNLL-2003English NER data set.fromNERDA.datasetsimportget_conll_datamodel=NERDA(dataset_training=get_conll_data('train'),dataset_validation=get_conll_data('valid'),transformer='bert-base-multilingual-uncased')By default the network architecture is analogous to that of the models inHvingelby et al. 2020.The model can then be trained/fine-tuned by invoking thetrainmethod, e.g.model.train()Note: this will take some time depending on the dimensions of your machine
(if you want to skip training, you can go ahead and use one of the models,
that we have already precooked for you in stead).After the model has been trained, the model can be used for predicting
named entities in new texts.# text to identify named entities in.text='Old MacDonald had a farm'model.predict_text(text)([['Old','MacDonald','had','a','farm']],[['B-PER','I-PER','O','O','O']])This means, that the model identified 'Old MacDonald' as aPERson.Please note, that theNERDAmodel configuration above was instantiated
with all default settings. You can however customize yourNERDAmodel
in a lot of ways:Use your own data set (finetune a transformer for any given language)Choose whatever transformer you likeSet all of the hyperparameters for the modelYou can even apply your own Network ArchitectureRead more about advanced usage ofNERDAin thedetailed documentation.Use a PrecookedNERDAmodelWe have precooked a number ofNERDAmodels for Danish and English, that you can download
and use right off the shelf.Here is an example.Instantiate a multilingual BERT model, that has been finetuned for NER in Danish,DA_BERT_ML.fromNERDA.precookedimportDA_BERT_ML()model=DA_BERT_ML()Down(load) network from web:model.download_network()model.load_network()You can now predict named entities in new (Danish) texts# (Danish) text to identify named entities in:# 'Jens Hansen har en bondegård' = 'Old MacDonald had a farm'text='Jens Hansen har en bondegård'model.predict_text(text)([['Jens','Hansen','har','en','bondegård']],[['B-PER','I-PER','O','O','O']])List of Precooked ModelsThe table below shows the precookedNERDAmodels publicly available for download.ModelLanguageTransformerDatasetF1-scoreDA_BERT_MLDanishMultilingual BERTDaNE82.8DA_ELECTRA_DADanishDanish ELECTRADaNE79.8EN_BERT_MLEnglishMultilingual BERTCoNLL-200390.4EN_ELECTRA_ENEnglishEnglish ELECTRACoNLL-200389.1F1-scoreis the micro-averaged F1-score across entity tags and is
evaluated on the respective test sets (that have not been used for training nor
validation of the models).Note, that we have not spent a lot of time on actually fine-tuning the models,
so there could be room for improvement. If you are able to improve the models,
we will be happy to hear from you and include yourNERDAmodel.Model PerformanceThe table below summarizes the performance (F1-scores) of the precookedNERDAmodels.LevelDA_BERT_MLDA_ELECTRA_DAEN_BERT_MLEN_ELECTRA_ENB-PER93.892.096.095.1I-PER97.897.198.597.9B-ORG69.566.988.486.2I-ORG69.970.785.783.1B-LOC82.579.092.391.1I-LOC31.644.483.980.5B-MISC73.468.681.880.1I-MISC86.163.663.468.4AVG_MICRO82.879.890.489.1AVG_MACRO75.672.886.385.3'NERDA'?'NERDA' originally stands for'Named Entity Recognition for DAnish'. However, this
is somewhat misleading, since the functionality is no longer limited to Danish.
On the contrary it generalizes to all other languages, i.e.NERDAsupports
fine-tuning of transformers for NER tasks for any arbitrary
language.BackgroundNERDAis developed as a part ofEkstra Bladet’s activities on Platform Intelligence in News (PIN). PIN is an industrial research project that is carried out in collaboration between theTechnical University of Denmark,University of CopenhagenandCopenhagen Business Schoolwith funding fromInnovation Fund Denmark. The project runs from 2020-2023 and develops recommender systems and natural language processing systems geared for news publishing, some of which are open sourced likeNERDA.Shout-outsThanks toAlexandra Institutefor with thedanlppackage to have encouraged us to develop this package.Thanks toMalte Højmark-BertelsenandKasper Jungefor giving feedback onNERDA.Read moreThe detailed documentation forNERDAincluding code references and
extended workflow examples can be accessedhere.ContactWe hope, that you will findNERDAuseful.Please direct any questions and feedbacks tous!If you want to contribute (which we encourage you to), open aPR.If you encounter a bug or want to suggest an enhancement, pleaseopen an issue.