sub_string_delim_at_index
SubStringDelimAtIndexLayer ¤
SubStringDelimAtIndexLayer(
name=None,
input_dtype=None,
output_dtype=None,
delimiter="_",
index=0,
default_value="",
**kwargs
)
Bases: BaseLayer
Layer which splits a string tensor by a delimiter and returns the substring at the specified index. If the delimiter is the empty string, the string is split into bytes/characters. If the index is negative, start counting from the end of the string. If the index is out of bounds, the default value is returned.
Initialise the SubStringDelimAtIndexLayer layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Optional[str]
|
The name of the layer. Defaults to |
None
|
input_dtype
|
Optional[str]
|
The dtype to cast the input to. Defaults to |
None
|
output_dtype
|
Optional[str]
|
The dtype to cast the output to. Defaults to |
None
|
delimiter
|
str
|
String to split on. Defaults to |
'_'
|
index
|
int
|
Index of the substring to return. Defaults to |
0
|
default_value
|
str
|
Value to return if index is out of bounds. Defaults to |
''
|
Source code in src/kamae/tensorflow/layers/sub_string_delim_at_index.py
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 | |
compatible_dtypes
property
¤
compatible_dtypes
_call ¤
_call(inputs, **kwargs)
Splits the input string tensor by the delimiter and returns the substring at the specified index. If the index is out of bounds, the default value is returned.
Decorated with @enforce_single_tensor_input to ensure that the input
is a single tensor. Raises an error if an iterable of tensors is passed
in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
Tensor
|
Input tensor. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor with the substring at the specified index. |
Source code in src/kamae/tensorflow/layers/sub_string_delim_at_index.py
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 | |
get_config ¤
get_config()
Returns the config of the SubStringDelimAtIndex layer. Used for saving and loading from a model.
Specifically adds the delimiter, index and default_value to the config.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary of the config of the layer. |
Source code in src/kamae/tensorflow/layers/sub_string_delim_at_index.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
resolve_negative_indices
staticmethod
¤
resolve_negative_indices(ragged_tensor, index)
Resolves negative indices to positive indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ragged_tensor
|
RaggedTensor
|
Ragged tensor |
required |
index
|
int
|
The index to resolve. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The resolved index. |
Source code in src/kamae/tensorflow/layers/sub_string_delim_at_index.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |