本文整理汇总了Python中dragnn.python.digraph_ops.LabelPotentialsFromTokens方法的典型用法代码示例。如果您正苦于以下问题:Python digraph_ops.LabelPotentialsFromTokens方法的具体用法?Python digraph_ops.LabelPotentialsFromTokens怎么用?Python digraph_ops.LabelPotentialsFromTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dragnn.python.digraph_ops
的用法示例。
在下文中一共展示了digraph_ops.LabelPotentialsFromTokens方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testLabelPotentialsFromTokens
# 需要导入模块: from dragnn.python import digraph_ops [as 别名]
# 或者: from dragnn.python.digraph_ops import LabelPotentialsFromTokens [as 别名]
def testLabelPotentialsFromTokens(self):
with self.test_session():
tokens = tf.constant([[[1, 2],
[3, 4],
[5, 6]],
[[6, 5],
[4, 3],
[2, 1]]], tf.float32)
weights = tf.constant([[ 2, 3],
[ 5, 7],
[11, 13]], tf.float32)
labels = digraph_ops.LabelPotentialsFromTokens(tokens, weights)
self.assertAllEqual(labels.eval(),
[[[ 8, 19, 37],
[ 18, 43, 85],
[ 28, 67, 133]],
[[ 27, 65, 131],
[ 17, 41, 83],
[ 7, 17, 35]]])
示例2: testLabelPotentialsFromTokens
# 需要导入模块: from dragnn.python import digraph_ops [as 别名]
# 或者: from dragnn.python.digraph_ops import LabelPotentialsFromTokens [as 别名]
def testLabelPotentialsFromTokens(self):
with self.test_session():
tokens = tf.constant([[[1, 2],
[3, 4],
[5, 6]],
[[6, 5],
[4, 3],
[2, 1]]], tf.float32) # pyformat: disable
weights = tf.constant([[ 2, 3],
[ 5, 7],
[11, 13]], tf.float32) # pyformat: disable
labels = digraph_ops.LabelPotentialsFromTokens(tokens, weights)
self.assertAllEqual(labels.eval(),
[[[ 8, 19, 37],
[ 18, 43, 85],
[ 28, 67, 133]],
[[ 27, 65, 131],
[ 17, 41, 83],
[ 7, 17, 35]]]) # pyformat: disable
示例3: create
# 需要导入模块: from dragnn.python import digraph_ops [as 别名]
# 或者: from dragnn.python.digraph_ops import LabelPotentialsFromTokens [as 别名]
def create(self,
fixed_embeddings,
linked_embeddings,
context_tensor_arrays,
attention_tensor,
during_training,
stride=None):
"""Requires |stride|; otherwise see base class."""
check.NotNone(stride,
'BiaffineLabelNetwork requires "stride" and must be called '
'in the bulk feature extractor component.')
# TODO(googleuser): Add dropout during training.
del during_training
# Retrieve (possibly averaged) weights.
weights_pair = self._component.get_variable('weights_pair')
weights_source = self._component.get_variable('weights_source')
weights_target = self._component.get_variable('weights_target')
biases = self._component.get_variable('biases')
# Extract and shape the source and target token activations. Use |stride|
# to collapse batch and beam into a single dimension.
sources = network_units.lookup_named_tensor('sources', linked_embeddings)
targets = network_units.lookup_named_tensor('targets', linked_embeddings)
sources_bxnxs = tf.reshape(sources.tensor, [stride, -1, self._source_dim])
targets_bxnxt = tf.reshape(targets.tensor, [stride, -1, self._target_dim])
# Compute the pair, source, and target potentials.
pairs_bxnxl = digraph_ops.LabelPotentialsFromTokenPairs(sources_bxnxs,
targets_bxnxt,
weights_pair)
sources_bxnxl = digraph_ops.LabelPotentialsFromTokens(sources_bxnxs,
weights_source)
targets_bxnxl = digraph_ops.LabelPotentialsFromTokens(targets_bxnxt,
weights_target)
# Combine them with the biases.
labels_bxnxl = pairs_bxnxl + sources_bxnxl + targets_bxnxl + biases
# Flatten out the batch dimension.
return [tf.reshape(labels_bxnxl, [-1, self._num_labels])]