Get articletopic outlink prediction
POST | /service/lw/inference/v1/models/outlink-topic-model:predict
|
---|
Get article topics and related scores from the Language agnostic link-based article topic model for a given wiki page. Check the model card for more information.
Examples
curl
Anonymous access
# Get topics and related scores from the Article Topic Outlink model for the page of Douglas Adams on English Wikipedia.
$ curl https://api.wikimedia.org/service/lw/inference/v1/models/outlink-topic-model:predict -X POST -d '{"page_title": "Douglas_Adams", "lang": "en"}' -H "Content-type: application/json"
Logged in access
# Get topics and related scores from the Article Topic Outlink model for the page of Douglas Adams on English Wikipedia.
$ curl https://api.wikimedia.org/service/lw/inference/v1/models/outlink-topic-model:predict -X POST -d '{"page_title": "Douglas_Adams", "lang": "en"}' -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-type: application/json"
Python
# Python 3
# Get topics and related scores from the Article Topic Outlink model for the page of Douglas Adams on English Wikipedia.
import json
import requests
use_auth = False
inference_url = 'https://api.wikimedia.org/service/lw/inference/v1/models/outlink-topic-model: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 = {"page_title": "Douglas_Adams", "lang": "en"}
response = requests.post(inference_url, headers=headers, data=json.dumps(data))
print(response.json())
JavaScript
/*
Get topics and related scores from the Article Topic Outlink model for the page of Douglas Adams on English Wikipedia.
*/
const inferenceUrl = "https://api.wikimedia.org/service/lw/inference/v1/models/outlink-topic-model: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 = {"page_title": "Douglas_Adams", "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. |
page_title
required |
A string representing the title of the Wiki article to score. Example: "Douglas_Adams" for the Wiki page of the author Douglas Adams. |
threshold
|
A float representing a custom threshold value to use when evaluating the scores. Default: empty. |
features_str
|
A string representing custom features to pass to the model. Default: empty. |
debug
|
A boolean indicating whether or not to enable debug output to return all predicted topics and scores, equivalent to setting the threshold to 0. Default: false. |
Responses
200 | Success: Returns an Article Topic Outlink scores object.
Example
{
"prediction": {
"article": "https://en.wikipedia.org/wiki/Douglas_Adams",
"results": [
{
"topic": "Culture.Media.Media*",
"score": 0.6723417043685913
},
{
"topic": "Culture.Biography.Biography*",
"score": 0.5156299471855164
}
]
}
}
|
---|