查看原文
其他

基于 BERT 的问答系统

Google TensorFlow 2021-07-27
本文介绍了 TensorFlow Lite 中的问答模型,这是一个基于所给段落的内容回答问题的预训练模型。



使用入门

如果您刚接触 TensorFlow Lite,并应用在 Android,我们建议您探索以下可帮助您入门的示例应用。


Android 示例

如果您使用 Android 以外的平台,或者已经熟悉 TensorFlow Lite API,则可以下载我们的入门问答模型

  • TensorFlow Lite API
    https://tensorflow.google.cn/api_docs/python/tf/lite

  • 入门问答模型
    https://github.com/tensorflow/examples/tree/master/lite/examples/bert_qa/android


下载入门模型以及术语表
  • https://storage.googleapis.com/download.tensorflow.org/models/tflite/bert_qa/mobilebert_qa_vocab.zip



工作方式

预训练模型BERT用SQuAD 1.1 数据集上微调 (fine-tune) 训练所得的模型,可以创建一个基于自然语言处理的问答系统。


BERT 或 Bidirectional Encoder Representations from Transformers 是一种预训练语言表征方法,可在多项自然语言处理任务上获得非常出色的结果。

  • BERT
    https://github.com/google-research/bert


此应用使用压缩版 BERT(即 MobileBERT),不仅运行速度提高 4 倍,而且模型大小减小为原来的 1/4。


SQuAD 或 Stanford Question Answering Dataset 是一个阅读理解数据集,包含来自维基百科的文章和一套针对每篇文章的问答对。

  • SQuAD
    https://rajpurkar.github.io/SQuAD-explorer/


此模型将一段文章和一个问题作为输入,然后返回文章中最有可能回答问题的句段。模型需要半复合预处理,包括词条化和 BERT 论文 中介绍并在示例应用中实现的后处理步骤。

  • 论文
    https://arxiv.org/abs/1810.04805



性能基准

性能基准数据由此处介绍的工具生成。

  • 此处介绍
    https://tensorflow.google.cn/lite/performance/benchmarks

  • Mobile Bert
    https://storage.googleapis.com/download.tensorflow.org/models/tflite/bert_qa/mobilebert_qa_vocab.zip

* 使用 4 线程。

** iPhone 上使用 2 线程以获得最佳性能结果。



示例输出

Passage (Input)

Google LLC is an American multinational technology company that specializes in Internet-related services and products, which include online advertising technologies, search engine, cloud computing, software, and hardware. It is considered one of the Big Four technology companies, alongside Amazon, Apple, and Facebook.


Google was founded in September 1998 by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University in California. Together they own about 14 percent of its shares and control 56 percent of the stockholder voting power through supervoting stock. They incorporated Google as a California privately held company on September 4, 1998, in California. Google was then reincorporated in Delaware on October 22, 2002. An initial public offering (IPO) took place on August 19, 2004, and Google moved to its headquarters in Mountain View, California, nicknamed the Googleplex. In August 2015, Google announced plans to reorganize its various interests as a conglomerate called Alphabet Inc. Google is Alphabet's leading subsidiary and will continue to be the umbrella company for Alphabet's Internet interests. Sundar Pichai was appointed CEO of Google, replacing Larry Page who became the CEO of Alphabet.


Question (Input)

Who is the CEO of Google?


Answer (Output)

Sundar Pichai



阅读更多关于 BERT 的内容
  • Bert:用于语言理解的深度双向转换器预训练 (论文)
    https://arxiv.org/abs/1810.04805

  • Bert 的开源实现
    https://github.com/google-research/bert




    您可能也对以下帖子感兴趣

    文章有问题?点此查看未经处理的缓存