Skip to content

Commit

Permalink
docs: update inference API examples for reranker model (#1541)
Browse files Browse the repository at this point in the history
* docs: update inference API examples for reranker model

- Update code examples to show correct input format for reranker
- Add examples for text/text_pair format required by mxbai-rerank-base-v1
- Include multiple input pairs to demonstrate batch processing
- Update curl, Python and JavaScript examples consistently

* undo hf lib reference
  • Loading branch information
Muhtasham authored Dec 26, 2024
1 parent 7f5034b commit 9fe4b36
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions docs/api-inference/tasks/text-classification.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,54 +37,67 @@ Explore all available models and find the one that suits you best [here](https:/
<inferencesnippet>

<curl>

```bash
curl https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english \
-X POST \
-d '{"inputs": "I like you. I love you"}' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer hf_***'
curl https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1 \
-X POST \
-d '{"inputs": [{"text": "What is Paris?", "text_pair": "Paris is the capital of France"}]}' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer hf_***'
```

</curl>

<python>
```py

```python
import requests

API_URL = "https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english"
API_URL = "https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1"
headers = {"Authorization": "Bearer hf_***"}

def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
output = query({
"inputs": "I like you. I love you",
"inputs": [
{"text": "What is Paris?", "text_pair": "Paris is the capital of France"},
{"text": "What is Paris?", "text_pair": "London is the capital of England"}
]
})
```

To use the Python client, see `huggingface_hub`'s [package reference](https://huggingface.co/docs/huggingface_hub/package_reference/inference_client#huggingface_hub.InferenceClient.text_classification).

</python>

<js>
```js

```javascript
async function query(data) {
const response = await fetch(
"https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english",
{
headers: {
Authorization: "Bearer hf_***",
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify(data),
}
);
const result = await response.json();
return result;
const response = await fetch(
"https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1",
{
headers: {
Authorization: "Bearer hf_***",
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify(data),
}
);
const result = await response.json();
return result;
}

query({"inputs": "I like you. I love you"}).then((response) => {
console.log(JSON.stringify(response));
query({
"inputs": [
{"text": "What is Paris?", "text_pair": "Paris is the capital of France"},
{"text": "What is Paris?", "text_pair": "London is the capital of England"}
]
}).then((response) => {
console.log(JSON.stringify(response));
});
```

Expand All @@ -94,7 +107,6 @@ To use the JavaScript client, see `huggingface.js`'s [package reference](https:/
</inferencesnippet>



### API specification

#### Request
Expand Down

0 comments on commit 9fe4b36

Please sign in to comment.