How to force the task of inference API?

Hello! I trained a model for zero-shot classification and in the pipelines it works great, but the inference api recognizes the task as text classification, and thus I can’t use it as zero-shot out of the box. Is there a way to hint the inference API to what task I want to use my model?

Thanks!

Replying to self, and figured out after looking into the code of the InferenceAPI objects. You can pass the task type as a path parameter like <<inference api base url>>/pipeline/task-type/model. Leaving it here in case anyone has the same question.

4 Likes

Here is a more detailed example:

import requests
import numpy as np

API_URL = "https://api-inference.huggingface.co/pipeline/feature-extraction/deepset/roberta-base-squad2"
headers = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}

def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.json()

data = query({"inputs": "This is a more detailed example."})
data = np.array(data)[0]
embedding = np.mean(data, axis=0)
len(embedding), embedding
1 Like