tf.lookup.TextFileInitializer

View source on GitHub

Table initializers from a text file.

tf.lookup.TextFileInitializer(
    filename, key_dtype, key_index, value_dtype, value_index, vocab_size=None,
    delimiter='\t', name=None
)

This initializer assigns one entry in the table for each line in the file.

The key and value type of the table to initialize is given by key_dtype and value_dtype.

The key and value content to get from each line is specified by the key_index and value_index.

For example if we have a file with the following content:

emerson 10
lake 20
palmer 30

The following snippet initializes a table with the first column as keys and second column as values:

table = tf.lookup.StaticHashTable(tf.lookup.TextFileInitializer(
    "test.txt", tf.string, 0, tf.int64, 1, delimiter=" "), -1)
...
table.init.run()

Similarly to initialize the whole line as keys and the line number as values.

table = tf.lookup.StaticHashTable(tf.lookup.TextFileInitializer(
    "test.txt", tf.string, tf.lookup.TextFileIndex.WHOLE_LINE,
    tf.int64, tf.lookup.TextFileIndex.LINE_NUMBER, delimiter=" "), -1)
...
table.init.run()

Args:

Attributes:

Raises:

Methods

initialize

View source

initialize(
    table
)

Initializes the table from a text file.

Args:

Returns:

The operation that initializes the table.

Raises: