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:
n_jobs (int | None)
use_ray (bool | None)
profiler (lenskit.pipeline.PipelineProfiler | None)
batch_size (int | None)
- Argss:
- pipeline:
The pipeline to evaluate.
- n_jobs:
The number of parallel threads to use, or
Nonefor 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.
- 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.
- 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.
- recommend(component='recommender', *, output='recommendations', **extra)#
Request the batch run to generate recomendations.
- 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:
- 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]