Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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