基于 BERT 的问答系统

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

上手指南

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

如果您使用 Android 以外的平台,或者已经熟悉 TensorFlow Lite API,则可以下载我们的 入门问答模型,备用 下载地址 (文件上传时间 2020/4/25)。

工作方式

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

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

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

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

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

性能基准测试

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

模型名称 模型大小 设备 CPU
Mobile Bert 100.5 Mb Pixel 3 (Android 10) 123ms*
Pixel 4 (Android 10) 74ms*
iPhone XS (iOS 12.4.1) 257ms**

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

示例输出

Passage (输入)

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.

问题 (输入)

Who is the CEO of Google?

回答 (输出)

Sundar Pichai

阅读更多关于 BERT 的内容

原文:TensorFlow 文档:问题和答案 / 发布:TensorFlow 公众号