Get readability prediction

POST /service/lw/inference/v1/models/readability:predict

The model generates scores to assess the readability of Wikipedia articles. The readability score is a rough proxy to capture how difficult it is for a reader to understand the text of the article. Check the model card for more info.

Examples

curl

Anonymous access

# Get the readability score for the edit on English Wikipedia identified by the revision id 123456.
$ curl https://api.wikimedia.org/service/lw/inference/v1/models/readability:predict -X POST -d '{"rev_id": 123456, "lang": "en"}' -H "Content-type: application/json"

Logged in access

# Get the readability score for the edit on English Wikipedia identified by the revision id 123456.
$ curl https://api.wikimedia.org/service/lw/inference/v1/models/readability:predict -X POST -d '{"rev_id": 123456, "lang": "en"}' -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-type: application/json"

Python

# Python 3
# Get the readability score for the edit on English Wikipedia identified by the revision id 123456.

import json
import requests

use_auth = False
inference_url = 'https://api.wikimedia.org/service/lw/inference/v1/models/readability: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 = {"rev_id": 123456, "lang": "en"}
response = requests.post(inference_url, headers=headers, data=json.dumps(data))
print(response.json())

JavaScript

/*
Get the readability score for the edit on English Wikipedia identified by the revision id 123456.
*/

const inferenceUrl = "https://api.wikimedia.org/service/lw/inference/v1/models/readability: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 = {"rev_id": 123456, "lang": "en"};

fetch(inferenceUrl, {
    method: "POST",
    headers: headers,
    body: JSON.stringify(data)
})
.then(response => response.json())
.then(inferenceData => console.log(inferenceData));

POST Parameters

lang

required

A string representing the language code related to the target wiki. Example: "en" for English Wikipedia.

Supported languages: 'af', 'sq', 'am', 'ar', 'hy', 'as', 'az', 'eu', 'be', 'bn', 'bs', 'br', 'bg', 'my', 'ca', 'zh-yue', 'zh', 'zh-classical', 'hr', 'cs', 'da', 'nl', 'en', 'eo', 'et', 'tl', 'fi', 'fr', 'gl', 'ka', 'de', 'el', 'gu', 'ha', 'he', 'hi', 'hu', 'is', 'id', 'ga', 'it', 'ja', 'jv', 'kn', 'kk', 'km', 'ko', 'ku', 'ky', 'lo', 'la', 'lv', 'lt', 'mk', 'mg', 'ms', 'ml', 'mr', 'mn', 'ne', 'no', 'or', 'om', 'ps', 'fa', 'pl', 'pt', 'pa', 'ro', 'ru', 'sa', 'gd', 'sr', 'sd', 'si', 'sk', 'sl', 'so', 'es', 'su', 'sw', 'sv', 'ta', 'te', 'th', 'tr', 'uk', 'ur', 'ug', 'uz', 'vi', 'cy', 'fy', 'xh', 'yi', 'simple'

rev_id

required

The revision id for the wiki identified by the lang parameter.

Responses

200 Success: Returns a readability score object.
Example
{
  "model_name": "readability",
  "model_version": "4",
  "wiki_db": "enwiki",
  "revision_id": 123456,
  "output": {
    "score": -0.29161882400512695,
    "fk_score_proxy": 8.63213539862886
  }
}