【导读】TensorFlow.js是将TensorFlow产品化的重要工具之一。本文介绍HuggingFace的开源QA项目,它基于TensorFlow.js,达到了Python版本两倍以上的性能。
TensorFlow.js是TensorFlow的Node.js版本,由于Node.js在工业界的广泛应用,TensorFlow.js成为了AI学术界与工业界之间的重要桥梁之一。近期,TensorFlow官方Twitter推荐了HuggingFace开源的项目Question Answering for Node.js,该项目基于TensorFlow.js实现,使用DistilBERT模型构建了QA系统:
说到HuggingFace大家应该并不陌生, 他们近期开源了许多高质量的AI项目,收到了Yann LeCun的极大赞赏:
Question Answering for Node.js项目的Github地址如下:
https://github.com/huggingface/node-question-answering
与许多其他Node.js库一样,我们可以通过一行命令一键安装Question Answering for Node.js:
npm install question-answering
该示例在本地运行模型,所以你需要先下载模型和词汇文件:
npx question-answering download
调用代码:
import { QAClient } from "question-answering";
const text = `
Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season.
The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California.
As this was the 50th Super Bowl, the league emphasized the "golden anniversary" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as "Super Bowl L"), so that the logo could prominently feature the Arabic numerals 50.
`;
const question = "Who won the Super Bowl?";
const qaClient = await QAClient.fromOptions();
const answer = await qaClient.predict(question, text);
console.log(answer); // { text: 'Denver Broncos', score: 0.3 }
更多相关信息请参考项目Github首页:
https://github.com/huggingface/node-question-answering