https://huggingface.co/sshleifer/distilbart-cnn-6-6 包含 ONNX 权重,以确保与 Transformers.js 兼容。
如果您尚未安装,可以通过以下命令从 NPM 安装 Transformers.js JavaScript 库:
npm i @huggingface/transformers示例: 文本摘要。
import { pipeline } from '@huggingface/transformers';
const generator = await pipeline('summarization', 'Xenova/distilbart-cnn-6-6');
const text = 'The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, ' +
'and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. ' +
'During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest ' +
'man-made structure in the world, a title it held for 41 years until the Chrysler Building in New ' +
'York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to ' +
'the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the ' +
'Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second ' +
'tallest free-standing structure in France after the Millau Viaduct.';
const output = await generator(text, {
max_new_tokens: 100,
});注意:为 ONNX 权重单独设立仓库是一种临时解决方案,旨在等待 WebML 获得更广泛的应用。如果您希望让您的模型具备网页部署能力,我们建议使用 🤗 Optimum 将模型转换为 ONNX 格式,并按照本仓库的结构进行组织(将 ONNX 权重放置在名为 onnx 的子文件夹中)。