【问题标题】:How to compute with sparse tensors in TensorFlow?如何在 TensorFlow 中使用稀疏张量进行计算?
【发布时间】:2017-04-29 17:52:33
【问题描述】:

我想以批处理方式从 TensorFlow 中的 DNC 实现中实现这个公式。



使用批量密集张量非常简单。

# w [B, N], p [B, N], L [B, N, N], B=batch_size
dot_prod = tf.batch_matmul(tf.expand_dims(w, axis=2), tf.expand_dims(p, axis=1))
one_prod = 1 - tf.expand_dims(w, 1) - tf.expand_dims(w, 2) 
L =  one_prod * pre_L + dot_prod

有没有办法用稀疏张量来实现这个? w、p 和 L 是稀疏但TensorFlow 缺乏稀疏批处理 matmul 和稀疏索引。

【问题讨论】:

标签: python tensorflow sparse-matrix


【解决方案1】:

尝试转换为密集张量:

tf.sparse_to_dense( sparse_indices, output_shape, sparse_values, default_value=0, validate_indices=True, name=None )

使用示例: mat = tf.sparse_to_dense(inds, [n, class_size], vals)

在此处查看文档:https://www.tensorflow.org/api_docs/python/tf/sparse_to_dense

【讨论】:

    猜你喜欢
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    • 2016-10-19
    • 2012-01-03
    相关资源
    最近更新 更多