Language
Our language detector uses SpaCy and FastText to predict what language the input text is written in.
Like many of our models, the longer the input the better the predictions are, especially if the text is written in a language that shares a recent common ancestor with another like Latin languages do with each other. For example, Spanish, Portuguese and Catalan.
Prediction labels
Limits
The maximum length accepted is 512 characters.
We return the 2-characters ISO_639-1 representing the language predicted, together with the language name written in English.
Example:
Field | Value | Meaning |
---|---|---|
iso_code | pt | The text was predicted to be in Portuguese |
language | Portuguese | Literal representation of pt , written in English |
Invokation
- cURL
- Python
- PHP
curl -L -G 'http://api.textkit.ai/detect/language' \
--data-urlencode 'text=this is just a random text' \
--header 'X-API-Key: your_api_key_here'
import requests
url = "https://api.textkit.ai/detect/language?text=this is a test"
payload={}
headers = {
'X-API-Key': 'your_api_key_here'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
<?php
$curl = curl_init();
$url = "https://api.textkit.ai/detect/language?text=" . urlencode("this is a test");
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'X-API-Key: your_api_key_here'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Response
{
"prediction": {
"iso_code": "en",
"language": "English"
},
"confidence": "0.982",
"time_ms": 16
}
Field | Meaning |
---|---|
prediction | The predicted label. See above for reference |
confidence | Value between 0 and 1 that indicates how confident the model is |
time_ms | Time in milliseconds the model took to predict the label. It does not account for the network round trip time between request and response |