feature_column_ops_test.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:lsdc 作者: febert 项目源码 文件源码
def testSparseFeatureColumnWithHashedBucketSize(self):
    movies = tf.contrib.layers.sparse_column_with_hash_bucket(
        column_name="movies", hash_bucket_size=15)
    with tf.Graph().as_default():
      features = {
          "movies": tf.SparseTensor(
              values=["matrix", "head-on", "winter sleep"],
              indices=[[0, 0], [0, 1], [1, 0]],
              shape=[2, 2])
      }
      output, column_to_variable, _ = (
          tf.contrib.layers.weighted_sum_from_feature_columns(features,
                                                              [movies],
                                                              num_outputs=1))
      with self.test_session() as sess:
        tf.global_variables_initializer().run()
        tf.initialize_all_tables().run()

        weights = column_to_variable[movies][0]
        self.assertEqual(weights.get_shape(), (15, 1))
        sess.run(weights.assign(weights + 0.4))
        # score for first example = 0.4 (matrix) + 0.4 (head-on) = 0.8
        # score for second example = 0.4 (winter sleep)
        self.assertAllClose(output.eval(), [[0.8], [0.4]])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号