推理端点(专用)文档

支持的 Transformers 和 Diffusers 任务

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

支持的 Transformers 和 Diffusers 任务

推理端点为以下库的机器学习任务提供开箱即用的支持

  • Transformers
  • Sentence-Transformers
  • Diffusers (用于文本到图像任务)

下表列出了 Hugging Face 托管的推理端点支持的任务。这些任务不需要任何形式的代码或“自定义容器”来部署端点。如果您想自定义以下任何任务,或想编写自己的自定义任务,请参阅“创建您自己的推理处理器”部分以获取更多信息。

以下大多数任务使用 `pipeline` 对象,有关可以发送到端点的其他参数的更多信息,请点击此处

任务 框架 开箱即用支持
文本到图像 Diffusers
文本分类 Transformers
零样本分类 Transformers
词符分类 Transformers
问答 Transformers
掩码填充 Transformers
摘要 Transformers
翻译 Transformers
文本到文本生成 Transformers
文本生成 Transformers
特征提取 Transformers
句子嵌入 Sentence Transformers
句子相似度 Sentence Transformers
排序 Sentence Transformers
图像分类 Transformers
自动语音识别 Transformers
音频分类 Transformers
物体检测 Transformers
图像分割 Transformers
表格问答 Transformers
对话式 Transformers
自定义 自定义
视觉问答 Transformers
零样本图像分类 Transformers

请求载荷示例

请参阅以下一些任务的请求示例

自定义处理器

{
  "inputs": "This is a sample input",
  "moreData": 1,
  "customTask": true
}

文本分类

有关其他参数,请参阅此参考文档

对单个文本进行分类

{
  "inputs": "This sound track was beautiful! It paints the scenery in your mind so well I would recomend it
  even to people who hate vid. game music!"
}

对文本对进行分类

{
  "inputs": {
    "text": "This sound track was beautiful!",
    "text_pair": "It paints the scenery in your mind so well I would recomend it even to people who hate vid. game music!"
  } 
}

零样本分类

有关其他参数,请参阅此参考文档

{
  "inputs": "Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!",
  "parameters": {
    "candidate_labels": ["refund", "legal", "faq"]
  }
}

词符分类

有关其他参数,请参阅此参考文档

{
  "inputs": "This sound track was beautiful! It paints the scenery in your mind so well I would recomend it
  even to people who hate vid. game music!"
}

问答

有关其他参数,请参阅此参考文档

{
  "inputs": {
    "question": "What is used for inference?",
    "context": "My Name is Philipp and I live in Nuremberg. This model is used with sagemaker for inference."
  }
}

掩码填充

有关其他参数,请参阅此参考文档

{
  "inputs": "This sound track was <mask>! It paints the scenery in your mind so well I would recomend it
  even to people who hate vid. game music!"
}

摘要

有关其他参数,请参阅此参考文档

{
  "inputs": "This sound track was beautiful! It paints the scenery in your mind so well I would recomend it
  even to people who hate vid. game music!"
}

翻译

有关其他参数,请参阅此参考文档

{
  "inputs": "This sound track was beautiful! It paints the scenery in your mind so well I would recomend it
  even to people who hate vid. game music!"
}

文本到文本生成

有关其他参数,请参阅此参考文档

{
  "inputs": "This sound track was beautiful! It paints the scenery in your mind so well I would recomend it
  even to people who hate vid. game music!"
}

文本生成

有关其他参数,请参阅此参考文档

{
  "inputs": "This sound track was beautiful! It paints the scenery in your mind so well I would recomend it
  even to people who hate vid. game music!"
}

特征提取

有关其他参数,请参阅此参考文档

{
  "inputs": "This sound track was beautiful! It paints the scenery in your mind so well I would recomend it
  even to people who hate vid. game music!"
}

句子嵌入

如果使用 TEI 容器,请参阅此参考文档以了解其他参数。

{
  "inputs": "This sound track was beautiful! It paints the scenery in your mind so well I would recomend it
  even to people who hate vid. game music!"
}

句子相似度

{
  "inputs": {
    "sentences": ["This sound track was beautiful!", "It paints the scenery in your mind so well"],
    "source_sentence": "What a wonderful day to listen to music"
  }
}

排序

{
  "inputs": ["This sound track was beautiful!", "It paints the scenery in your mind so well"]
}

图像分类

图像分类可以接收 `json` 载荷或直接从 `image` 接收二进制数据。

JSON

{
  "inputs": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAgI"
}

二进制

curl --request POST \
  --url https://{ENDPOINT}/ \
  --header 'Content-Type: image/jpg' \
  --header 'Authorization: Bearer {HF_TOKEN}' \
  --data-binary '@test.jpg'

自动语音识别

自动语音识别可以接收 `json` 载荷或直接从 `audio` 接收二进制数据。有关其他参数,请参阅此参考文档

JSON

{
  "inputs": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAgI"
}

二进制

curl --request POST \
  --url https://{ENDPOINT}/ \
  --header 'Content-Type: audio/x-flac' \
  --header 'Authorization: Bearer {HF_TOKEN}' \
  --data-binary '@sample.flac'

音频分类

音频分类可以接收 `json` 载荷或直接从 `audio` 接收二进制数据。有关其他参数,请参阅此参考文档

JSON

{
  "inputs": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAgI"
}

二进制

curl --request POST \
  --url https://{ENDPOINT}/ \
  --header 'Content-Type: audio/x-flac' \
  --header 'Authorization: Bearer {HF_TOKEN}' \
  --data-binary '@sample.flac'

目标检测

目标检测可以接收 `json` 载荷或直接从 `image` 接收二进制数据。有关其他参数,请参阅此参考文档

JSON

{
  "inputs": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAgI"
}

二进制

curl --request POST \
  --url https://{ENDPOINT}/ \
  --header 'Content-Type: image/jpg' \
  --header 'Authorization: Bearer {HF_TOKEN}' \
  --data-binary '@test.jpg'

图像分割

图像分割可以接收 `json` 载荷或直接从 `image` 接收二进制数据。有关其他参数,请参阅此参考文档

JSON

{
  "inputs": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAgI"
}

二进制

curl --request POST \
  --url https://{ENDPOINT}/ \
  --header 'Content-Type: image/jpg' \
  --header 'Authorization: Bearer {HF_TOKEN}' \
  --data-binary '@test.jpg'

表格问答

有关其他参数,请参阅此参考文档

{
  "inputs": {
    "query": "How many stars does the transformers repository have?",
    "table": {
      "Repository": ["Transformers", "Datasets", "Tokenizers"],
      "Stars": ["36542", "4512", "3934"],
      "Contributors": ["651", "77", "34"],
      "Programming language": ["Python", "Python", "Rust, Python and NodeJS"]
    }
  }
}

对话

有关其他参数,请参阅此参考文档

{"inputs": [
  {
      "role": "user",
      "content": "Which movie is the best ?"
  },
  {
      "role": "assistant",
      "content": "It's Die Hard for sure."
  },
  {
      "role": "user",
      "content": "Can you explain why?"
  }
]}

文本到图像

{        
  "inputs": "realistic render portrait realistic render portrait of group of flying blue whales towards the moon, intricate, toy, sci - fi, extremely detailed, digital painting, sculpted in zbrush, artstation, concept art, smooth, sharp focus, illustration, chiaroscuro lighting, golden ratio, incredible art by artgerm and greg rutkowski and alphonse mucha and simon stalenhag",
}

对于文本到图像模型,请注意,目前您的模型仓库需要是一个包含完整权重的 diffusers 模型(即,不仅仅是 LoRA)。

其他参数

您可以添加 transformers 的 `pipelines` API 支持的其他参数。

例如,如果您有一个 `text-generation` 管线,您可以为 `repetition_penalty` 或 `max_length` 提供 `generation_kwargs`。

{
  "inputs": "Hugging Face, the winner of VentureBeat’s Innovation in Natural Language Process/Understanding Award for 2021, is looking to level the playing field. The team, launched by Clément Delangue and Julien Chaumond in 2016, was recognized for its work in democratizing NLP, the global market value for which is expected to hit $35.1 billion by 2026. This week, Google’s former head of Ethical AI Margaret Mitchell joined the team.",
  "parameters": {
    "repetition_penalty": 4.0,
    "max_length": 128
  }
}
< > 在 GitHub 上更新