codecamp

TensorFlow函数:tf.sparse_softmax

tf.sparse_softmax 函数

sparse_softmax(
    sp_input,
    name=None
)

定义在:tensorflow/python/ops/sparse_ops.py.

请参阅指南:稀疏张量>数学运算

将 softmax 应用于批量的 N 维 SparseTensor.

在 tf.sparse_softmax 函数中输入代表一个具有逻辑形状[..., B, C](其中N >= 2)的 N 维 SparseTensor ,并且具有按照规范词典顺序排序的索引.

这个操作相当于将 tf.nn.softmax() 应用于具有形状 [B, C] 的每个最内层逻辑子矩阵,但是有了catch,隐式零元素不参与.具体来说,该算法等同于:

  1. 将 tf.nn.softmax () 应用于每个内层子矩阵的致密视图,其形状为 [B, C],沿着大小为 C 的维度;
  2. 掩盖原始的隐式零元素;
  3. 重新规格化剩余的元素.

因此,SparseTensor 结果具有完全相同的非零指数和形状.

以下是一个示例:

# First batch:
# [?   e.]
# [1.  ? ]
# Second batch:
# [e   ? ]
# [e   e ]
shape = [2, 2, 2]  # 3-D SparseTensor
values = np.asarray([[[0., np.e], [1., 0.]], [[np.e, 0.], [np.e, np.e]]])
indices = np.vstack(np.where(values)).astype(np.int64).T

result = tf.sparse_softmax(tf.SparseTensor(indices, values, shape))
# ...returning a 3-D SparseTensor, equivalent to:
# [?   1.]     [1    ?]
# [1.  ? ] and [.5  .5]
# where ? means implicitly zero

函数参数:

  • sp_input:表示 N 维 SparseTensor,其中 N >= 2.
  • name:操作的可选名称.

函数返回值:

  • output:表示结果的 N 维 SparseTensor.
TensorFlow函数:tf.sparse_slice
TensorFlow函数:tf.sparse_split
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }