本文整理汇总了Python中dragnn.python.network_units.GatherNetwork方法的典型用法代码示例。如果您正苦于以下问题:Python network_units.GatherNetwork方法的具体用法?Python network_units.GatherNetwork怎么用?Python network_units.GatherNetwork使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dragnn.python.network_units
的用法示例。
在下文中一共展示了network_units.GatherNetwork方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from dragnn.python import network_units [as 别名]
# 或者: from dragnn.python.network_units import GatherNetwork [as 别名]
def setUp(self):
# Clear the graph and all existing variables. Otherwise, variables created
# in different tests may collide with each other.
tf.reset_default_graph()
self._master = MockMaster()
self._master.spec = spec_pb2.MasterSpec()
text_format.Parse("""
component {
name: 'test'
backend { registered_name: 'TestComponent' }
linked_feature {
name: 'indices'
fml: 'input.focus'
size: 1
embedding_dim: -1
source_component: 'previous'
source_translator: 'identity'
source_layer: 'index_layer'
}
linked_feature {
name: 'features'
fml: 'input.focus'
size: 1
embedding_dim: -1
source_component: 'previous'
source_translator: 'identity'
source_layer: 'feature_layer'
}
network_unit {
registered_name: 'GatherNetwork'
}
}
""", self._master.spec)
self._component = MockComponent(self._master,
self._master.spec.component[0])
self._master.lookup_component['previous'].network = MockNetwork(
index_layer=1, feature_layer=2)
示例2: testConstantPadding
# 需要导入模块: from dragnn.python import network_units [as 别名]
# 或者: from dragnn.python.network_units import GatherNetwork [as 别名]
def testConstantPadding(self):
with tf.Graph().as_default(), self.test_session():
with tf.variable_scope('test_scope'):
network = network_units.GatherNetwork(self._component)
# Construct a batch of two items with 3 and 2 steps, respectively.
indices = tf.constant([[1], [2], [0], # item 1
[-1], [0], [-1]], # item 2
dtype=tf.int64)
features = tf.constant([[1.0, 1.5], [2.0, 2.5], [3.0, 3.5], # item 1
[4.0, 4.5], [5.0, 5.5], [6.0, 6.5]], # item 2
dtype=tf.float32)
fixed_embeddings = []
linked_embeddings = [
network_units.NamedTensor(indices, 'indices', 1),
network_units.NamedTensor(features, 'features', 2)
]
with tf.variable_scope('test_scope', reuse=True):
outputs = network.create(fixed_embeddings, linked_embeddings, None,
None, True, 2)
gathered = outputs[0]
# Zeros will be substituted for index -1.
self.assertAllEqual(gathered.eval(),
[[2.0, 2.5], # gathered from 1
[3.0, 3.5], # gathered from 2
[1.0, 1.5], # gathered from 0
[0.0, 0.0], # gathered from -1
[4.0, 4.5], # gathered from 0
[0.0, 0.0]]) # gathered from -1
示例3: testTrainablePadding
# 需要导入模块: from dragnn.python import network_units [as 别名]
# 或者: from dragnn.python.network_units import GatherNetwork [as 别名]
def testTrainablePadding(self):
self._component.spec.network_unit.parameters['trainable_padding'] = 'true'
with tf.Graph().as_default(), self.test_session():
with tf.variable_scope('test_scope'):
network = network_units.GatherNetwork(self._component)
# Construct a batch of two items with 3 and 2 steps, respectively.
indices = tf.constant([[1], [2], [0], # item 1
[-1], [0], [-1]], # item 2
dtype=tf.int64)
features = tf.constant([[1.0, 1.5], [2.0, 2.5], [3.0, 3.5], # item 1
[4.0, 4.5], [5.0, 5.5], [6.0, 6.5]], # item 2
dtype=tf.float32)
fixed_embeddings = []
linked_embeddings = [
network_units.NamedTensor(indices, 'indices', 1),
network_units.NamedTensor(features, 'features', 2)
]
with tf.variable_scope('test_scope', reuse=True):
outputs = network.create(fixed_embeddings, linked_embeddings, None,
None, True, 2)
gathered = outputs[0]
# Ensure that the padding variable is initialized.
tf.global_variables_initializer().run()
# Randomly-initialized padding will be substituted for index -1.
self.assertAllEqual(gathered[0].eval(), [2.0, 2.5]) # gathered from 1
self.assertAllEqual(gathered[1].eval(), [3.0, 3.5]) # gathered from 2
self.assertAllEqual(gathered[2].eval(), [1.0, 1.5]) # gathered from 0
tf.logging.info('padding = %s', gathered[3].eval()) # gathered from -1
self.assertAllEqual(gathered[4].eval(), [4.0, 4.5]) # gathered from 0
tf.logging.info('padding = %s', gathered[5].eval()) # gathered from -1
# Though random, the padding must identical.
self.assertAllEqual(gathered[3].eval(), gathered[5].eval())
示例4: testConstantPadding
# 需要导入模块: from dragnn.python import network_units [as 别名]
# 或者: from dragnn.python.network_units import GatherNetwork [as 别名]
def testConstantPadding(self):
with tf.Graph().as_default(), self.test_session():
with tf.variable_scope('test_scope'):
network = network_units.GatherNetwork(self._component)
# Construct a batch of two items with 3 and 2 steps, respectively.
indices = tf.constant(
[
# item 1
[1],
[2],
[0],
# item 2
[-1],
[0],
[-1]
],
dtype=tf.int64)
features = tf.constant(
[
# item 1
[1.0, 1.5],
[2.0, 2.5],
[3.0, 3.5],
# item 2
[4.0, 4.5],
[5.0, 5.5],
[6.0, 6.5]
],
dtype=tf.float32)
fixed_embeddings = []
linked_embeddings = [
network_units.NamedTensor(indices, 'indices', 1),
network_units.NamedTensor(features, 'features', 2)
]
with tf.variable_scope('test_scope', reuse=True):
outputs = network.create(fixed_embeddings, linked_embeddings, None,
None, True, 2)
gathered = outputs[0]
# Zeros will be substituted for index -1.
self.assertAllEqual(
gathered.eval(),
[
[2.0, 2.5], # gathered from 1
[3.0, 3.5], # gathered from 2
[1.0, 1.5], # gathered from 0
[0.0, 0.0], # gathered from -1
[4.0, 4.5], # gathered from 0
[0.0, 0.0] # gathered from -1
])
示例5: testTrainablePadding
# 需要导入模块: from dragnn.python import network_units [as 别名]
# 或者: from dragnn.python.network_units import GatherNetwork [as 别名]
def testTrainablePadding(self):
self._component.spec.network_unit.parameters['trainable_padding'] = 'true'
with tf.Graph().as_default(), self.test_session():
with tf.variable_scope('test_scope'):
network = network_units.GatherNetwork(self._component)
# Construct a batch of two items with 3 and 2 steps, respectively.
indices = tf.constant(
[
# item 1
[1],
[2],
[0],
# item 2
[-1],
[0],
[-1]
],
dtype=tf.int64)
features = tf.constant(
[
# item 1
[1.0, 1.5],
[2.0, 2.5],
[3.0, 3.5],
# item 2
[4.0, 4.5],
[5.0, 5.5],
[6.0, 6.5]
],
dtype=tf.float32)
fixed_embeddings = []
linked_embeddings = [
network_units.NamedTensor(indices, 'indices', 1),
network_units.NamedTensor(features, 'features', 2)
]
with tf.variable_scope('test_scope', reuse=True):
outputs = network.create(fixed_embeddings, linked_embeddings, None,
None, True, 2)
gathered = outputs[0]
# Ensure that the padding variable is initialized.
tf.global_variables_initializer().run()
# Randomly-initialized padding will be substituted for index -1.
self.assertAllEqual(gathered[0].eval(), [2.0, 2.5]) # gathered from 1
self.assertAllEqual(gathered[1].eval(), [3.0, 3.5]) # gathered from 2
self.assertAllEqual(gathered[2].eval(), [1.0, 1.5]) # gathered from 0
tf.logging.info('padding = %s', gathered[3].eval()) # gathered from -1
self.assertAllEqual(gathered[4].eval(), [4.0, 4.5]) # gathered from 0
tf.logging.info('padding = %s', gathered[5].eval()) # gathered from -1
# Though random, the padding must identical.
self.assertAllEqual(gathered[3].eval(), gathered[5].eval())