2017-09-22 140 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++定義。