tf.contrib.lookup.index_to_string_table_from_file
Stay organized with collections
Save and categorize content based on your preferences.
Returns a lookup table that maps a Tensor
of indices into strings.
tf.contrib.lookup.index_to_string_table_from_file(
vocabulary_file, vocab_size=None, default_value='UNK', name=None,
key_column_index=TextFileIndex.LINE_NUMBER,
value_column_index=TextFileIndex.WHOLE_LINE, delimiter='\t'
)
This operation constructs a lookup table to map int64 indices into string
values. The table is initialized from a vocabulary file specified in
vocabulary_file
, where the whole line is the value and the
zero-based line number is the index.
Any input which does not have a corresponding index in the vocabulary file
(an out-of-vocabulary entry) is assigned the default_value
The underlying table must be initialized by calling
session.run(tf.compat.v1.tables_initializer())
or
session.run(table.init())
once.
To specify multi-column vocabulary files, use key_column_index and
value_column_index and delimiter.
- 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
.
Sample Usages:
If we have a vocabulary file "test.txt" with the following content:
emerson
lake
palmer
indices = tf.constant([1, 5], tf.int64)
table = tf.lookup.index_to_string_table_from_file(
vocabulary_file="test.txt", default_value="UNKNOWN")
values = table.lookup(indices)
...
tf.compat.v1.tables_initializer().run()
values.eval() ==> ["lake", "UNKNOWN"]
Args |
vocabulary_file
|
The vocabulary filename, may be a constant scalar Tensor .
|
vocab_size
|
Number of the elements in the vocabulary, if known.
|
default_value
|
The value to use for out-of-vocabulary indices.
|
name
|
A name for this op (optional).
|
key_column_index
|
The column index from the text file to get the key
values from. The default is to use the line number, starting from zero.
|
value_column_index
|
The column index from the text file to get the value
values from. The default is to use the whole line content.
|
delimiter
|
The delimiter to separate fields in a line.
|
Returns |
The lookup table to map a string values associated to a given index int64
Tensors .
|
Raises |
ValueError
|
when vocabulary_file is empty.
|
ValueError
|
when vocab_size is invalid.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2020-10-01 UTC."],[],[],null,["# tf.contrib.lookup.index_to_string_table_from_file\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/lookup_ops.py#L1441-L1529) |\n\nReturns a lookup table that maps a `Tensor` of indices into strings. \n\n tf.contrib.lookup.index_to_string_table_from_file(\n vocabulary_file, vocab_size=None, default_value='UNK', name=None,\n key_column_index=TextFileIndex.LINE_NUMBER,\n value_column_index=TextFileIndex.WHOLE_LINE, delimiter='\\t'\n )\n\nThis operation constructs a lookup table to map int64 indices into string\nvalues. The table is initialized from a vocabulary file specified in\n`vocabulary_file`, where the whole line is the value and the\nzero-based line number is the index.\n\nAny input which does not have a corresponding index in the vocabulary file\n(an out-of-vocabulary entry) is assigned the `default_value`\n\nThe underlying table must be initialized by calling\n`session.run(tf.compat.v1.tables_initializer())` or\n`session.run(table.init())` once.\n\nTo specify multi-column vocabulary files, use key_column_index and\nvalue_column_index and delimiter.\n\n- TextFileIndex.LINE_NUMBER means use the line number starting from zero, expects data type int64.\n- TextFileIndex.WHOLE_LINE means use the whole line content, expects data type string.\n- A value \\\u003e=0 means use the index (starting at zero) of the split line based on `delimiter`.\n\n#### Sample Usages:\n\nIf we have a vocabulary file \"test.txt\" with the following content: \n\n emerson\n lake\n palmer\n\n indices = tf.constant([1, 5], tf.int64)\n table = tf.lookup.index_to_string_table_from_file(\n vocabulary_file=\"test.txt\", default_value=\"UNKNOWN\")\n values = table.lookup(indices)\n ...\n tf.compat.v1.tables_initializer().run()\n\n values.eval() ==\u003e [\"lake\", \"UNKNOWN\"]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------------|------------------------------------------------------------------------------------------------------------------------------|\n| `vocabulary_file` | The vocabulary filename, may be a constant scalar `Tensor`. |\n| `vocab_size` | Number of the elements in the vocabulary, if known. |\n| `default_value` | The value to use for out-of-vocabulary indices. |\n| `name` | A name for this op (optional). |\n| `key_column_index` | The column index from the text file to get the `key` values from. The default is to use the line number, starting from zero. |\n| `value_column_index` | The column index from the text file to get the `value` values from. The default is to use the whole line content. |\n| `delimiter` | The delimiter to separate fields in a line. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The lookup table to map a string values associated to a given index `int64` `Tensors`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|----------------------------------|\n| `ValueError` | when `vocabulary_file` is empty. |\n| `ValueError` | when `vocab_size` is invalid. |\n\n\u003cbr /\u003e"]]