Multilingual BertForQuestionAnswering model (from mrm8488)

Description

Pretrained Question Answering model, adapted from Hugging Face and curated to provide scalability and production-readiness using Spark NLP. bert-multi-cased-finetuned-xquadv1 is a Multilingual model orginally trained by mrm8488.

Download Copy S3 URI

How to use

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

spanClassifier = BertForQuestionAnswering.pretrained("bert_qa_bert_multi_cased_finetuned_xquadv1","xx") \
.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 = BertForQuestionAnswering
.pretrained("bert_qa_bert_multi_cased_finetuned_xquadv1","xx")
.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("xx.answer_question.xquad.bert.cased").predict("""What's my name?|||"My name is Clara and I live in Berkeley.""")

Model Information

Model Name: bert_qa_bert_multi_cased_finetuned_xquadv1
Compatibility: Spark NLP 4.0.0+
License: Open Source
Edition: Official
Input Labels: [sentence, token]
Output Labels: [embeddings]
Language: xx
Size: 665.6 MB
Case sensitive: true
Max sentence length: 512

References

  • https://huggingface.co/mrm8488/bert-multi-cased-finetuned-xquadv1
  • https://github.com/google-research/bert/blob/master/multilingual.md
  • https://twitter.com/mrm8488
  • https://github.com/moses-smt/mosesdecoder/blob/master/scripts/tokenizer/tokenizer.perl
  • https://colab.research.google.com/github/mrm8488/shared_colab_notebooks/blob/master/Try_mrm8488_xquad_finetuned_model.ipynb
  • https://github.com/fxsjy/jieba
  • https://github.com/deepmind/xquad