Classifier API Documentation
Description:
The Classifier API allows authenticated users to submit text data for classification. It takes input text and labels, classifies the text, and provides classification results, including label probabilities. This comprehensive documentation will guide you through using the Classifier API and It includes practical examples showcasing different scenarios, including English input with English output and English input with Japanese output.
How to Use the Classifier API
HTTP Methods:
POST
: Submit text for classification (requires authentication).GET
: Retrieve classification results using a Unique Identifier (UID).
Classify Text
Endpoint: https://kafkai.io/api/v1.0/classifier-api/
HTTP Method: POST
How the API Works
To classify text, follow these steps:
-
Authentication: Include an authentication token in your request header.
-
Compose Your Request: Create your request with the following JSON data:
{ "source_text": "Insert your text to classify here.", "labels": "label1,label2,label3", "output_lang": "en" }
source_text
: Place the text you want to classify in this field.labels
: Specify the labels for classification, separated by a delimiter (,
by default). Labels should not contain spaces.output_lang
: If you prefer the classification results in a specific language (e.g., "en" for English or "ja" for Japanese), specify it here. If not specified, the results will use the source language.
-
Submit Your Request: Send the POST request to the
https://kafkai.io/api/v1.0/classifier-api/
endpoint. -
Receive Classification Results: You will receive a JSON response containing classification results, including label probabilities.
Practical Examples (POST Request)
Example 1: English Input and English Output (POST Request)
Input Text (English):
"Excellent product, highly recommended. It exceeded my expectations."
Labels: "positive," "recommendation," "product"
Output Language: English ("en")
Python Example (English Input and English Output):
import requests
import json
url = "https://kafkai.io/api/v1.0/classifier-api/"
headers = {
"Authorization": "Token <your-api-key>",
"Content-Type": "application/json",
}
data = {
"source_text": "Excellent product, highly recommended. It exceeded my expectations.",
"labels": "positive,recommendation,product",
"output_lang": "en"
}
response = requests.post(url, headers=headers, data=json.dumps(data))
classification_result = response.json()
print(classification_result)
cURL Request (English Input and English Output):
curl -X POST -H "Authorization: Token <your-api-key>" -H "Content-Type: application/json" -d '{
"source_text": "Excellent product, highly recommended. It exceeded my expectations.",
"labels": "positive,recommendation,product",
"output_lang": "en"
}' https://kafkai.io/api/v1.0/classifier-api/
Notes:
- This example classifies English text and requests results in English (
"output_lang": "en"
).
Example 2: English Input and Japanese Output (POST Request)
Input Text (English):
Mount Fuji is Japan's highest peak, an active volcano, a tourist hotspot, and an iconic beauty spot.
Labels: "tourist_destination," "nature," "Japan"
Output Language: Japanese ("ja")
Python Example (English Input and Japanese Output):
import requests
import json
url = "https://kafkai.io/api/v1.0/classifier-api/"
headers = {
"Authorization": "Token <your-api-key>",
"Content-Type": "application/json",
}
data = {
"source_text": "Mount Fuji is Japan's highest peak, an active volcano, a tourist hotspot, and an iconic beauty spot"
"labels": "tourist_destination,nature,Japan",
"output_lang": "ja"
}
response = requests.post(url, headers=headers, data=json.dumps(data))
classification_result = response.json()
print(classification_result)
cURL Request (English Input and Japanese Output):
curl -X POST -H "Authorization: Token <your-api-key>" -H "Content-Type: application/json" -d '{
"source_text": "Mount Fuji is Japan's highest peak, an active volcano, a tourist hotspot, and an iconic beauty spot."
"labels": "tourist_destination,nature,Japan",
"output_lang": "ja"
}' https://kafkai.io/api/v1.0/classifier-api/
Notes:
- This example classifies English text and requests results in Japanese (
"output_lang": "ja"
).
Retrieve Classification Results
Endpoint: https://kafkai.io/api/v1.0/classifier-api/{uid}/
UID Example: d9a4cca5-fdb8-482e-a972-9da4de19738f
HTTP Method: GET
Retrieving Classification Results
To retrieve classification results, use the following endpoint:
- Replace
{uid}
in the URL with the Unique Identifier (UID) of the classification data you wish to retrieve.
Practical Example (GET Request)
To retrieve the classification results for the previously classified text, use the following python
and cURL
examples:
Python Example (GET Request):
import requests
url = "https://kafkai.io/api/v1.0/classifier-api/d9a4cca5-fdb8-482e-a972-9da4de19738f/"
headers = {
"Authorization": "Token <your-api-key>"
}
response = requests.get(url, headers=headers)
classification_result = response.json()
print(classification_result)
cURL Request (GET Request):
curl -H "Authorization: Token <your-api-key>" https://kafkai.io/api/v1.0/classifier-api/d9a4cca5-fdb8-482e-a972-9da4de19738f/
Notes:
- These examples demonstrate how to retrieve classification results using both Python and cURL.
Conclusion
The Classifier API allows you to classify text efficiently and supports different output languages. Ensure you are authenticated before making requests and refer to the provided examples for correct API usage.