Type StaticVocabularyTable
Namespace tensorflow.lookup
Parent StaticVocabularyTable
Interfaces IStaticVocabularyTable
String to Id table wrapper that assigns out-of-vocabulary keys to buckets. For example, if an instance of `StaticVocabularyTable` is initialized with a
string-to-id initializer that maps: * `emerson -> 0`
* `lake -> 1`
* `palmer -> 2` The `Vocabulary` object will performs the following mapping: * `emerson -> 0`
* `lake -> 1`
* `palmer -> 2`
* ` -> bucket_id`, where bucket_id will be between `3` and
`3 + num_oov_buckets - 1`, calculated by:
`hash() % num_oov_buckets + vocab_size` If input_tensor is `["emerson", "lake", "palmer", "king", "crimson"]`,
the lookup result is `[0, 1, 2, 4, 7]`. If `initializer` is None, only out-of-vocabulary buckets are used. Example usage:
The hash function used for generating out-of-vocabulary buckets ID is
Fingerprint64.
Show Example
num_oov_buckets = 3 input_tensor = tf.constant(["emerson", "lake", "palmer", "king", "crimnson"]) table = tf.lookup.StaticVocabularyTable( tf.TextFileIdTableInitializer(filename), num_oov_buckets) out = table.lookup(input_tensor). table.init.run() print(out.eval())