Home

Awesome

** new: how to use the model for NER task, see below **

<img src="./images/logo-biobertpr1.png" alt="Logo BioBERTpt">

BioBERTpt - Portuguese Clinical and Biomedical BERT

This repository contains fine-tuned BERT models trained on the clinical domain for Portuguese language. Pre-trained BERT-multilingual-cased were fine-tuned with clinical narratives from Brazilian hospitals and abstracts of scientific papers from Pubmed and Scielo.

Table of contents

Contributors

Students:

Professors:

1 Pontifícia Universidade Católica do Paraná, Brazil

2 University of Applied Sciences and Arts of Western Switzerland

Attention-head view

This is a example of the attention visualizing in the Transformer model with BioBERTpt(all), using BertViz. The attention-head view visualizes the attention patterns produced by one or more attention heads in a given transformer layer.

<img src="./images/exemplo.gif" alt="Attention-head view">
(...)
model_version = 'pucpr/biobertpt-all'
do_lower_case = True
model = BertModel.from_pretrained(model_version, output_attentions=True)
tokenizer = BertTokenizer.from_pretrained(model_version, do_lower_case=do_lower_case)
sentence_a = "A paciente tomou paracetamol, pois estava com febre."
sentence_b = "Ela ficou sonolenta e foi se deitar."
show_head_view(model, tokenizer, sentence_a, sentence_b)

BioBERTpt on Hugging Faces repo

BioBERTpt models are on Hugging Faces repo:

BioBERTpt(all): A clinical and biomedical language model for Portuguese

BioBERTpt(clin): A clinical language model for Portuguese (trained with EHR from hospitals)

BioBERTpt(bio): A biomedical language model for Portuguese (trained with scientific papers from Pubmed and Scielo)

These models were fine-tuned on Portuguese clinical and biomedical data, from BERT-multilingual. These models refers to in-domains models, without a specific task.

If the models were useful, we would love to receive a like ❤️

<img src="./images/like-biobertpt-all.jpg" alt="BioBERTpt">

Next, see how to use BioBERTpt models for the NER task.

NER Experiment in SemClinBr Corpora

We evaluate our models on SemClinBr, a semantically annotated corpus for Portuguese clinical NER, containing 1,000 labeled clinical notes. These corpus comprehended 100 UMLS semantic types, summarized in 13 groups of entities: Disorders, Chemicals and Drugs, Medical Procedure, Diagnostic Procedure, Disease Or Syndrome, Findings, Health Care Activity, Laboratory or Test Result, Medical Device, Pharmacologic Substance, Quantitative Concept, Sign or Symptom and Therapeutic or Preventive Procedure.

All NER models are available in the Hugging Faces repository.

The table below shows complete F1-score results for each entity in SemClinBr, where the last three models (in italian) are our in-domain models. In bold, the higher values.

Entity / ModelDisordersChemicalDrugsProceduresDiagProcedDiseaseSyndFindingsHeatlhLaboratoryMedicalPharmacologicQuantitativeSignTherapeutic
BERT multilingual uncased0.78680.90260.66960.54620.56240.50340.37350.37780.55850.75570.60680.51850.4874
BERT multilingual cased0.78230.90100.67440.51930.53800.50460.41230.41680.59270.59270.61290.53660.4862
Portuguese BERT large0.62500.78230.45250.50430.57450.52640.33550.40410.51350.72250.56150.55170.4888
Portuguese BERT base0.78440.90380.67210.55580.53990.5000.34620.42230.53660.77540.56760.53750.4712
BioBERtpt (bio)0.78530.89390.68930.55070.57490.52600.45910.39810.60420.72370.59190.53350.5008
BioBERtpt (clin)0.78050.91090.68550.55950.58290.52070.40570.45260.56180.77910.59260.54350.4593
BioBERtpt (all)0.79130.90420.70320.54810.56410.51730.40370.44000.55520.74720.59970.56570.5128

How to use the model

Load the model via the transformers library:

from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("pucpr/biobertpt-all")
model = AutoModel.from_pretrained("pucpr/biobertpt-all")

How to use the model for the NER task

  1. Download a fine-tuned model for NER
  2. See how to use a NER model (notebook).
  3. How to use the model with docker

Prerequisite


Please download the amazing Huggingface implementation of BERT.

For more information, you can refer to these examples.

Reproduce BioBERTpt


To replicate our work, or fine-tune you own model, just do this steps:

git clone https://github.com/huggingface/transformers
cd transformers
pip install .

mkdir data

# please put your corpus file in this folder in a txt format

python examples/run_language_modeling.py --output_dir=output --model_type=bert \
    --model_name_or_path=bert-base-multilingual-cased --do_train --train_data_file=data/corpus.txt  --num_train_epochs 15 --mlm \
	--learning_rate 1e-5  --per_gpu_train_batch_size 16 --seed 666 --block_size=512

Acknowledgements

This study was financed in part by the Coordenação de Aperfeiçoamento de Pessoal de Nível Superior - Brasil (CAPES) - Finance Code 001.

Citation

@inproceedings{schneider-etal-2020-biobertpt,
    title = "{B}io{BERT}pt - A {P}ortuguese Neural Language Model for Clinical Named Entity Recognition",
    author = "Schneider, Elisa Terumi Rubel  and
      de Souza, Jo{\~a}o Vitor Andrioli  and
      Knafou, Julien  and
      Oliveira, Lucas Emanuel Silva e  and
      Copara, Jenny  and
      Gumiel, Yohan Bonescki  and
      Oliveira, Lucas Ferro Antunes de  and
      Paraiso, Emerson Cabrera  and
      Teodoro, Douglas  and
      Barra, Cl{\'a}udia Maria Cabral Moro",
    booktitle = "Proceedings of the 3rd Clinical Natural Language Processing Workshop",
    month = nov,
    year = "2020",
    address = "Online",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/2020.clinicalnlp-1.7",
    pages = "65--72",
    abstract = "With the growing number of electronic health record data, clinical NLP tasks have become increasingly relevant to unlock valuable information from unstructured clinical text. Although the performance of downstream NLP tasks, such as named-entity recognition (NER), in English corpus has recently improved by contextualised language models, less research is available for clinical texts in low resource languages. Our goal is to assess a deep contextual embedding model for Portuguese, so called BioBERTpt, to support clinical and biomedical NER. We transfer learned information encoded in a multilingual-BERT model to a corpora of clinical narratives and biomedical-scientific papers in Brazilian Portuguese. To evaluate the performance of BioBERTpt, we ran NER experiments on two annotated corpora containing clinical narratives and compared the results with existing BERT models. Our in-domain model outperformed the baseline model in F1-score by 2.72{\%}, achieving higher performance in 11 out of 13 assessed entities. We demonstrate that enriching contextual embedding models with domain literature can play an important role in improving performance for specific NLP tasks. The transfer learning process enhanced the Portuguese biomedical NER model by reducing the necessity of labeled data and the demand for retraining a whole new model.",
}

Star History

Star History Chart