2017-09-22 33 views
1

Here是描述TensorFlow的tf.string_to_hash_bucket_fast的页面。 (版本目前是1.3)。它说定义这个函数的文件是tensorflow/python/ops/gen_string_ops.py,它似乎不存在于github上。 gen可能意味着它已生成。好的。张量散列函数是什么?

这个函数的实体定义是什么(即如果我想在另一个平台上,我可以重新实现它)?

回答

1

是的,安装Tensorflow后会生成该文件,因此您可以在该路径中的机器中找到该文件。对我来说,它是设在这里:

/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_string_ops.py

PS:你可以看到这样的路径,当你遇到错误。

固体的定义是:

def string_to_hash_bucket(string_tensor, num_buckets, name=None): 
    r"""Converts each string in the input Tensor to its hash mod by a number of buckets. 

    The hash function is deterministic on the content of the string within the 
    process. 

    Note that the hash function may change from time to time. 
    This functionality will be deprecated and it's recommended to use 
    `tf.string_to_hash_bucket_fast()` or `tf.string_to_hash_bucket_strong()`. 

    Args: 
    string_tensor: A `Tensor` of type `string`. 
    num_buckets: An `int` that is `>= 1`. The number of buckets. 
    name: A name for the operation (optional). 

    Returns: 
    A `Tensor` of type `int64`. 
    A Tensor of the same shape as the input `string_tensor`. 
    """ 
    result = _op_def_lib.apply_op("StringToHashBucket", 
           string_tensor=string_tensor, 
           num_buckets=num_buckets, name=name) 
    return result 

您可以跟踪你想要什么/usr/local/lib/python2.7/dist-packages/下(这取决于您的设置)。绝对的,Python的定义不是真正的定义,真正的定义是在前面的答案中阐述的C++定义。