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,
"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: |
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":"2",
"wiki_db":"enwiki",
"revision_id":123456,
"output":{
"prediction":false,
"probabilities":{
"true":0.4793056845664978,
"false":0.5206943154335022
},
"fk_score":8.277095534538086
}
}
|
---|