utils

Utilities needed for little repititive tasks

source

namestr

 namestr (obj, namespace=None)

Returns the name of the object obj passed

Here’s an example of how namestr works:

a = 'some_var'
test_eq(namestr(a, globals()), ['a'])

source

list_files

 list_files (startpath)

[simulates the linux tree cmd] (https://stackoverflow.com/questions/9727673/list-directory-tree-structure-in-python)


source

make_paths

 make_paths (path, prefix=None)

with path as basedir, makes data and models dir and returns a dictionary of relevant pathlib objects

with tempfile.TemporaryDirectory() as tempdirname:
    print(f"created temporary dir: {tempdirname}")
    _paths = make_paths(Path(tempdirname), "mimic3-9k")
    for v in _paths.values(): v.touch()
    list_files(tempdirname)
created temporary dir: /tmp/tmpi1evi3rs
tmpi1evi3rs/
    data/
        mimic3-9k_tok.ft
        mimic3-9k_lbl.ft
        mimic3-9k.csv
        mimic3-9k_tok_lbl.ft
    models/
        mimic3-9k_dls_clas.pkl
        mimic3-9k_dls_lm.pkl
        mimic3-9k_lm_r.pth
        mimic3-9k_lm_finetuned_r.pth
        mimic3-9k_tok_lbl_info.pkl
        mimic3-9k_dls_lm_vocab_r.pkl
        mimic3-9k_dls_collab.pkl
        mimic3-9k_clas.pth
        mimic3-9k_dset_clas.pkl
        mimic3-9k_dls_lm_vocab.pkl
        mimic3-9k_dls_learn_rank.pkl
        mimic3-9k_dls_lm_r.pkl
        mimic3-9k_dset_clas_r.pkl
        mimic3-9k_lm.pth
        mimic3-9k_clas_r.pth
        mimic3-9k_lm_finetuned.pth
        mimic3-9k_dls_clas_r.pkl
        collab/
            mimic3-9k_collab.pth

source

plot_hist

 plot_hist (data, x_label=None, y_label=None, title='Histogram')

source

plot_reduction

 plot_reduction (X, tSNE=True, n_comps=None, perplexity=30, figsize=(6,
                 4))

PCA on X and plots the first two principal components, returns the decomposition and the explained variances for each directions, if tSNE then does a tSNE after PCA.


source

test_eqs

 test_eqs (*args)
test_eqs(1, 1, 9//9)

source

validate

 validate (learner, cb=<class
           'fastai.callback.tracker.SaveModelCallback'>)

validates a learner within a context manager after temporarily removing cb if it exists


source

cudamem

 cudamem (device=device(type='cpu'))