View source: R/layers-preprocessing.R
layer_string_lookup | R Documentation |
A preprocessing layer which maps string features to integer indices.
layer_string_lookup(
object,
max_tokens = NULL,
num_oov_indices = 1L,
mask_token = NULL,
oov_token = "[UNK]",
vocabulary = NULL,
idf_weights = NULL,
encoding = "utf-8",
invert = FALSE,
output_mode = "int",
sparse = FALSE,
pad_to_max_tokens = FALSE,
...
)
object |
What to compose the new
|
max_tokens |
Maximum size of the vocabulary for this layer. This should
only be specified when adapting the vocabulary or when setting
|
num_oov_indices |
The number of out-of-vocabulary tokens to use. If this value is more than 1, OOV inputs are hashed to determine their OOV value. If this value is 0, OOV inputs will cause an error when calling the layer. Defaults to 1. |
mask_token |
A token that represents masked inputs. When |
oov_token |
Only used when |
vocabulary |
Optional. Either an array of strings or a string path to a
text file. If passing an array, can pass a character vector or
or 1D tensor containing the string vocabulary terms. If passing a file
path, the file should contain one line per term in the vocabulary. If
this argument is set, there is no need to |
idf_weights |
Only valid when |
encoding |
Optional. The text encoding to use to interpret the input
strings. Defaults to |
invert |
Only valid when |
output_mode |
Specification for the output of the layer. Defaults to
|
sparse |
Boolean. Only applicable when |
pad_to_max_tokens |
Only applicable when |
... |
standard layer arguments. |
This layer translates a set of arbitrary strings into integer output via a
table-based vocabulary lookup. This layer will perform no splitting or
transformation of input strings. For a layer than can split and tokenize
natural language, see the layer_text_vectorization()
layer.
The vocabulary for the layer must be either supplied on construction or
learned via adapt()
. During adapt()
, the layer will analyze a data set,
determine the frequency of individual strings tokens, and create a
vocabulary from them. If the vocabulary is capped in size, the most frequent
tokens will be used to create the vocabulary and all others will be treated
as out-of-vocabulary (OOV).
There are two possible output modes for the layer.
When output_mode
is "int"
,
input strings are converted to their index in the vocabulary (an integer).
When output_mode
is "multi_hot"
, "count"
, or "tf_idf"
, input strings
are encoded into an array where each dimension corresponds to an element in
the vocabulary.
The vocabulary can optionally contain a mask token as well as an OOV token
(which can optionally occupy multiple indices in the vocabulary, as set
by num_oov_indices
).
The position of these tokens in the vocabulary is fixed. When output_mode
is "int"
, the vocabulary will begin with the mask token (if set), followed
by OOV indices, followed by the rest of the vocabulary. When output_mode
is "multi_hot"
, "count"
, or "tf_idf"
the vocabulary will begin with
OOV indices and instances of the mask token will be dropped.
For an overview and full list of preprocessing layers, see the preprocessing guide.
adapt()
https://www.tensorflow.org/api_docs/python/tf/keras/layers/StringLookup
https://keras.io/api/layers/preprocessing_layers/categorical/string_lookup
Other categorical features preprocessing layers:
layer_category_encoding()
,
layer_hashing()
,
layer_integer_lookup()
Other preprocessing layers:
layer_category_encoding()
,
layer_center_crop()
,
layer_discretization()
,
layer_hashing()
,
layer_integer_lookup()
,
layer_normalization()
,
layer_random_brightness()
,
layer_random_contrast()
,
layer_random_crop()
,
layer_random_flip()
,
layer_random_height()
,
layer_random_rotation()
,
layer_random_translation()
,
layer_random_width()
,
layer_random_zoom()
,
layer_rescaling()
,
layer_resizing()
,
layer_text_vectorization()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.