ORES package¶
Subpackages¶
Submodules¶
ores.api module¶
This module provides a ores.api.Session
class that can maintain a
client connection to an instance of ORES and efficiently generate scores.
Batching and parallelism are set by constructor arguments.
-
class
ores.api.
Session
(host, user_agent=None, session=None, retries=5, batch_size=50, parallel_requests=4)[source]¶ Constructs a session with an ORES API and provides facilities for scoring revisions in batch and parallel.
- Parameters
- hoststr
The host of ORES to connect to (preceed with “http” or “https”)
- user_agentstr
A User-Agent header to send with every request
- batch_sizeint
The number of scores to batch per request.
- parallel_requestint
The maximum number of requests to make in parallel
- retriesint
The maximum number of retries for basic HTTP errors before giving up
-
class
ores.api.
Session
(host, user_agent=None, session=None, retries=5, batch_size=50, parallel_requests=4)[source] Bases:
object
Constructs a session with an ORES API and provides facilities for scoring revisions in batch and parallel.
- Parameters
- hoststr
The host of ORES to connect to (preceed with “http” or “https”)
- user_agentstr
A User-Agent header to send with every request
- batch_sizeint
The number of scores to batch per request.
- parallel_requestint
The maximum number of requests to make in parallel
- retriesint
The maximum number of retries for basic HTTP errors before giving up
-
DEFAULT_USERAGENT
= 'ores.api default user-agent'¶
-
score
(context, models, revids)[source] Genetate scores for model applied to a sequence of revisions.
- Parameters
- contextstr
The name of the context – usually the database name of a wiki
- modelsiterable
The names of a models to apply
- revidsiterable
A sequence of revision IDs to score.
ores.errors module¶
-
exception
ores.errors.
MissingContext
[source]¶ Bases:
RuntimeError
-
exception
ores.errors.
MissingModels
[source]¶ Bases:
RuntimeError
-
exception
ores.errors.
ScoreProcessorOverloaded
[source]¶ Bases:
RuntimeError
-
exception
ores.errors.
TimeoutError
[source]¶ Bases:
RuntimeError
-
exception
ores.errors.
TooManyRequestsError
[source]¶ Bases:
RuntimeError
ores.score_request module¶
-
class
ores.score_request.
ScoreRequest
(context_name, rev_ids, model_names, precache=False, include_features=False, injection_caches=None, model_info=None, ip=None)[source]¶ Bases:
object
ores.score_response module¶
ores.scoring_context module¶
-
class
ores.scoring_context.
ClientScoringContext
(name, model_map, *args, **kwargs)[source]¶ Bases:
ores.scoring_context.ScoringContext
A simplistic scoring context that is not capable of performing the scoring itself. This ScoringContext is intended to be used in clients where an external service actually implements the scoring pattern (e.g.
ores.scoring_systems.CeleryQueue
). This ScoringContext saves on unnecessary memory usage, but still provides access to basic informational functionality.
-
class
ores.scoring_context.
ScoringContext
(name, model_map, extractor)[source]¶ Bases:
dict
Represents a context in which scoring can take place. Usually, a wiki is 1:1 with a “ScoringContext”.
- Parameters
- namestr
The name of the context in which scoring will happen. This is usually a wiki’s database name.
- model_mapdict
A mapping between names and
revscoring.Model
instances- extractor
revscoring.Extractor
An extractor to use for gathering feature values
-
extract_root_dependency_caches
(model_names, rev_ids, injection_caches=None)[source]¶ Extracts a mapping of root
revscoring.Datasource
capable of generating the features needed for a particular set of models without additional IO. This method implements all of the IO heavy operations. The roots dependency caches produced by calling this method can then be passed to process_model_scores() for scoring.- Parameters
- model_nameslist ( str )
The names of a
revscoring.Model
to extract the roots dependencies for
-
classmethod
from_config
(config, name, section_key='scoring_contexts')[source]¶ Expects:
- scoring_contexts:
- enwiki:
- scorer_models:
damaging: enwiki_damaging_2014 good-faith: enwiki_good-faith_2014
extractor: enwiki
- ptwiki:
- scorer_models:
damaging: ptwiki_damaging_2014 good-faith: ptwiki_good-faith_2014
extractor: ptwiki
- extractors:
enwiki_api: … ptwiki_api: …
- scorer_models:
enwiki_damaging_2014: … enwiki_good-faith_2014: …
-
classmethod
map_from_config
(config, context_names, section_key='scoring_contexts')[source]¶ Loads a whole set of ScoringContext’s from a configuration file while maintaining a cache of model names. This aids in better memory management and allows model aliases to be implemented at the configuration level.
- Returns
A map of context_names and ScoringContext’s where models are loaded once and reused cross contexts.
-
process_model_scores
(model_names, root_cache, include_features=False)[source]¶ Generates a score map for a set of models based on a root_cache. This method performs no substantial IO, but may incur substantial CPU usage.
- Parameters
- model_namesset ( str )
A set of models to score
- root_cachedict ( str –> mixed )
A cache of pre-computed root_dependencies for a specific revision. See extract_root_dependency_caches()
- include_featuresbool
If True, include a map of basic features used in scoring along with the model score. If False, just generate the scores.
-
class
ores.scoring_context.
ServerScoringContext
(name, *args, **kwargs)[source]¶ Bases:
ores.scoring_context.ScoringContext
A scoring context that is only capable of scoring. This ScoringContext is intended to be used in clients where a web service (client) implements all of the model_info actions (e.g.
ores.scoring_systems.CeleryQueue
).This ScoringContext saves on unnecessary memory usage, but still provides access to basic scoring functionality.