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
}
language The language code as returned by the model.

Supported languages:

wikicode The language code in ISO 639-1 format as used in wiki projects.

ace acm acq aeb af ajp sq am ar ary arz as ast awa ay azb az ba bm ban be bem bn bh bjn bo bs bug bg ca ceb cs cjk ckb crh cy da de din dyu dz el en eo et eu ee fo fj fi fon fr fur ff om gd ga gl gn gu ht ha he hi hne hr hu hy ibo ilo id is it jv ja kab kac kam kn ks ka kk kbp kea mn kh ki rw ky kmb ku kg ko lo lij li ln lt lmo ltg lb lua lg luo lu lvs mag mai ml mr min mk mt mni mos mi my nl nn no ne nso nus ny oc or pag pa pap ps fa mg pl pt qu ro rn ru sg sa sat shn si sk sl sm sn sd so st es sc sr ss su sv sw szl ta tt te tg tl th ti tp tn ts tk tum tr tw tzm ug uk umb ur uz vec vi war wo xh yi yo zh ms zu

languagename The name of the language in English.
score Score represents a probability that represents the confidence of the model for the current prediction.