本文整理汇总了Python中tensorflow.python.ops.sparse_ops.sparse_softmax函数的典型用法代码示例。如果您正苦于以下问题:Python sparse_softmax函数的具体用法?Python sparse_softmax怎么用?Python sparse_softmax使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sparse_softmax函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testHigherRanks
def testHigherRanks(self):
# For the first shape:
# First batch:
# [? e.]
# [1. ? ]
# Second batch:
# [e ? ]
# [e e ]
#
# The softmax results should be:
# [? 1.] [1 ?]
# [1. ? ] and [.5 .5]
# where ? means implicitly zero.
#
# The second shape: same input data, but with a higher-rank shape.
shapes = [[2, 2, 2], [2, 1, 2, 2]]
for shape in shapes:
values = np.asarray(
[0., np.e, 1., 0., np.e, 0., np.e, np.e]).reshape(shape)
sp_t, unused_nnz = _sparsify(values, thresh=1e-2)
expected_values = [1., 1., 1., .5, .5]
with self.test_session(use_gpu=False):
result = sparse_ops.sparse_softmax(sp_t).eval()
self.assertAllEqual(expected_values, result.values)
self.assertAllEqual(sp_t.indices.eval(), result.indices)
self.assertAllEqual(shape, result.shape)
开发者ID:govindap,项目名称:tensorflow,代码行数:28,代码来源:sparse_ops_test.py
示例2: testGradient
def testGradient(self):
x_shape = [2, 5, 10]
with self.test_session(use_gpu=False):
for dtype in [np.float32, np.float64]:
x_np = np.random.randn(*x_shape).astype(dtype)
x_tf, nnz = _sparsify(x_np)
y_tf = sparse_ops.sparse_softmax(x_tf)
err = gradient_checker.compute_gradient_error(x_tf.values, (nnz,),
y_tf.values, (nnz,))
self.assertLess(err, 1e-4)
开发者ID:jon-sch,项目名称:tensorflow,代码行数:10,代码来源:sparse_ops_test.py
示例3: testEquivalentToDensified
def testEquivalentToDensified(self):
np.random.seed(1618)
n, m = np.random.choice(20, size=2)
for dtype in [np.float32, np.float64]:
sp_vals_np = np.random.rand(n, m).astype(dtype)
batched_sp_t, unused_nnz1 = _sparsify(sp_vals_np.reshape((1, n, m)), thresh=0.0) # No masking.
with self.test_session(use_gpu=False):
densified = tf.constant(sp_vals_np)
sp_result = sparse_ops.sparse_softmax(batched_sp_t).eval().values.reshape((n, m))
dense_result = tf.nn.softmax(densified)
self.assertAllClose(dense_result.eval(), sp_result)
开发者ID:tongwang01,项目名称:tensorflow,代码行数:16,代码来源:sparse_ops_test.py
示例4: testEquivalentToDensified
def testEquivalentToDensified(self):
np.random.seed(1618)
n, m = np.random.choice(20, size=2)
for dtype in [np.float32, np.float64]:
sp_vals_np = np.random.rand(n, m).astype(dtype)
batched_sp_t, unused_nnz1 = _sparsify(
sp_vals_np.reshape((1, n, m)), thresh=0.) # No masking.
with test_util.force_cpu():
densified = constant_op.constant(sp_vals_np)
sp_result = self.evaluate(
sparse_ops.sparse_softmax(batched_sp_t)).values.reshape((n, m))
dense_result = nn_ops.softmax(densified)
self.assertAllClose(dense_result, sp_result)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:18,代码来源:sparse_ops_test.py
示例5: call
def call(self, inputs):
return sparse_ops.sparse_softmax(inputs)
开发者ID:keveman,项目名称:tensorflow,代码行数:2,代码来源:base_test.py
注:本文中的tensorflow.python.ops.sparse_ops.sparse_softmax函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论