LostTech.TensorFlow : API Documentation

Type TextFileInitializer

Namespace tensorflow.lookup

Parent TableInitializerBase

Interfaces ITextFileInitializer

Table initializers from a text file.

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`.

* `TextFileIndex.LINE_NUMBER` means use the line number starting from zero, expects data type int64. * `TextFileIndex.WHOLE_LINE` means use the whole line content, expects data type string. * A value `>=0` means use the index (starting at zero) of the split line based on `delimiter`.

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:

* `emerson -> 10` * `lake -> 20` * `palmer -> 30` Similarly to initialize the whole line as keys and the line number as values.

* `emerson 10 -> 0` * `lake 20 -> 1` * `palmer 30 -> 2`
Show Example
table = tf.lookup.StaticHashTable(tf.lookup.TextFileInitializer(
                "test.txt", tf.string, 0, tf.int64, 1, delimiter=" "), -1)
           ...
            table.init.run() 

Methods

Properties

Public static methods

TextFileInitializer NewDyn(object filename, object key_dtype, object key_index, object value_dtype, object value_index, object vocab_size, ImplicitContainer<T> delimiter, object name)

Constructs a table initializer object to populate from a text file.

It generates one key-value pair per line. The type of table key and value are specified by `key_dtype` and `value_dtype`, respectively. Similarly the content of the key and value are specified by the key_index and value_index.

- TextFileIndex.LINE_NUMBER means use the line number starting from zero, expects data type int64. - TextFileIndex.WHOLE_LINE means use the whole line content, expects data type string. - A value >=0 means use the index (starting at zero) of the split line based on `delimiter`.
Parameters
object filename
The filename of the text file to be used for initialization. The path must be accessible from wherever the graph is initialized (eg. trainer or eval workers). The filename may be a scalar `Tensor`.
object key_dtype
The `key` data type.
object key_index
the index that represents information of a line to get the table 'key' values from.
object value_dtype
The `value` data type.
object value_index
the index that represents information of a line to get the table 'value' values from.'
object vocab_size
The number of elements in the file, if known.
ImplicitContainer<T> delimiter
The delimiter to separate fields in a line.
object name
A name for the operation (optional).

Public properties

DType key_dtype get;

object key_dtype_dyn get;

object PythonObject get;

DType value_dtype get;

object value_dtype_dyn get;