簡體   English   中英

什么是 tensorflow 哈希函數?

[英]What are the tensorflow hash functions?

是描述 TensorFlow 的tf.string_to_hash_bucket_fast的頁面。 (版本目前是 1.3。)它說定義這個函數的文件是tensorflow/python/ops/gen_string_ops.py ,它似乎不存在於 github 上。 gen可能意味着它已生成。 好的。

這個函數的可靠定義是什么(也就是說,如果我想在另一個平台上重新實現它)?

基於string_to_hash_bucket_op.cc 中的注冊信息。 我認為tf.string_to_hash_bucket_fast的實現在相應的 .h 文件中的StringToHashBucketOp類中。

是的,一旦您安裝了 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++ 定義。

只是為了建立在所有以前的答案之上:最終你通過以下導入結束這里並包括: https : //github.com/tensorflow/tensorflow/blob/master/tensorflow/core/platform/hash.cc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM