ploomber.OnlineModel¶
- class ploomber.OnlineModel(module)¶
A subclass of
ploomber.OnlineDAG
to provider a simpler interface for online DAGs whose terminal task callsmodel.predict
.OnlineModel
is initialized with a module following a standard structure. Looks for apipeline-features.yaml
in the module’s root directory (e.g.src/my_module/pipeline-features.yaml
), amodel.pickle
in the module’s root directory. The terminal task is executed with amodel
parameter which contains the load model and callsmodel.predict
. The last task inpipeline-features.yaml
should be namedfeatures
.See here for a complete example: https://github.com/ploomber/projects/blob/master/templates/ml-online/src/ml_online/infer.py
- Parameters
module – A module following a standard structure
Examples
>>> import my_module >>> model = OnlineModel(my_module) >>> model.predict(x=some_input)
Methods
Must return the location of a partial dag (str or pathlib.Path)
init_dag_from_partial
(partial)Initialize partial returned by get_partial()
predict
(**kwargs)Returns the output of
model.predict(upstream['features'])
Must return a dictionary with parameters passed to
terminal_task
terminal_task
(upstream, model)Las function to execute.
- get_partial()¶
Must return the location of a partial dag (str or pathlib.Path)
- classmethod init_dag_from_partial(partial)¶
Initialize partial returned by get_partial()
- predict(**kwargs)¶
Returns the output of
model.predict(upstream['features'])
- terminal_params()¶
Must return a dictionary with parameters passed to
terminal_task
- static terminal_task(upstream, model)¶
Las function to execute. The
upstream
parameter contains the output of all tasks that have no downstream dependencies