import gradio as gr
from transformers import pipeline
import torch
title = "Extractive QA Biomedicine"
description = """
Recent research has made available Spanish Language Models trained on Biomedical corpus. This project explores the use of these new models to generate extractive Question Answering models for Biomedicine, and compares their effectiveness with general masked language models.
The models were trained on the SQUAD_ES Dataset (automatic translation of the Stanford Question Answering Dataset into Spanish). SQUAD v2 version was chosen in order to include questions that cannot be answered based on a provided context.
The models were evaluated on BIOMED_SQUAD_ES_V2 Dataset , a subset of the SQUAD_ES evaluation dataset containing questions related to the Biomedical domain.
The project is aligned with goal number 3 of the Sustainable Development Goals promoted by the United Nations: "Ensure a healthy life and promote well-being for all at all ages", since this research can lead to the development of tools that facilitate the access to health information by doctors and Spanish-speaking people from all over the world.
In the following Demo, the four trained models can be tested to answer a question given a context (the confidence score - from 0 to 1 - of the predicted answer is also displayed):
"""
article = """
Results
Challenges
Question Answering is a complex task to understand, as it requires not only pre-processing the inputs, but also post-processing the outputs. Moreover, the metrics used are quite specific.
There is not as much documentation and tutorials available for QA as for other more popular NLP tasks. In particular, the examples provided are often focused on the SQUAD v1 format and not on SQUAD v2, the format selected for this project.
Before the Hackathon, there was no Biomedical QA dataset in Spanish publicly available (particularly with the SQUAD V2 format). It was necessary to create a validation Biomedical Dataset using the SQUAD_ES Dataset.
Conclusion and Future Work
If F1 Score is considered, the results show that there may be no advantage in using domain-specific masked language models to generate Biomedical QA models.
However, the F1 Scores reported for the Biomedical roberta-based models are not far below from those of the general roberta-based model.
If only unanswerable questions are taken into account, the model with the best F1 Score is hackathon-pln-es/roberta-base-biomedical-es-squad2-es.
The model hackathon-pln-es/biomedtra-small-es-squad2-es, on the contrary, shows inability to correctly identify unanswerable questions.
As future work, the following experiments could be carried out:
- Create Biomedical masked-language models adapted from a general model, to preserve words and features of Spanish that are also present in Biomedical questions and articles. The Biomedical base models used in the project were trained from scratch from a Biomedical corpus.
- Create a Biomedical training dataset with SQUAD v2 format.
- Generate a new and larger Spanish Biomedical validation dataset, not translated from English as in the case of SQUAD_ES Dataset.
- Ensamble different models.
Author
Santiago Maximo
"""
device = 0 if torch.cuda.is_available() else -1
MODEL_NAMES = ["hackathon-pln-es/roberta-base-bne-squad2-es",
"hackathon-pln-es/roberta-base-biomedical-clinical-es-squad2-es",
"hackathon-pln-es/roberta-base-biomedical-es-squad2-es",
"hackathon-pln-es/biomedtra-small-es-squad2-es"]
examples = [
[MODEL_NAMES[2], "¿Qué cidippido se utiliza como descripción de los ctenóforos en la mayoría de los libros de texto?","Para un filo con relativamente pocas especies, los ctenóforos tienen una amplia gama de planes corporales. Las especies costeras necesitan ser lo suficientemente duras para soportar las olas y remolcar partículas de sedimentos, mientras que algunas especies oceánicas son tan frágiles que es muy difícil capturarlas intactas para su estudio. Además, las especies oceánicas no conservan bien, y son conocidas principalmente por fotografías y notas de observadores. Por lo tanto, la mayor atención se ha concentrado recientemente en tres géneros costeros: Pleurobrachia, Beroe y Mnemiopsis. Al menos dos libros de texto basan sus descripciones de ctenóforos en los cidipépidos Pleurobrachia."],
[MODEL_NAMES[0], "¿Dónde se atasca un fagocito en un patógeno?", "La fagocitosis es una característica importante de la inmunidad celular innata llevada a cabo por células llamadas fagocitos que absorben, o comen, patógenos o partículas. Los fagocitos generalmente patrullan el cuerpo en busca de patógenos, pero pueden ser llamados a lugares específicos por citoquinas. Una vez que un patógeno ha sido absorbido por un fagocito, queda atrapado en una vesícula intracelular llamada fagosoma, que posteriormente se fusiona con otra vesícula llamada lisosoma para formar un fagocito."],
]
def getanswer(model_name, question, context):
question_answerer = pipeline("question-answering", model=model_name, device=device)
response = question_answerer({
'question': question,
'context': context
})
return response['answer'],response['score']
face = gr.Interface(
fn=getanswer,
inputs=[
gr.inputs.Radio(
label="Pick a QA Model",
choices=MODEL_NAMES,
),
gr.inputs.Textbox(lines=1, placeholder="Question Here… "),
gr.inputs.Textbox(lines=10, placeholder="Context Here… ")
],
outputs=[
gr.outputs.Textbox(label="Answer"),
gr.outputs.Textbox(label="Score"),
],
layout="vertical",
title=title,
examples=examples,
description=description,
article=article,
allow_flagging ="never"
)
face.launch()