finds.recipes.learn
Miscellaneous utilities
Copyright 2022, Terence Lim
MIT License
- finds.recipes.learn.cuda_summary()[source]
Print details of cuda environment
Notes:
check cuda version (e.g. 11.4?): Nvidia-smi
install matching torch version
pip3 install torch torchvision torchaudio –extra-index-url https://download.pytorch.org/whl/cu116
you can specify $ export TORCH_CUDA_ARCH_LIST=”8.6” in your environment to force it to build with SM 8.6 support
- 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