--- title: lightning_helper keywords: fastai sidebar: home_sidebar summary: "Helper functions for training models using the pytorch-lightning framework" description: "Helper functions for training models using the pytorch-lightning framework" nb_path: "lightning_helper.ipynb" ---
{% raw %}
{% endraw %} {% raw %}

class SlateDataModule[source]

SlateDataModule(*args:Any, **kwargs:Any) :: LightningDataModule

A LightningDataModule wrapper around the dataloaders created in dataset_torch.

{% endraw %} {% raw %}
{% endraw %} {% raw %}

class CallbackPrintRecommendedCategory[source]

CallbackPrintRecommendedCategory(dm, num_recs=2, max_interactions=10, report_interval=100) :: Callback

A pytorch lightning callback that prints the clicks the user did, and the top recommendations at a given interaction.

{% endraw %} {% raw %}
{% endraw %} {% raw %}

class Hitrate[source]

Hitrate(dm, report_interval=100, num_rec=10) :: Callback

Module computing hitrate over the test dataset. NB: This assumes that recommendations does not change over time. I.e. will not work on temporal models.

{% endraw %} {% raw %}
{% endraw %} {% raw %}
dm = SlateDataModule()
dm.prepare_data()
dm.setup()

checksum = next(iter(dm.train_dataloader()))['slate'].sum().item()
assert checksum == 98897096275, "Data error: Checksum of first batch is not expected value. Seed error?"
/opt/conda/envs/pytorch/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)
2021-07-06 11:24:50,376 Downloading data.npz
2021-07-06 11:24:50,377 Downloading ind2val.json
2021-07-06 11:24:50,378 Downloading itemattr.npz
2021-07-06 11:24:50,378 Done downloading all files.
2021-07-06 11:24:50,379 Load data..
2021-07-06 11:24:50,379 Download data if not in data folder..
2021-07-06 11:24:50,379 Downloading data.npz
2021-07-06 11:24:50,380 Downloading ind2val.json
2021-07-06 11:24:50,381 Downloading itemattr.npz
2021-07-06 11:24:50,381 Done downloading all files.
2021-07-06 11:24:50,381 Load data..
{% endraw %}