支持的 Transformers 和 Diffusers 任务
Inference Endpoints 为以下库的机器学习任务提供开箱即用的支持
- Transformers
- Sentence-Transformers
- Diffusers(用于文本到图像任务)
下面是 Inference Endpoint 支持的 Hugging Face 管理任务的表格。这些任务不需要任何形式的代码或 “自定义容器” 来部署 Endpoint。如果您想自定义以下任何任务,或者想编写自己的自定义任务,请查看 “创建您自己的推理处理程序” 部分以获取更多信息。
以下大多数任务都使用 pipeline
对象,有关可以发送到 endpoint 的其他参数的更多信息,请参见 此处。
任务 | 框架 | 开箱即用支持 |
---|---|---|
文本到图像 | Diffusers | ✅ |
文本分类 | Transformers | ✅ |
零样本分类 | Transformers | ✅ |
Token 分类 | 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"]
}
}
Token 分类
有关其他参数,请参阅此参考。
{
"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!"
}
句子嵌入
{
"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"]
}
图像分类
图像分类可以直接从 image
接收 json
负载或二进制数据。
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'
自动语音识别
自动语音识别可以直接从 audio
接收 json
负载或二进制数据。有关其他参数,请参阅此参考。
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'
音频分类
音频分类可以直接从 audio
接收 json
负载或二进制数据。有关其他参数,请参阅此参考。
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'
物体检测
物体检测可以直接从 image
接收 json
负载或二进制数据。有关其他参数,请参阅此参考。
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'
图像分割
图像分割可以直接从 image
接收 json
负载或二进制数据。有关其他参数,请参阅此参考。
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)。
附加参数
您可以添加额外的参数,这些参数由 pipelines
API 从 transformers 提供支持。
例如,如果您有一个 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
}
}