2017-07-20 5 views
0

私はスパース列でDNNclassifierを作成しています。トレーニングデータは次のようになり、何がTensorFlowのhash_bucket_sizeに関係するのですか

samples  col1       col2   price label 
    eg1 [[0,1,0,0,0,2,0,1,0,3,...] [[0,0,4,5,0,...] 5.2 0 
    eg2 [0,0,...]      [0,0,...]   0  1 
    eg3 [0,0,...]]     [0,0,...]   0  1 

は、次のスニペットは、成功し

import tensorflow as tf 

sparse_feature_a = tf.contrib.layers.sparse_column_with_hash_bucket('col1', 3, dtype=tf.int32) 
sparse_feature_b = tf.contrib.layers.sparse_column_with_hash_bucket('col2', 1000, dtype=tf.int32) 

sparse_feature_a_emb = tf.contrib.layers.embedding_column(sparse_id_column=sparse_feature_a, dimension=2) 
sparse_feature_b_emb = tf.contrib.layers.embedding_column(sparse_id_column=sparse_feature_b, dimension=2) 
feature_c = tf.contrib.layers.real_valued_column('price') 

estimator = tf.contrib.learn.DNNClassifier(
    feature_columns=[sparse_feature_a_emb, sparse_feature_b_emb, feature_c], 
    hidden_units=[5, 3], 
    n_classes=2, 
    model_dir='./tfTmp/tfTmp0') 

# Input builders 
def input_fn_train(): # returns x, y (where y represents label's class index). 
    features = {'col1': tf.SparseTensor(indices=[[0, 1], [0, 5], [0, 7], [0, 9]], 
            values=[1, 2, 1, 3], 
            dense_shape=[3, int(250e6)]), 
       'col2': tf.SparseTensor(indices=[[0, 2], [0, 3]], 
            values=[4, 5], 
            dense_shape=[3, int(100e6)]), 
         'price': tf.constant([5.2, 0, 0])} 
    labels = tf.constant([0, 1, 1]) 
    return features, labels 

estimator.fit(input_fn=input_fn_train, steps=100) 

を実行することができますしかし、私は3がhash_bucket_sizeを意味

sparse_feature_a = tf.contrib.layers.sparse_column_with_hash_bucket('col1', 3, dtype=tf.int32) 

、この文から疑問を持っています= 3ですが、このスパーステンソルは4つの非ゼロ値を含み、

has_bucket_sizeここには何もありません。スパーステンソルでは、ゼロ以外の値がいくつあっても、整数> 1で設定するだけで正常に動作します。

私の理解は正しいとは限りません。誰でもどのように説明することができますhas_bucket_size作品?どうもありがとう!

答えて

1

hash_bucket_sizeは、元のインデックスを取得し、指定されたサイズのスペースにハッシュし、ハッシュされたインデックスをフィーチャとして使用します。

これは、可能なインデックスの全範囲を知る前にモデルを指定することができることを意味し、インデックスの一部が衝突する可能性があります。

+0

ありがとうございます!今私は、実際のデータの全範囲を網羅している数字を推測できれば完璧だと思います。予想よりも小さい数字を推測すると、それも機能しますが、不確実な動作を引き起こす可能性があります。 –

関連する問題