deepr.prepros.TableInitializer
- class deepr.prepros.TableInitializer(table_initializer_fn)[source]
Table Initializer.
Tensorflow does not allow tables initialization inside a
map
transformation (all tables must be created outside themap
).To remedy this, follow this example
First, create a
table_initializer_fn
that uses thetf.AUTO_REUSE
argument.>>> import deepr >>> def table_initializer_fn(): ... return deepr.utils.table_from_mapping( ... name="partner_table", mapping={1: 2}, reuse=tf.AUTO_REUSE ... )
Then, define your preprocessing pipeline as follows
>>> prepro_fn = deepr.prepros.Serial( ... deepr.prepros.TableInitializer(table_initializer_fn), ... deepr.prepros.Map(deepr.layers.Lookup(table_initializer_fn)), ... )
When applying the
prepro_fn
on atf.data.Dataset
, it will run thetable_initializer_fn
at the beginning (outside themap
transformation), then apply theLookup
that uses the sametable_initializer_fn
, but thanks toreuse=tf.AUTO_REUSE
instead of creating a new table, it will simply reuse the table created by theTableInitializer
.Methods
__init__
(table_initializer_fn)apply
(dataset[, mode])Pre-process a dataset