English BertForQuestionAnswering model (from EasthShin)

Description

Pretrained Question Answering model, adapted from Hugging Face and curated to provide scalability and production-readiness using Spark NLP. Klue-CommonSense-model is a English model orginally trained by EasthShin.

Download Copy S3 URI

How to use

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

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

Model Information

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

References

  • https://huggingface.co/EasthShin/Klue-CommonSense-model
  • https://mindslab.ai:8080/kr/company
  • https://ainize.ai/EastHShin/Klue-CommonSense_QA?branch=main
  • https://ainize.ai/workspace/create?imageId=hnj95592adzr02xPTqss&git=https://github.com/EastHShin/Klue-CommonSense-workspace
  • https://main-klue-common-sense-qa-east-h-shin.endpoint.ainize.ai/