Skip to content

Commit 9fe4b36

Browse files
authored
docs: update inference API examples for reranker model (#1541)
* 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
1 parent 7f5034b commit 9fe4b36

File tree

1 file changed

+40
-28
lines changed

1 file changed

+40
-28
lines changed

docs/api-inference/tasks/text-classification.md

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,54 +37,67 @@ Explore all available models and find the one that suits you best [here](https:/
3737
<inferencesnippet>
3838

3939
<curl>
40+
4041
```bash
41-
curl https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english \
42-
-X POST \
43-
-d '{"inputs": "I like you. I love you"}' \
44-
-H 'Content-Type: application/json' \
45-
-H 'Authorization: Bearer hf_***'
42+
curl https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1 \
43+
-X POST \
44+
-d '{"inputs": [{"text": "What is Paris?", "text_pair": "Paris is the capital of France"}]}' \
45+
-H 'Content-Type: application/json' \
46+
-H 'Authorization: Bearer hf_***'
4647
```
48+
4749
</curl>
4850

4951
<python>
50-
```py
52+
53+
```python
5154
import requests
5255

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

5659
def query(payload):
57-
response = requests.post(API_URL, headers=headers, json=payload)
58-
return response.json()
59-
60+
response = requests.post(API_URL, headers=headers, json=payload)
61+
return response.json()
62+
6063
output = query({
61-
"inputs": "I like you. I love you",
64+
"inputs": [
65+
{"text": "What is Paris?", "text_pair": "Paris is the capital of France"},
66+
{"text": "What is Paris?", "text_pair": "London is the capital of England"}
67+
]
6268
})
6369
```
6470

6571
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).
72+
6673
</python>
6774

6875
<js>
69-
```js
76+
77+
```javascript
7078
async function query(data) {
71-
const response = await fetch(
72-
"https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english",
73-
{
74-
headers: {
75-
Authorization: "Bearer hf_***",
76-
"Content-Type": "application/json",
77-
},
78-
method: "POST",
79-
body: JSON.stringify(data),
80-
}
81-
);
82-
const result = await response.json();
83-
return result;
79+
const response = await fetch(
80+
"https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1",
81+
{
82+
headers: {
83+
Authorization: "Bearer hf_***",
84+
"Content-Type": "application/json",
85+
},
86+
method: "POST",
87+
body: JSON.stringify(data),
88+
}
89+
);
90+
const result = await response.json();
91+
return result;
8492
}
8593

86-
query({"inputs": "I like you. I love you"}).then((response) => {
87-
console.log(JSON.stringify(response));
94+
query({
95+
"inputs": [
96+
{"text": "What is Paris?", "text_pair": "Paris is the capital of France"},
97+
{"text": "What is Paris?", "text_pair": "London is the capital of England"}
98+
]
99+
}).then((response) => {
100+
console.log(JSON.stringify(response));
88101
});
89102
```
90103

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

96109

97-
98110
### API specification
99111

100112
#### Request

0 commit comments

Comments
 (0)