deepr.prepros.TableInitializer
- class deepr.prepros.TableInitializer(table_initializer_fn)[source]
Table Initializer.
Tensorflow does not allow tables initialization inside a
maptransformation (all tables must be created outside themap).To remedy this, follow this example
First, create a
table_initializer_fnthat uses thetf.AUTO_REUSEargument.>>> 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_fnon atf.data.Dataset, it will run thetable_initializer_fnat the beginning (outside themaptransformation), then apply theLookupthat uses the sametable_initializer_fn, but thanks toreuse=tf.AUTO_REUSEinstead 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