Spanish RobertaForQuestionAnswering (from BSC-TeMU)

Description

Pretrained Question Answering model, adapted from Hugging Face and curated to provide scalability and production-readiness using Spark NLP. roberta-large-bne-sqac is a Spanish model originally trained by BSC-TeMU.

Download Copy S3 URI

How to use

document_assembler = MultiDocumentAssembler() \ 
.setInputCols(["question", "context"]) \
.setOutputCols(["document_question", "document_context"])

spanClassifier = RoBertaForQuestionAnswering.pretrained("roberta_qa_BSC_TeMU_roberta_large_bne_sqac","es") \
.setInputCols(["document_question", "document_context"]) \
.setOutputCol("answer") \
.setCaseSensitive(True)

pipeline = Pipeline().setStages([
document_assembler,
spanClassifier
])

example = spark.createDataFrame([["What's my name?", "My name is Clara and I live in Berkeley."]]).toDF("question", "context")

result = pipeline.fit(example).transform(example)
val document = new MultiDocumentAssembler()
.setInputCols("question", "context")
.setOutputCols("document_question", "document_context")

val spanClassifier = RoBertaForQuestionAnswering
.pretrained("roberta_qa_BSC_TeMU_roberta_large_bne_sqac","es")
.setInputCols(Array("document_question", "document_context"))
.setOutputCol("answer")
.setCaseSensitive(true)
.setMaxSentenceLength(512)

val pipeline = new Pipeline().setStages(Array(document, spanClassifier))

val example = Seq(
("Where was John Lenon born?", "John Lenon was born in London and lived in Paris. My name is Sarah and I live in London."),
("What's my name?", "My name is Clara and I live in Berkeley."))
.toDF("question", "context")

val result = pipeline.fit(example).transform(example)
import nlu
nlu.load("es.answer_question.sqac.roberta.large").predict("""What's my name?|||"My name is Clara and I live in Berkeley.""")

Model Information

Model Name: roberta_qa_BSC_TeMU_roberta_large_bne_sqac
Compatibility: Spark NLP 4.0.0+
License: Open Source
Edition: Official
Input Labels: [question, context]
Output Labels: [answer]
Language: es
Size: 1.3 GB
Case sensitive: true
Max sentence length: 512

References

  • https://huggingface.co/BSC-TeMU/roberta-large-bne-sqac
  • https://github.com/PlanTL-SANIDAD/lm-spanish
  • http://www.bne.es/en/Inicio/index.html
  • https://arxiv.org/abs/1907.11692
  • https://arxiv.org/abs/2107.07253