Inference Providers 文档
摘要
加入 Hugging Face 社区
并获取增强的文档体验
开始使用
摘要
摘要是生成文档的较短版本,同时保留其重要信息的任务。有些模型可以从原始输入中提取文本,而其他模型可以生成全新的文本。
有关 summarization
任务的更多详细信息,请查看其 专用页面!您将找到示例和相关材料。
推荐模型
- facebook/bart-large-cnn:一个强大的摘要模型,在英语新闻文章上训练。擅长生成基于事实的摘要。
- Falconsai/medical_summarization:一个在医学文章上训练的摘要模型。
浏览所有可用模型,并在此处找到最适合您的模型 here。
使用 API
from huggingface_hub import InferenceClient
client = InferenceClient(
provider="hf-inference",
api_key="hf_xxxxxxxxxxxxxxxxxxxxxxxx",
)
result = client.summarization(
inputs="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.",
model="facebook/bart-large-cnn",
)
API 规范
请求
有效负载 | ||
---|---|---|
inputs* | 字符串 | 要摘要的输入文本。 |
parameters | 对象 | |
clean_up_tokenization_spaces | 布尔值 | 是否清理文本输出中潜在的额外空格。 |
truncation | 枚举 | 可能的值:do_not_truncate、longest_first、only_first、only_second。 |
generate_parameters | 对象 | 文本生成算法的附加参数化。 |
某些选项可以通过将标头传递给 Inference API 来配置。以下是可用的标头
标头 | ||
---|---|---|
authorization | 字符串 | 身份验证标头,格式为 'Bearer: hf_****' ,其中 hf_**** 是具有 Inference API 权限的个人用户访问令牌。您可以从 您的设置页面 生成一个。 |
x-use-cache | 布尔值,默认为 true | Inference API 上有一个缓存层,用于加速我们已经看到的请求。大多数模型都可以使用这些结果,因为它们是确定性的(意味着输出无论如何都是相同的)。但是,如果您使用非确定性模型,您可以设置此参数以阻止使用缓存机制,从而产生真正的全新查询。在此处阅读有关缓存的更多信息 here。 |
x-wait-for-model | 布尔值,默认为 false | 如果模型尚未准备就绪,请等待它,而不是收到 503 错误。它限制了完成推理所需的请求数量。建议仅在收到 503 错误后才将此标志设置为 true,因为它会将应用程序中的挂起限制在已知位置。在此处阅读有关模型可用性的更多信息 here。 |
有关 Inference API 标头的更多信息,请查看 参数 指南。
响应
响应体 | ||
---|---|---|
summary_text | 字符串 | 摘要文本。 |