Skip to content

Discrepancy between client.sentence_similarity input snippet & reality #1680

@tomaarsen

Description

@tomaarsen

Hello!

Details

I've gotten an issue on one of my models (https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/discussions/127) showing a discrepancy between the recommended usage snippet with the Inference Providers

import os
from huggingface_hub import InferenceClient

client = InferenceClient(
    provider="hf-inference",
    api_key=os.environ["HF_TOKEN"],
)

result = client.sentence_similarity(
    {
    "source_sentence": "That is a happy person",
    "sentences": [
        "That is a happy dog",
        "That is a very happy person",
        "Today is a sunny day"
    ]
},
    model="sentence-transformers/all-MiniLM-L6-v2",
)

and the actual code from huggingface_hub:

    def sentence_similarity(
        self, sentence: str, other_sentences: List[str], *, model: Optional[str] = None
    ) -> List[float]:

I suspect this is caused by this input:

const inputsSentenceSimilarity = () =>
`{
"source_sentence": "That is a happy person",
"sentences": [
"That is a happy dog",
"That is a very happy person",
"Today is a sunny day"
]
}`;

which should likely instead be

const inputsSentenceSimilarity = () => 
 	`{ 
     "sentence": "That is a happy person", 
     "other_sentences": [ 
         "That is a happy dog", 
         "That is a very happy person", 
         "Today is a sunny day" 
     ] 
 }`; 

or

const inputsSentenceSimilarity = () =>
	`sentence="That is a happy person",
    other_sentences=[
        "That is a happy dog",
        "That is a very happy person",
        "Today is a sunny day"
    ]`;

Depending on if the inputsSentenceSimilarity must be json parsable.
I'm afraid I don't currently have the bandwidth to make a PR for this.

cc @Wauplin @hanouticelina

  • Tom Aarsen

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions