Wiki.LiftWing (mediawiki_client v0.5.3)

View Source

This module provides an adapter for the Lift Wing API for machine learning predictions.

See this page for a catalog of models, https://wikitech.wikimedia.org/wiki/Machine_Learning/LiftWing#Current_Inference_Services

Specific API methods have only been written for a handful of the models, please follow the pattern below to add additional models, and please contribute back here!

The server currently rate-limits requests to 50,000 per hour per IP address.

Summary

Types

  • :adapter - Override the HTTP adapter
  • :debug - Turn on verbose logging by setting to true
  • :endpoint - Override the base URL to query
  • :user_agent - Override the user-agent header string

Types

client_option()

@type client_option() ::
  {:adapter, module()}
  | {:debug, true}
  | {:endpoint, binary()}
  | {:user_agent, binary()}

client_options()

@type client_options() :: [client_option()]
  • :adapter - Override the HTTP adapter
  • :debug - Turn on verbose logging by setting to true
  • :endpoint - Override the base URL to query
  • :user_agent - Override the user-agent header string

Functions

articlequality(client, lang, revid, with_features \\ false)

@spec articlequality(Tesla.Client.t(), binary(), integer(), boolean()) ::
  {:ok, map()} | {:error, any()}

Language-agnostic article quality as documented on https://api.wikimedia.org/wiki/Lift_Wing_API/Reference/Get_language_agnostic_articlequality_prediction

Wiki.LiftWing.new()
|> Wiki.LiftWing.articlequality("en", 123456)
# {:ok,
#  %{
#    "model_name" => "articlequality",
#    "model_version" => "1",
#    "revision_id" => 123456,
#    "score" => 0.10391570042067477,
#    "wiki_db" => "enwiki"
#  }}

articletopic(client, wiki, revid, with_features \\ false)

@spec articletopic(Tesla.Client.t(), binary(), integer(), boolean()) ::
  {:ok, map()} | {:error, any()}

Article topic prediction

Wiki.LiftWing.new()
|> Wiki.LiftWing.articletopic("enwiki", 12345)
# {:ok,
#  %{
#    "enwiki" => %{
#      "models" => %{"articletopic" => %{"version" => "1.3.0"}},
#      "scores" => %{
#        "12345" => %{
#          "articletopic" => %{
#            "score" => %{
#              "prediction" => ["STEM.STEM*"],
#              "probability" => %{
#                "Culture.Internet culture" => 0.0027448342044452587,
#                "Culture.Media.Books" => 7.42678990345212e-4,
#                "Geography.Regions.Europe.Western Europe" => 0.001866188163881686,
#                "Culture.Visual arts.Comics and Anime" => 3.67749742655391e-4,
#                "STEM.STEM*" => 0.9049354239597514,
#                ....

new(opts \\ [])

@spec new(client_options()) :: Tesla.Client.t()

Create a new Lift Wing client.

Arguments

  • opts - Configuration options that can change client behavior

Return value

Returns an opaque client object, which should be passed to request/2.

request(client, opts)

@spec request(
  Tesla.Client.t(),
  keyword()
) :: {:ok, map()} | {:error, any()}

Make a Lift Wing request.

Arguments

  • client - Client object as returned by new/1.
  • Remaining parameters are passed to Tesla.request

revscoring_articlequality(client, wiki, revid, with_features \\ false)

@spec revscoring_articlequality(Tesla.Client.t(), binary(), integer(), boolean()) ::
  {:ok, map()} | {:error, any()}

Revscoring inference for the specific wikis listed on https://api.wikimedia.org/wiki/Lift_Wing_API/Reference/Get_revscoring_articlequality_prediction

Wiki.LiftWing.new()
|> Wiki.LiftWing.revscoring_articlequality("enwiki", 12345)
# {:ok,
#  %{
#    "enwiki" => %{
#      "models" => %{"articlequality" => %{"version" => "0.9.2"}},
#      "scores" => %{
#        "12345" => %{
#          "articlequality" => %{
#            "score" => %{
#              "prediction" => "Stub",
#              "probability" => %{
#                "B" => 0.04109666150848109,
#                "C" => 0.02060738177009099,
#                "FA" => 0.0029400688910391592,
#                "GA" => 0.004970401857774162,
#                "Start" => 0.17362493306327959,
#                "Stub" => 0.7567605529093352
#              }
#            }
#          }
#        }
#      }
#    }
#  }}