MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / __init__

Method __init__

tensorflow/python/ops/lookup_ops.py:871–932  ·  view source on GitHub ↗

Construct a `IdTableWithHashBuckets` object. Args: table: Table that maps `tf.string` or `tf.int64` keys to `tf.int64` ids. num_oov_buckets: Number of buckets to use for out-of-vocabulary keys. hasher_spec: A `HasherSpec` to specify the hash function to use for assigna

(self,
               table,
               num_oov_buckets,
               hasher_spec=FastHashSpec,
               name=None,
               key_dtype=None)

Source from the content-addressed store, hash-verified

869 """
870
871 def __init__(self,
872 table,
873 num_oov_buckets,
874 hasher_spec=FastHashSpec,
875 name=None,
876 key_dtype=None):
877 """Construct a `IdTableWithHashBuckets` object.
878
879 Args:
880 table: Table that maps `tf.string` or `tf.int64` keys to `tf.int64` ids.
881 num_oov_buckets: Number of buckets to use for out-of-vocabulary keys.
882 hasher_spec: A `HasherSpec` to specify the hash function to use for
883 assignation of out-of-vocabulary buckets (optional).
884 name: A name for the operation (optional).
885 key_dtype: Data type of keys passed to `lookup`. Defaults to
886 `table.key_dtype` if `table` is specified, otherwise `tf.string`. Must
887 be string or integer, and must be castable to `table.key_dtype`.
888
889 Raises:
890 ValueError: when `table` in None and `num_oov_buckets` is not positive.
891 TypeError: when `hasher_spec` is invalid.
892 """
893 # If a name ends with a '/' it is a "name scope", remove all trailing '/'
894 # characters to use as table name.
895 if name:
896 name = name.rstrip("/")
897 if table:
898 if key_dtype is None:
899 key_dtype = table.key_dtype
900 supported_table_key_dtypes = (dtypes.int64, dtypes.string)
901 if table.key_dtype not in supported_table_key_dtypes:
902 raise TypeError("Invalid key dtype, expected one of %s, but got %s." %
903 (supported_table_key_dtypes, key_dtype))
904 if table.key_dtype.is_integer != key_dtype.is_integer:
905 raise TypeError("Invalid key dtype, expected %s but got %s." %
906 ("integer" if key_dtype.is_integer else "non-integer",
907 table.key_dtype))
908 if table.value_dtype != dtypes.int64:
909 raise TypeError("Invalid value dtype, expected %s but got %s." %
910 (dtypes.int64, table.value_dtype))
911 self._table = table
912 name = name or self._table.name
913 else:
914 if num_oov_buckets <= 0:
915 raise ValueError("oov_buckets must be > 0 if no table is supplied.")
916 key_dtype = dtypes.string if key_dtype is None else key_dtype
917 self._table = None
918 name = name or "hash_bucket"
919 if (not key_dtype.is_integer) and (dtypes.string != key_dtype):
920 raise TypeError("Invalid key_dtype, expected integer or string, got %s." %
921 key_dtype)
922 self._num_oov_buckets = num_oov_buckets
923
924 if not isinstance(hasher_spec, HasherSpec):
925 raise TypeError("hasher_spec must be of type HasherSpec, got %s" %
926 hasher_spec)
927 self._hasher_spec = hasher_spec
928 if name:

Callers

nothing calls this directly

Calls 2

splitMethod · 0.45
__init__Method · 0.45

Tested by

no test coverage detected