Can one get an embeddings from an inference API that computes Sentence Similarity?
Hi there,I’m new to using Huggingface’s inference API and wanted to check if a model whose task is to return Sentence Similarity can return sentence embeddings instead.For example, inthissentence-transformers model, the model task is to return sentence similarity. Instead, I would like to just get the embeddings of a list of sentences.Is there an API parameter I can tweak to get this? Help would be very much appreciated!
2022-01-19T08:47:38Z
Hi there!Yes, you can compute sentence embeddings. Here is an exampleimport requests

API_URL = "https://api-inference.huggingface.co/pipeline/feature-extraction/sentence-transformers/all-mpnet-base-v2"
headers = {"Authorization": "Bearer API_TOKEN"}

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

output = query({
    "inputs": ["this is a sentence", "this is another sentence"]
})
# Output is a list of 2 embeddings, each of 768 values.
2023-03-05T15:54:50Z
Can you use this endpointto do image embedding?IE: using the modelsentence-transformers/clip-ViT-B-32-multilingual-v1https://api-inference.huggingface.co/pipeline/feature-extraction/sentence-transformers/**sentence-transformers/clip-ViT-B-32-multilingual-v1**If so, how do you pass the images? via base64encode?I’m doing it passing base64encode images in the “inputs” parameter and it doesn’t seem to get the image meaning content right…body:{“inputs”: ,“options”: {“wait_for_model”: true}}Thanks in advance!
2023-08-03T21:49:42Z
@osansevieroDoes this still work?It was working until recently, now I get the error{'error': ['SentenceSimilarityInputsCheck expected dict not list:rootinparameters']}.Thanks in advance!
2023-08-04T08:28:01Z
Hi there! Do you have an example of the request you’re doing? I just tried one as above and it is working well.
2023-08-04T17:20:05Z
Nevermind! I missed thepipeline/feature-extraction/part of the URL. Thanks a ton!
2023-10-29T01:03:09Z
Since it looks like the main difference here is the addition of pipeline/feature-extraction in the url, how would you replicate this approach on a deployed inference endpoint?– i.e.“https:some-custom-key.region.aws.endpoints.huggingface.cloud”
2023-11-02T15:48:46Z
@Jonp1When set up the deployed inference endpoint you can choose theTask. To get the text embeddings useSentence Embeddingsimage593×584 70.5 KB
2024-09-19T13:40:53Z
Just Thank you dude, i was searching for this since last hour.THANK YOU VERY MUCH