code-loader 1.0.66.dev2__py3-none-any.whl → 1.0.67__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- code_loader/contract/visualizer_classes.py +13 -3
- code_loader/default_losses.py +0 -2
- code_loader/default_metrics.py +10 -2
- code_loader/inner_leap_binder/leapbinder_decorators.py +16 -18
- {code_loader-1.0.66.dev2.dist-info → code_loader-1.0.67.dist-info}/METADATA +1 -1
- {code_loader-1.0.66.dev2.dist-info → code_loader-1.0.67.dist-info}/RECORD +8 -8
- {code_loader-1.0.66.dev2.dist-info → code_loader-1.0.67.dist-info}/LICENSE +0 -0
- {code_loader-1.0.66.dev2.dist-info → code_loader-1.0.67.dist-info}/WHEEL +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import List, Any, Union
|
1
|
+
from typing import List, Any, Union, Optional
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
import numpy.typing as npt
|
@@ -112,11 +112,12 @@ class LeapText:
|
|
112
112
|
|
113
113
|
Example:
|
114
114
|
text_data = ['I', 'ate', 'a', 'banana', '', '', '']
|
115
|
-
|
116
|
-
LeapText(
|
115
|
+
heatmap = [0.1, 0.3, 0.2, 0.9, 0.0, 0.0, 0.0]
|
116
|
+
leap_text = LeapText(data=text_data heatmap=heatmap) # Create LeapText object
|
117
117
|
"""
|
118
118
|
data: List[str]
|
119
119
|
type: LeapDataType = LeapDataType.Text
|
120
|
+
heatmap: Optional[List[float]] = None
|
120
121
|
|
121
122
|
def __post_init__(self) -> None:
|
122
123
|
validate_type(self.type, LeapDataType.Text)
|
@@ -124,6 +125,15 @@ class LeapText:
|
|
124
125
|
for value in self.data:
|
125
126
|
validate_type(type(value), str)
|
126
127
|
|
128
|
+
if self.heatmap is not None:
|
129
|
+
validate_type(type(self.heatmap), list)
|
130
|
+
for v in self.heatmap:
|
131
|
+
validate_type(type(v), float)
|
132
|
+
if len(self.heatmap) != len(self.data):
|
133
|
+
raise LeapValidationError(
|
134
|
+
f"Heatmap length ({len(self.heatmap)}) must match the number of tokens in `data` ({len(self.data)})."
|
135
|
+
)
|
136
|
+
|
127
137
|
|
128
138
|
@dataclass
|
129
139
|
class LeapHorizontalBar:
|
code_loader/default_losses.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
from enum import Enum
|
2
2
|
|
3
|
-
from code_loader.contract.datasetclasses import ConfusionMatrixElement # type: ignore
|
4
|
-
from code_loader.contract.enums import ConfusionMatrixValue, MetricDirection # type: ignore
|
5
3
|
from code_loader.default_metrics import mean_absolute_percentage_error_dimension_reduced, \
|
6
4
|
mean_absolute_error_dimension_reduced, mean_squared_logarithmic_error_dimension_reduced, \
|
7
5
|
mean_squared_error_dimension_reduced, categorical_crossentropy, binary_crossentropy
|
code_loader/default_metrics.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# mypy: ignore-errors
|
2
|
+
|
1
3
|
from enum import Enum
|
2
4
|
from typing import List, Tuple
|
3
5
|
import numpy as np
|
@@ -19,12 +21,18 @@ class Metric(Enum):
|
|
19
21
|
|
20
22
|
def binary_crossentropy(ground_truth: np.array, prediction: np.array) -> np.array:
|
21
23
|
ground_truth, prediction = flatten_non_batch_dims(ground_truth, prediction)
|
22
|
-
|
24
|
+
epsilon = 1e-07
|
25
|
+
prediction = np.clip(prediction, epsilon, 1.0 - epsilon)
|
26
|
+
return -(ground_truth * np.log(prediction) + (1 - ground_truth) *
|
27
|
+
np.log(1 - prediction)).sum(axis=1).astype(np.float32)
|
23
28
|
|
24
29
|
|
25
30
|
def categorical_crossentropy(ground_truth: np.array, prediction: np.array) -> np.array:
|
26
31
|
ground_truth, prediction = flatten_non_batch_dims(ground_truth, prediction)
|
27
|
-
|
32
|
+
prediction = prediction / np.sum(prediction, axis=1)
|
33
|
+
epsilon = 1e-07
|
34
|
+
prediction = np.clip(prediction, epsilon, 1.0 - epsilon)
|
35
|
+
return -(ground_truth * np.log(prediction)).sum(axis=1).astype(np.float32)
|
28
36
|
|
29
37
|
def accuracy_reduced(ground_truth: np.array, prediction: np.array) -> np.array:
|
30
38
|
ground_truth, prediction = flatten_non_batch_dims(ground_truth, prediction)
|
@@ -340,38 +340,36 @@ def tensorleap_custom_loss(name: str):
|
|
340
340
|
|
341
341
|
leap_binder.add_custom_loss(user_function, name)
|
342
342
|
|
343
|
+
valid_types = np.ndarray
|
344
|
+
try:
|
345
|
+
import tensorflow as tf
|
346
|
+
valid_types = (np.ndarray, tf.Tensor)
|
347
|
+
except ImportError:
|
348
|
+
pass
|
349
|
+
|
343
350
|
def _validate_input_args(*args, **kwargs):
|
344
|
-
try:
|
345
|
-
import tensorflow as tf
|
346
|
-
except ImportError as e:
|
347
|
-
raise Exception('the input arguments of the custom loss function should be tensorflow tensors') from e
|
348
351
|
|
349
352
|
for i, arg in enumerate(args):
|
350
353
|
if isinstance(arg, list):
|
351
354
|
for y, elem in enumerate(arg):
|
352
|
-
assert isinstance(elem,
|
353
|
-
|
355
|
+
assert isinstance(elem, valid_types), (f'tensorleap_custom_loss validation failed: '
|
356
|
+
f'Element #{y} of list should be a numpy array. Got {type(elem)}.')
|
354
357
|
else:
|
355
358
|
assert isinstance(arg, tf.Tensor), (f'tensorleap_custom_loss validation failed: '
|
356
|
-
f'Argument #{i} should be a
|
359
|
+
f'Argument #{i} should be a numpy array. Got {type(arg)}.')
|
357
360
|
for _arg_name, arg in kwargs.items():
|
358
361
|
if isinstance(arg, list):
|
359
362
|
for y, elem in enumerate(arg):
|
360
|
-
assert isinstance(elem,
|
361
|
-
f'Element #{y} of list should be a
|
363
|
+
assert isinstance(elem,valid_types), (f'tensorleap_custom_loss validation failed: '
|
364
|
+
f'Element #{y} of list should be a numpy array. Got {type(elem)}.')
|
362
365
|
else:
|
363
|
-
assert isinstance(arg,
|
364
|
-
f'Argument #{_arg_name} should be a
|
366
|
+
assert isinstance(arg, valid_types), (f'tensorleap_custom_loss validation failed: '
|
367
|
+
f'Argument #{_arg_name} should be a numpy array. Got {type(arg)}.')
|
365
368
|
|
366
369
|
def _validate_result(result):
|
367
|
-
|
368
|
-
import tensorflow as tf
|
369
|
-
except ImportError:
|
370
|
-
raise Exception('the input arguments of the custom loss function should be tensorflow tensors')
|
371
|
-
|
372
|
-
assert isinstance(result, (np.ndarray, tf.Tensor)), \
|
370
|
+
assert isinstance(result, valid_types), \
|
373
371
|
(f'tensorleap_custom_loss validation failed: '
|
374
|
-
f'The return type should be a numpy array
|
372
|
+
f'The return type should be a numpy array. Got {type(result)}.')
|
375
373
|
|
376
374
|
def inner(*args, **kwargs):
|
377
375
|
_validate_input_args(*args, **kwargs)
|
@@ -6,9 +6,9 @@ code_loader/contract/datasetclasses.py,sha256=L_fSdSvf-eKoez2uBJ8VjfrKedEP0szNOP
|
|
6
6
|
code_loader/contract/enums.py,sha256=6Lo7p5CUog68Fd31bCozIuOgIp_IhSiPqWWph2k3OGU,1602
|
7
7
|
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
8
8
|
code_loader/contract/responsedataclasses.py,sha256=RSx9m_R3LawhK5o1nAcO3hfp2F9oJYtxZr_bpP3bTmw,4005
|
9
|
-
code_loader/contract/visualizer_classes.py,sha256=
|
10
|
-
code_loader/default_losses.py,sha256=
|
11
|
-
code_loader/default_metrics.py,sha256=
|
9
|
+
code_loader/contract/visualizer_classes.py,sha256=zD7SVgI1R_DaGby3FPJY2rFphK162P7F2hRTHp2xUuM,12428
|
10
|
+
code_loader/default_losses.py,sha256=NoOQym1106bDN5dcIk56Elr7ZG5quUHArqfP5-Nyxyo,1139
|
11
|
+
code_loader/default_metrics.py,sha256=v16Mrt2Ze1tXPgfKywGVdRSrkaK4CKLNQztN1UdVqIY,5010
|
12
12
|
code_loader/experiment_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
13
|
code_loader/experiment_api/api.py,sha256=a7wh6Hhe7IaVxu46eV2soSz-yxnmXG3ipU1BBtsEAaQ,2493
|
14
14
|
code_loader/experiment_api/cli_config_utils.py,sha256=n6JMyNrquxql3KKxHhAP8jAzezlRT-PV2KWI95kKsm0,1140
|
@@ -21,13 +21,13 @@ code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZ
|
|
21
21
|
code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaSbeTVzq-2ja_SQw4zi7LXwKL9cY,990
|
22
22
|
code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
|
23
23
|
code_loader/inner_leap_binder/leapbinder.py,sha256=o57Pj-iY61-OBuTjK-jYUKCJ0g2pPWbbqitv_e75Bps,25959
|
24
|
-
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=
|
24
|
+
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=P42U-sqsPKZgsaAzmX8y13F2N3CogeTzU1Iozj4S0GY,20778
|
25
25
|
code_loader/leaploader.py,sha256=K__WKfqtKwEch40au177Po10EUX7gm0PJzcV6kpUMlo,22212
|
26
26
|
code_loader/leaploaderbase.py,sha256=aHlqWDZRacIdBefeB9goYVnpApaNN2FT24uPIWKkCeQ,3090
|
27
27
|
code_loader/utils.py,sha256=aw2i_fqW_ADjLB66FWZd9DfpCQ7mPdMyauROC5Nd51I,2197
|
28
28
|
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
29
29
|
code_loader/visualizers/default_visualizers.py,sha256=Ffx5VHVOe5ujBOsjBSxN_aIEVwFSQ6gbhTMG5aUS-po,2305
|
30
|
-
code_loader-1.0.
|
31
|
-
code_loader-1.0.
|
32
|
-
code_loader-1.0.
|
33
|
-
code_loader-1.0.
|
30
|
+
code_loader-1.0.67.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
31
|
+
code_loader-1.0.67.dist-info/METADATA,sha256=8y0TuGAW-03Mu3pxeGwRDGAa1Z2WMRCZ3Tw98qh6uuQ,849
|
32
|
+
code_loader-1.0.67.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
33
|
+
code_loader-1.0.67.dist-info/RECORD,,
|
File without changes
|
File without changes
|