lenskit.batch.BatchPipelineRunner#

class lenskit.batch.BatchPipelineRunner(*, n_jobs=None, use_ray=None, profiler=None, batch_size=None)#

Apply a pipeline to a collection of test users.

Stability:
Caller (see Stability Levels).
Parameters:
Argss:
pipeline:

The pipeline to evaluate.

n_jobs:

The number of parallel threads to use, or None for default defined by LensKit configuration and environment variables (see Configuring Parallelism).

use_ray:

Use Ray instead of threads to parallelize batch inference, overriding any option set in an environment variable or lenskit.toml.

batch_size:

The batch size for multiprocess execution. If None, a batch size based on the number of inputs is used, with a maximum batch size of 1000.

n_jobs: int#
use_ray: bool#
batch_size: int | None = None#
profiler: lenskit.pipeline.PipelineProfiler | None#
invocations: list[InvocationSpec]#
add_invocation(inv)#
Parameters:

inv (InvocationSpec)

score(component='scorer', *, output='scores')#

Request the batch run to generate test item scores.

Parameters:
  • component (str) – The name of the rating predictor component to run.

  • output (str) – The name of the results in the output dictionary.

predict(component='rating-predictor', *, output='predictions')#

Request the batch run to generate test item rating predictions. It is identical to score() but with different defaults.

Parameters:
  • component (str) – The name of the rating predictor component to run.

  • output (str) – The name of the results in the output dictionary.

recommend(component='recommender', *, output='recommendations', **extra)#

Request the batch run to generate recomendations.

Parameters:
  • component (str) – The name of the recommender component to run.

  • output (str) – The name of the results in the output dictionary.

  • extra (Any) – Extra inputs to the recommender. A common option is n, the number of recommendations to return (a default may be baked into the pipeline).

run(pipeline, queries)#

Run the pipeline and collect its results.

Note

The runner does not guarantee that results are in the same order as the original inputs.

Parameters:
  • pipeline (lenskit.pipeline.Pipeline) – The pipeline to run.

  • queries (lenskit.batch._queries.BatchInput) – The collection of test queries use. See Batch Queries for details on the various input formats.

Returns:

The batch results, mapping output names to item list collections of outputs.

Return type:

lenskit.batch._results.BatchResults

run_iter(pipeline, queries)#

Run the pipeline and yield its results.

This generator should be closed when it is done or the run is aborted, to ensure resources are properly cleaned up. The best way to use this method is as follows:

with closing(runner.run_iter()) as results:
    for key, outs in results:
        # do something with the data
        pass

Note

The runner does not guarantee that results are in the same order as the original inputs — with parallelism, they may be yielded in the order they are ready.

Parameters:
  • pipeline (lenskit.pipeline.Pipeline) – The pipeline to run.

  • queries (lenskit.batch._queries.BatchInput) – The collection of test queries use. See Batch Queries for details on the various input formats.

Return type:

collections.abc.Generator[lenskit.batch._results.BatchResultRow]