Get language identification prediction
POST | /service/lw/inference/v1/models/langid:predict
|
---|
The model generates scores to assess the language of the text provided as input. Check the model card for more info.
Examples
curl
Anonymous access
# Anonymous request
$ curl https://api.wikimedia.org/service/lw/inference/v1/models/langid:predict -X POST -d '{"text": "Some sample text in any language that we want to identify"}' -H "Content-type: application/json"
Logged in access
# Authenticated request using Bearer token
$ curl https://api.wikimedia.org/service/lw/inference/v1/models/langid:predict -X POST -d '{"text": "Some sample text in any language that we want to identify"}' -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-type: application/json"
Python
# Python 3
import json
import requests
use_auth = False
inference_url = 'https://api.wikimedia.org/service/lw/inference/v1/models/langid:predict'
if use_auth:
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)',
'Content-type': 'application/json'
}
else:
headers = {}
data = {"text": "Some sample text in any language that we want to identify"}
response = requests.post(inference_url, headers=headers, data=json.dumps(data))
print(response.json())
JavaScript
const inferenceUrl = "https://api.wikimedia.org/service/lw/inference/v1/models/langid:predict";
const accessToken = "YOUR_ACCESS_TOKEN";
const appName = "YOUR_APP_NAME";
const email = "YOUR_EMAIL_OR_CONTACT_PAGE";
let headers = new Headers({
"Content-Type": "application/json",
"Authorization": "Bearer " + accessToken,
"Api-User-Agent": appName + " ( " + email + " )"
});
let data = {"text": "Some sample text in any language that we want to identify"};
fetch(inferenceUrl, {
method: "POST",
headers: headers,
body: JSON.stringify(data)
})
.then(response => response.json())
.then(inferenceData => console.log(inferenceData));
POST Parameters
text
required |
A string that contains the text which we want to identify the language it is written in. |
Responses
200 | Success: Returns a language identification object.
Example
{ "language":"eng_Latn",
"wikicode":"en",
"languagename":"English",
"score":0.4073379337787628
}
|
---|