Get reference risk prediction

POST /service/lw/inference/v1/models/reference-risk:predict

This model uses edit history metadata to predict the likelihood of a reference to survive on a Wikipedia article. Check the model card for more info.

Examples

curl

Anonymous access

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

Logged in access

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

Python

# Python 3
# Get the reference risk score for the edit on English Wikipedia identified by the revision id 1242378206.

import json
import requests

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

JavaScript

/*
Get the reference risk score for the edit on English Wikipedia identified by the revision id 1242378206.
*/

const inferenceUrl = "https://api.wikimedia.org/service/lw/inference/v1/models/reference-risk: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": 1242378206, "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.
rev_id

required

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

optional

boolean

Returns a list of additional reference metadata for each reference when set to True.


Responses

200 Success: Returns a Reference risk score object.
Example
{
   "model_name":"reference-risk",
   "model_version":"2024-07",
   "wiki_db":"enwiki",
   "revision_id":1242378206,
   "reference_count":307,
   "survival_ratio":{
      "min":0.6917214573238013,
      "mean":0.830631414204165,
      "median":0.8305581162142753
   },
   "reference_risk_score":0.0
}