utils
This module contains some utility functions
create_dir
create_dir (path_dir)
Create directory if needed
val2iterable
val2iterable (val, lsize=1, t='list')
Convert an element (nonlist value) to an iterable. Currently support list and nparray
seed_everything
seed_everything (seed=42)
seed_notorch
seed_notorch (seed=42)
print_msg
print_msg (msg, dash_num=5, verbose=True)
callable_name
callable_name (any_callable:Callable[...,Any])
To get name of any callable
check_and_get_attribute
check_and_get_attribute (obj, attr_name)
load_pickle
load_pickle (fname, parent='pickle_files')
save_to_pickle
save_to_pickle (my_list, fname, parent='pickle_files')
check_input_validation
check_input_validation (df:pandas.core.frame.DataFrame, verbose=True)
check_text_leaking
check_text_leaking (trn_txt:list, test_txt:list, verbose=True)
none2emptystr
none2emptystr (x)
lambda_batch
lambda_batch (inp, feature, func, is_batched)
Details | |
---|---|
inp | HuggingFace Dataset |
feature | Feature name. |
func | The function to apply |
is_batched | Whether batching is applied |
lambda_map_batch
lambda_map_batch (inp, feature, func, is_batched, output_feature='same', is_func_batched=False)
Type | Default | Details | |
---|---|---|---|
inp | HuggingFace Dataset | ||
feature | Feature name. | ||
func | The function to apply | ||
is_batched | Whether batching is applied | ||
output_feature | str | same | New feature output, if different from ‘feature’. If none, use function’s output feature(s) |
is_func_batched | bool | False | Whether the func above only works with batch (mostly sklearn’s) |
augmentation_stream_generator
augmentation_stream_generator (dset, text_name, func)
func_all
func_all (x, functions)
get_dset_col_names
get_dset_col_names (dset)
hf_filter_dset
hf_filter_dset (dset, func, is_batched=True, batch_size=1024, num_proc=1)
hf_map_dset
hf_map_dset (dset, func, is_batched=True, batch_size=1024, num_proc=1)
resize_model_embeddings
resize_model_embeddings (model, tokenizer)
sigmoid
sigmoid (x)
*A numerically stable version of the logistic sigmoid function.
Source: assignment3 of cs231n*