Initializes the table from a text file. Args: table: The table to be initialized. Returns: The operation that initializes the table. Raises: TypeError: when the keys and values data types do not match the table key and value data types.
(self, table)
| 632 | super(TextFileInitializer, self).__init__(key_dtype, value_dtype) |
| 633 | |
| 634 | def initialize(self, table): |
| 635 | """Initializes the table from a text file. |
| 636 | |
| 637 | Args: |
| 638 | table: The table to be initialized. |
| 639 | |
| 640 | Returns: |
| 641 | The operation that initializes the table. |
| 642 | |
| 643 | Raises: |
| 644 | TypeError: when the keys and values data types do not match the table |
| 645 | key and value data types. |
| 646 | """ |
| 647 | _check_table_dtypes(table, self.key_dtype, self.value_dtype) |
| 648 | with ops.name_scope(self._name, "text_file_init", (table.resource_handle,)): |
| 649 | filename = ops.convert_to_tensor( |
| 650 | self._filename, dtypes.string, name="asset_filepath") |
| 651 | init_op = gen_lookup_ops.initialize_table_from_text_file_v2( |
| 652 | table.resource_handle, filename, self._key_index, self._value_index, |
| 653 | -1 if self._vocab_size is None else self._vocab_size, self._delimiter) |
| 654 | ops.add_to_collection(ops.GraphKeys.TABLE_INITIALIZERS, init_op) |
| 655 | # If the filename tensor is anything other than a string constant (e.g., |
| 656 | # if it is a placeholder) then it does not make sense to track it as an |
| 657 | # asset. |
| 658 | if not context.executing_eagerly() and constant_op.is_constant(filename): |
| 659 | ops.add_to_collection(ops.GraphKeys.ASSET_FILEPATHS, filename) |
| 660 | return init_op |
| 661 | |
| 662 | @property |
| 663 | def _shared_name(self): |
nothing calls this directly
no test coverage detected