Skip to content

string_to_string_list

StringToStringListLayer ¤

StringToStringListLayer(
    name=None,
    input_dtype=None,
    output_dtype=None,
    separator=",",
    default_value="",
    list_length=1,
    **kwargs
)

Bases: BaseLayer

A layer that converts a string to a list of strings by splitting on a separator. It takes a default value and a list_length parameter to ensure that the output tensor has the correct shape.

If the separator is empty, the string is split on bytes/characters.

Initialises the StringToStringListLayer layer.

Parameters:

Name Type Description Default
name Optional[str]

The name of the layer. Defaults to None.

None
input_dtype Optional[str]

The dtype to cast the input to. Defaults to None.

None
output_dtype Optional[str]

The dtype to cast the output to. Defaults to None.

None
separator str

The separator to use when joining the strings. Defaults to ",".

','
default_value str

The value to use when the input is empty. Defaults to "".

''
list_length int

The length of the string list in the output tensor. Defaults to 1.

1
Source code in src/kamae/keras/tensorflow/layers/string_to_string_list.py
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
def __init__(
    self,
    name: Optional[str] = None,
    input_dtype: Optional[str] = None,
    output_dtype: Optional[str] = None,
    separator: str = ",",
    default_value: str = "",
    list_length: int = 1,
    **kwargs: Any,
) -> None:
    """
    Initialises the StringToStringListLayer layer.

    :param name: The name of the layer. Defaults to `None`.
    :param input_dtype: The dtype to cast the input to. Defaults to `None`.
    :param output_dtype: The dtype to cast the output to. Defaults to `None`.
    :param separator: The separator to use when joining the strings.
    Defaults to `","`.
    :param default_value: The value to use when the input is empty.
    Defaults to `""`.
    :param list_length: The length of the string list in the output tensor.
    Defaults to `1`.
    """
    super().__init__(
        name=name, input_dtype=input_dtype, output_dtype=output_dtype, **kwargs
    )
    self.separator = separator
    self.list_length = list_length
    self.default_value = default_value

compatible_dtypes property ¤

compatible_dtypes

Returns the compatible dtypes of the layer.

Returns:

Type Description
Optional[List[str]]

The compatible dtypes of the layer.

get_config ¤

get_config()

Gets the configuration of the StringToStringList layer. Used for saving and loading from a model.

Specifically adds the axis, separator and keepdims to the config dictionary.

Returns:

Type Description
Dict[str, Any]

Dictionary of the configuration of the layer.

Source code in src/kamae/keras/tensorflow/layers/string_to_string_list.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def get_config(self) -> Dict[str, Any]:
    """
    Gets the configuration of the StringToStringList layer.
    Used for saving and loading from a model.

    Specifically adds the `axis`, `separator` and `keepdims` to the config
    dictionary.

    :returns: Dictionary of the configuration of the layer.
    """
    config = super().get_config()
    config.update(
        {
            "separator": self.separator,
            "default_value": self.default_value,
            "list_length": self.list_length,
        }
    )
    return config