utils
cast_general_vector(vector, return_type)
Cast a vector to the desired type.
vector: GeneralVector: Vector to cast return_type: GeneralVectorLiteral: Wanted return type.
Vector in desired format
Examples:
>>> from klinker.utils import cast_general_vector
>>> import numpy as np
>>> arr = np.array([1,2,3])
>>> cast_general_vector(arr, "pt")
tensor([1, 2, 3])
>>> t_arr = cast_general_vector(arr, "pt")
>>> t_arr
tensor([1, 2, 3])
>>> cast_general_vector(t_arr, "np")
array([1, 2, 3])
Source code in klinker/utils.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
concat_frames(frames)
Concatenate dask or pandas frames.
frames: List[Frame]: List of dataframes.
concatenated dataframes
Source code in klinker/utils.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
resolve_device(device=None)
Resolve a torch.device given a desired device (string).
device: DeviceHint: (Default value = None)
Returns:
Source code in klinker/utils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
tokenize_row(row, tokenize_fn=word_tokenize, min_token_length=1)
Tokenize rows of series.
row: pd.Series: row with values to tokenize tokenize_fn: Callable[[str], List[str]]: Tokenization function min_token_length: int: Discard tokens below this value
List of tokens
Source code in klinker/utils.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |