tf.keras.layers.experimental.preprocessing.CategoryCrossing
Stay organized with collections
Save and categorize content based on your preferences.
Category crossing layer.
Inherits From: PreprocessingLayer
, Layer
, Module
tf.keras.layers.experimental.preprocessing.CategoryCrossing(
depth=None, name=None, separator=None, **kwargs
)
This layer concatenates multiple categorical inputs into a single categorical
output (similar to Cartesian product). The output dtype is string.
Usage:
inp_1 = ['a', 'b', 'c']
inp_2 = ['d', 'e', 'f']
layer = tf.keras.layers.experimental.preprocessing.CategoryCrossing()
layer([inp_1, inp_2])
<tf.Tensor: shape=(3, 1), dtype=string, numpy=
array([[b'a_X_d'],
[b'b_X_e'],
[b'c_X_f']], dtype=object)>
inp_1 = ['a', 'b', 'c']
inp_2 = ['d', 'e', 'f']
layer = tf.keras.layers.experimental.preprocessing.CategoryCrossing(
separator='-')
layer([inp_1, inp_2])
<tf.Tensor: shape=(3, 1), dtype=string, numpy=
array([[b'a-d'],
[b'b-e'],
[b'c-f']], dtype=object)>
Arguments |
depth
|
depth of input crossing. By default None, all inputs are crossed into
one output. It can also be an int or tuple/list of ints. Passing an
integer will create combinations of crossed outputs with depth up to that
integer, i.e., [1, 2, ..., depth ), and passing a tuple of integers will
create crossed outputs with depth for the specified values in the tuple,
i.e., depth =(N1, N2) will create all possible crossed outputs with depth
equal to N1 or N2. Passing None means a single crossed output with all
inputs. For example, with inputs a , b and c , depth=2 means the
output will be [a;b;c;cross(a, b);cross(bc);cross(ca)].
|
separator
|
A string added between each input being joined. Defaults to
'X'.
|
name
|
Name to give to the layer.
|
**kwargs
|
Keyword arguments to construct a layer.
|
Input shape: a list of string or int tensors or sparse tensors of shape
[batch_size, d1, ..., dm]
Output shape: a single string or int tensor or sparse tensor of shape
[batch_size, d1, ..., dm]
Returns |
If any input is RaggedTensor , the output is RaggedTensor .
Else, if any input is SparseTensor , the output is SparseTensor .
Otherwise, the output is Tensor .
|
Example: (depth
=None)
If the layer receives three inputs:
a=[[1], [4]]
, b=[[2], [5]]
, c=[[3], [6]]
the output will be a string tensor:
[[b'1_X_2_X_3'], [b'4_X_5_X_6']]
Example: (depth
is an integer)
With the same input above, and if depth
=2,
the output will be a list of 6 string tensors:
[[b'1'], [b'4']]
[[b'2'], [b'5']]
[[b'3'], [b'6']]
[[b'1_X_2'], [b'4_X_5']]
,
[[b'2_X_3'], [b'5_X_6']]
,
[[b'3_X_1'], [b'6_X_4']]
Example: (depth
is a tuple/list of integers)
With the same input above, and if depth
=(2, 3)
the output will be a list of 4 string tensors:
[[b'1_X_2'], [b'4_X_5']]
,
[[b'2_X_3'], [b'5_X_6']]
,
[[b'3_X_1'], [b'6_X_4']]
,
[[b'1_X_2_X_3'], [b'4_X_5_X_6']]
Methods
adapt
View source
adapt(
data, reset_state=True
)
Fits the state of the preprocessing layer to the data being passed.
Arguments |
data
|
The data to train on. It can be passed either as a tf.data
Dataset, or as a numpy array.
|
reset_state
|
Optional argument specifying whether to clear the state of
the layer at the start of the call to adapt , or whether to start
from the existing state. This argument may not be relevant to all
preprocessing layers: a subclass of PreprocessingLayer may choose to
throw if 'reset_state' is set to False.
|
partial_crossing
View source
partial_crossing(
partial_inputs, ragged_out, sparse_out
)
Gets the crossed output from a partial list/tuple of inputs.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2021-02-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2021-02-18 UTC."],[],[],null,["# tf.keras.layers.experimental.preprocessing.CategoryCrossing\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.4.0/tensorflow/python/keras/layers/preprocessing/category_crossing.py#L39-L210) |\n\nCategory crossing layer.\n\nInherits From: [`PreprocessingLayer`](../../../../../tf/keras/layers/experimental/preprocessing/PreprocessingLayer), [`Layer`](../../../../../tf/keras/layers/Layer), [`Module`](../../../../../tf/Module)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.layers.experimental.preprocessing.CategoryCrossing`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/experimental/preprocessing/CategoryCrossing)\n\n\u003cbr /\u003e\n\n tf.keras.layers.experimental.preprocessing.CategoryCrossing(\n depth=None, name=None, separator=None, **kwargs\n )\n\nThis layer concatenates multiple categorical inputs into a single categorical\noutput (similar to Cartesian product). The output dtype is string.\n\n#### Usage:\n\n inp_1 = ['a', 'b', 'c']\n inp_2 = ['d', 'e', 'f']\n layer = tf.keras.layers.experimental.preprocessing.CategoryCrossing()\n layer([inp_1, inp_2])\n \u003ctf.Tensor: shape=(3, 1), dtype=string, numpy=\n array([[b'a_X_d'],\n [b'b_X_e'],\n [b'c_X_f']], dtype=object)\u003e\n\n inp_1 = ['a', 'b', 'c']\n inp_2 = ['d', 'e', 'f']\n layer = tf.keras.layers.experimental.preprocessing.CategoryCrossing(\n separator='-')\n layer([inp_1, inp_2])\n \u003ctf.Tensor: shape=(3, 1), dtype=string, numpy=\n array([[b'a-d'],\n [b'b-e'],\n [b'c-f']], dtype=object)\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `depth` | depth of input crossing. By default None, all inputs are crossed into one output. It can also be an int or tuple/list of ints. Passing an integer will create combinations of crossed outputs with depth up to that integer, i.e., \\[1, 2, ..., `depth`), and passing a tuple of integers will create crossed outputs with depth for the specified values in the tuple, i.e., `depth`=(N1, N2) will create all possible crossed outputs with depth equal to N1 or N2. Passing `None` means a single crossed output with all inputs. For example, with inputs `a`, `b` and `c`, `depth=2` means the output will be \\[a;b;c;cross(a, b);cross(bc);cross(ca)\\]. |\n| `separator` | A string added between each input being joined. Defaults to '*X*'. |\n| `name` | Name to give to the layer. |\n| `**kwargs` | Keyword arguments to construct a layer. |\n\n\u003cbr /\u003e\n\nInput shape: a list of string or int tensors or sparse tensors of shape\n`[batch_size, d1, ..., dm]`\n\nOutput shape: a single string or int tensor or sparse tensor of shape\n`[batch_size, d1, ..., dm]`\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| If any input is `RaggedTensor`, the output is `RaggedTensor`. Else, if any input is `SparseTensor`, the output is `SparseTensor`. Otherwise, the output is `Tensor`. ||\n\n\u003cbr /\u003e\n\nExample: (`depth`=None)\nIf the layer receives three inputs:\n`a=[[1], [4]]`, `b=[[2], [5]]`, `c=[[3], [6]]`\nthe output will be a string tensor:\n`[[b'1_X_2_X_3'], [b'4_X_5_X_6']]`\n\nExample: (`depth` is an integer)\nWith the same input above, and if `depth`=2,\nthe output will be a list of 6 string tensors:\n`[[b'1'], [b'4']]`\n`[[b'2'], [b'5']]`\n`[[b'3'], [b'6']]`\n`[[b'1_X_2'], [b'4_X_5']]`,\n`[[b'2_X_3'], [b'5_X_6']]`,\n`[[b'3_X_1'], [b'6_X_4']]`\n\nExample: (`depth` is a tuple/list of integers)\nWith the same input above, and if `depth`=(2, 3)\nthe output will be a list of 4 string tensors:\n`[[b'1_X_2'], [b'4_X_5']]`,\n`[[b'2_X_3'], [b'5_X_6']]`,\n`[[b'3_X_1'], [b'6_X_4']]`,\n`[[b'1_X_2_X_3'], [b'4_X_5_X_6']]`\n\nMethods\n-------\n\n### `adapt`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.4.0/tensorflow/python/keras/engine/base_preprocessing_layer.py#L53-L66) \n\n adapt(\n data, reset_state=True\n )\n\nFits the state of the preprocessing layer to the data being passed.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments ||\n|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `data` | The data to train on. It can be passed either as a tf.data Dataset, or as a numpy array. |\n| `reset_state` | Optional argument specifying whether to clear the state of the layer at the start of the call to `adapt`, or whether to start from the existing state. This argument may not be relevant to all preprocessing layers: a subclass of PreprocessingLayer may choose to throw if 'reset_state' is set to False. |\n\n\u003cbr /\u003e\n\n### `partial_crossing`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.4.0/tensorflow/python/keras/layers/preprocessing/category_crossing.py#L129-L142) \n\n partial_crossing(\n partial_inputs, ragged_out, sparse_out\n )\n\nGets the crossed output from a partial list/tuple of inputs."]]