Get article descriptions

POST /service/lw/inference/v1/models/article-descriptions:predict

The model generates a short description for the Wikipedia article 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/article-descriptions:predict -X POST -d '{"lang": "en", "title": "Clandonald", "num_beams": 2, "debug": 1}' -H "Content-type: application/json"

Logged in access

# Authenticated request using Bearer token
$ curl https://api.wikimedia.org/service/lw/inference/v1/models/article-descriptions:predict -X POST -d '{"lang": "en", "title": "Clandonald", "num_beams": 2, "debug": 1}' -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/article-descriptions: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 = {"lang": "en", "title": "Clandonald", "num_beams": 2, "debug": 1}
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/article-descriptions: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 = {"lang": "en", "title": "Clandonald", "num_beams": 2, "debug": 1};

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

POST Parameters

lang

required

The language code for the Wikipedia article.
title

required

The wikipedia article title.
num_beams

required

The number of beams.
debug

optional

Set debug mode on or off (i.e 1 or 0)

Responses

200 Success: Returns an article descriptions object.
Example
{
  "lang": "en",
  "title": "Clandonald",
  "blp": false,
  "num_beams": 2,
  "groundtruth": "Hamlet in Alberta, Canada",
  "latency": {
    "wikidata-info (s)": 0.051393747329711914,
    "mwapi - first paragraphs (s)": 0.22525501251220703,
    "total network (s)": 0.2677001953125,
    "model (s)": 2.823765754699707,
    "total (s)": 3.091487407684326
  },
  "features": {
    "descriptions": {
      "fr": "hameau d'Alberta",
      "en": "hamlet in central Alberta, Canada"
    },
    "first-paragraphs": {
      "en": "Clandonald is a hamlet in central Alberta, Canada within the County of Vermilion River. It is located approximately 28 kilometres (17 mi) north of Highway 16 and 58 kilometres (36 mi) northwest of Lloydminster.",
      "fr": "Clandonald est un hameau (hamlet) du Comté de Vermilion River, situé dans la province canadienne d'Alberta."
    }
  },
  "prediction": [
    "Hamlet in Alberta, Canada",
    "human settlement in Alberta, Canada"
  ]
}