finds.recipes.learn

Miscellaneous utilities

Copyright 2022, Terence Lim

MIT License

finds.recipes.learn.cuda_summary()[source]

Print details of cuda environment

Notes:

finds.recipes.learn.form_batches(batch_size: int, idx: List) List[List[int]][source]

Shuffles idx list into minibatches each of size batch_size

Parameters:
  • batch_size – Size of each minibatch

  • idx – List of indexes

Returns:

List of batches of shuffled indexes

finds.recipes.learn.form_input(docs: List[List[int]], pad: int | None = 0) List[List[int]][source]

Pad lists of index lists to form batch of equal lengths

Parameters:
  • docs – Input documents as lists of int lists

  • pad – Value to pad with (None to pad with random value from list)

Returns:

List of padded lists of ints

finds.recipes.learn.form_splits(labels: List[str | int] | int, test_size: float | int = 0.2, random_state: int = 42) List[List][source]

Wraps over train_test_split to stratifies labels into split indexes

Parameters:
  • labels – Labels of series to stratify, or length of series to shuffle

  • test_size – Desired size of test set as fraction or number of samples

  • random_state – Set random seed

Returns:

tuple of stratified train indexes and test indexes

finds.recipes.learn.torch_summary(model)[source]

Print torch network summary

https://stackoverflow.com/questions/42480111/how-do-i-print-the-model-summary-in-pytorch

finds.recipes.learn.torch_trainable(model, total: bool = True) List[int] | int[source]

Returns total number of trainable parameters in torch model