本文整理汇总了Python中tensorflow.python.ops.string_ops.string_to_hash_bucket_fast方法的典型用法代码示例。如果您正苦于以下问题:Python string_ops.string_to_hash_bucket_fast方法的具体用法?Python string_ops.string_to_hash_bucket_fast怎么用?Python string_ops.string_to_hash_bucket_fast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.ops.string_ops
的用法示例。
在下文中一共展示了string_ops.string_to_hash_bucket_fast方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _transform_feature
# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_to_hash_bucket_fast [as 别名]
def _transform_feature(self, inputs):
input_tensor = _to_sparse_input(inputs.get(self.key))
if not isinstance(input_tensor, sparse_tensor_lib.SparseTensor):
raise ValueError('SparseColumn input must be a SparseTensor.')
_assert_string_or_int(
input_tensor.dtype,
prefix='column_name: {} input_tensor'.format(self.key))
if self.dtype.is_integer != input_tensor.dtype.is_integer:
raise ValueError(
'Column dtype and SparseTensors dtype must be compatible. '
'key: {}, column dtype: {}, tensor dtype: {}'.format(
self.key, self.dtype, input_tensor.dtype))
if self.dtype == dtypes.string:
sparse_values = input_tensor.values
else:
sparse_values = string_ops.as_string(input_tensor.values)
sparse_id_values = string_ops.string_to_hash_bucket_fast(
sparse_values, self.hash_bucket_size, name='lookup')
return sparse_tensor_lib.SparseTensor(
input_tensor.indices, sparse_id_values, input_tensor.dense_shape)
示例2: _apply_transform
# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_to_hash_bucket_fast [as 别名]
def _apply_transform(self, input_tensors, **kwargs):
"""Applies the transformation to the `transform_input`.
Args:
input_tensors: a list of Tensors representing the input to
the Transform.
**kwargs: additional keyword arguments, unused here.
Returns:
A namedtuple of Tensors representing the transformed output.
"""
result = string_ops.string_to_hash_bucket_fast(input_tensors[0],
self._num_buckets,
name=None)
# pylint: disable=not-callable
return self.return_type(result)
示例3: _get_string_to_hash_bucket_fn
# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_to_hash_bucket_fast [as 别名]
def _get_string_to_hash_bucket_fn(self, hasher_spec):
"""Returns the string_to_hash_bucket op to use based on `hasher_spec`."""
if not isinstance(hasher_spec, HasherSpec):
raise TypeError("hasher_spec must be of type HasherSpec %s" % hasher_spec)
if hasher_spec.hasher == "fasthash":
return string_ops.string_to_hash_bucket_fast
if hasher_spec.hasher == "legacy":
return string_ops.string_to_hash_bucket
if hasher_spec.hasher == "stronghash":
return functools.partial(
string_ops.string_to_hash_bucket_strong, key=hasher_spec.key)
raise ValueError("Unknown hasher %s" % hasher_spec.hasher)
示例4: _do_transform
# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_to_hash_bucket_fast [as 别名]
def _do_transform(self, input_tensor):
if self.dtype.is_integer:
sparse_values = string_ops.as_string(input_tensor.values)
else:
sparse_values = input_tensor.values
sparse_id_values = string_ops.string_to_hash_bucket_fast(
sparse_values, self.bucket_size, name="lookup")
return sparse_tensor_py.SparseTensor(input_tensor.indices, sparse_id_values,
input_tensor.dense_shape)
示例5: insert_transformed_feature
# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_to_hash_bucket_fast [as 别名]
def insert_transformed_feature(self, columns_to_tensors):
"""Handles sparse column to id conversion."""
input_tensor = self._get_input_sparse_tensor(columns_to_tensors)
if self.dtype.is_integer:
sparse_values = string_ops.as_string(input_tensor.values)
else:
sparse_values = input_tensor.values
sparse_id_values = string_ops.string_to_hash_bucket_fast(
sparse_values, self.bucket_size, name="lookup")
columns_to_tensors[self] = sparse_tensor_py.SparseTensor(
input_tensor.indices, sparse_id_values, input_tensor.dense_shape)
示例6: insert_transformed_feature
# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_to_hash_bucket_fast [as 别名]
def insert_transformed_feature(self, columns_to_tensors):
"""Handles sparse column to id conversion."""
sparse_tensor = columns_to_tensors[self.name]
if self.dtype.is_integer:
sparse_values = string_ops.as_string(sparse_tensor.values)
else:
sparse_values = sparse_tensor.values
sparse_id_values = string_ops.string_to_hash_bucket_fast(
sparse_values, self.bucket_size, name="lookup")
columns_to_tensors[self] = sparse_tensor_py.SparseTensor(
sparse_tensor.indices, sparse_id_values, sparse_tensor.shape)