transformation
Bases: Module
, function
The base class of the data transformation function in the tinyBIG toolkit.
It will be used as the base class template for defining the data expansion and compression functions.
...
Notes
Formally, given the underlying data distribution mapping \(f: {R}^m \to {R}^n\) to be learned, the data expansion function \(\kappa\) projects input data into a new space shown as follows:
\[ \kappa: {R}^m \to {R}^{D}, \]
where the target dimension vector space dimension \(D\) is determined when defining \(\kappa\).
In practice, the function \(\kappa\) can either expand or compress the input to a higher- or lower-dimensional space. The corresponding function, \(\kappa\), can also be referred to as the data expansion function (if \(D > m\)) and data compression function (if \(D < m\)), respectively. Collectively, these can be unified under the term "data transformation functions".
Attributes:
Name | Type | Description |
---|---|---|
name |
str, default = 'base_transformation'
|
Name of the data transformation function. |
preprocess_functions |
function | list, default = None
|
Preprocessing function or function list. |
postprocess_functions |
function | list, default = None
|
Postprocessing function or function list. |
preprocess_function_configs |
dict, default = None
|
Configs of preprocessing function or function list. |
postprocess_function_configs |
dict, default = None
|
Configs of postprocessing function or function list. |
device |
str, default = 'cpu'
|
Device of the data transformation function of the data transformation. |
Methods:
Name | Description |
---|---|
__init__ |
It initializes the data transformation function. |
get_name |
It gets the name of the data transformation function. |
pre_process |
It performs the pre-processing of the input data before transformation. |
post_process |
It performs the post-processing of the input data after transformation. |
calculate_D |
It calculate the expansion space dimension based on the input dimension parameter. |
forward |
The forward method to perform data transformation. |
__call__ |
The built-in callable method of the data transformation function. |
Source code in tinybig/module/base_transformation.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 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 112 113 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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
__call__(*args, **kwargs)
The re-implementation of the callable method.
It applies the data expansion operation to the input data and returns the expansion result by calling the "forward" method.
Returns:
Type | Description |
---|---|
Tensor
|
The expanded data vector of the input. |
Source code in tinybig/module/base_transformation.py
__init__(name='base_transformation', preprocess_functions=None, postprocess_functions=None, preprocess_function_configs=None, postprocess_function_configs=None, device='cpu', *args, **kwargs)
The initialization method of the base data transformation function.
It initializes a base data transformation function object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Name of the data transformation function. |
'base_transformation'
|
|
preprocess_functions
|
Preprocessing function or function list. |
None
|
|
postprocess_functions
|
Postprocessing function or function list. |
None
|
|
preprocess_function_configs
|
Configs of preprocessing function or function list. |
None
|
|
postprocess_function_configs
|
Configs of postprocessing function or function list. |
None
|
|
device
|
The device of the transformation function. |
'cpu'
|
Returns:
Type | Description |
---|---|
object
|
The base data transformation function object. |
Source code in tinybig/module/base_transformation.py
calculate_D(m)
abstractmethod
The transformation dimension calculation method.
It calculates the intermediate transformation space dimension based on the input dimension parameter m. The method is declared as an abstractmethod and needs to be implemented in the inherited classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
int
|
The dimension of the input space. |
required |
Returns:
Type | Description |
---|---|
int
|
The dimension of the transformation space. |
Source code in tinybig/module/base_transformation.py
forward(x, device='cpu', *args, **kwargs)
abstractmethod
The forward method of the data transformation function.
It applies the data expansion operation to the input data and returns the expansion result. The method is declared as a abstractmethod and needs to be implemented in the inherited classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input data vector. |
required |
device
|
The device to perform the data transformation. |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
The expanded data vector of the input. |
Source code in tinybig/module/base_transformation.py
get_name()
The name retrieval method of data transformation function.
It returns the name of the data transformation function.
Returns:
Type | Description |
---|---|
str
|
The name of the data transformation function. |
Source code in tinybig/module/base_transformation.py
post_process(x, device='cpu', *args, **kwargs)
The post-processing method of data transformation function.
It post-process the input vector x with the (optional) post-processing functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input data vector. |
required |
device
|
The device to perform the data expansion. |
'cpu'
|
|
args
|
The other parameters of the method. |
()
|
|
kwargs
|
The other parameters of the method. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
It returns the data vector after the post-processing. |
Source code in tinybig/module/base_transformation.py
pre_process(x, device='cpu', *args, **kwargs)
The pre-processing method of data transformation function.
It pre-process the input vector x with the (optional) pre-processing functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input data vector. |
required |
device
|
The device to perform the data expansion. |
'cpu'
|
|
args
|
The other parameters of the method. |
()
|
|
kwargs
|
The other parameters of the method. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
It returns the data vector after the pre-processing. |