当前位置: 首页>>代码示例>>Python>>正文


Python spec_pb2.ComponentSpec方法代码示例

本文整理汇总了Python中dragnn.protos.spec_pb2.ComponentSpec方法的典型用法代码示例。如果您正苦于以下问题:Python spec_pb2.ComponentSpec方法的具体用法?Python spec_pb2.ComponentSpec怎么用?Python spec_pb2.ComponentSpec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dragnn.protos.spec_pb2的用法示例。


在下文中一共展示了spec_pb2.ComponentSpec方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: default_source_layer

# 需要导入模块: from dragnn.protos import spec_pb2 [as 别名]
# 或者: from dragnn.protos.spec_pb2 import ComponentSpec [as 别名]
def default_source_layer(self):
    """Returns the default source_layer setting for this ComponentSpec.

    Usually links are intended for a specific layer in the network unit.
    For common network units, this returns the hidden layer intended
    to be read by recurrent and cross-component connections.

    Returns:
      String name of default network layer.

    Raises:
      ValueError: if no default is known for the given setup.
    """
    for network, default_layer in [('FeedForwardNetwork', 'layer_0'),
                                   ('LayerNormBasicLSTMNetwork', 'state_h_0'),
                                   ('LSTMNetwork', 'layer_0'),
                                   ('IdentityNetwork', 'input_embeddings')]:
      if self.spec.network_unit.registered_name.endswith(network):
        return default_layer

    raise ValueError('No default source for network unit: %s' %
                     self.spec.network_unit) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:24,代码来源:spec_builder.py

示例2: _component_contents

# 需要导入模块: from dragnn.protos import spec_pb2 [as 别名]
# 或者: from dragnn.protos.spec_pb2 import ComponentSpec [as 别名]
def _component_contents(component):
  """Generates the label on component boxes.

  Args:
    component: spec_pb2.ComponentSpec proto

  Returns:
    String label
  """
  return """<
  <B>{name}</B><BR />
  {transition_name}<BR />
  {network_name}<BR />
  {num_actions_str}<BR />
  hidden: {num_hidden}
  >""".format(
      name=component.name,
      transition_name=component.transition_system.registered_name,
      network_name=component.network_unit.registered_name,
      num_actions_str="{} action{}".format(component.num_actions, "s" if
                                           component.num_actions != 1 else ""),
      num_hidden=component.network_unit.parameters.get("hidden_layer_sizes",
                                                       "not specified")) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:25,代码来源:render_spec_with_graphviz.py

示例3: testFailsOnFixedFeature

# 需要导入模块: from dragnn.protos import spec_pb2 [as 别名]
# 或者: from dragnn.protos.spec_pb2 import ComponentSpec [as 别名]
def testFailsOnFixedFeature(self):
    component_spec = spec_pb2.ComponentSpec()
    text_format.Parse("""
        name: "annotate"
        network_unit {
          registered_name: "IdentityNetwork"
        }
        fixed_feature {
          name: "fixed" embedding_dim: 32 size: 1
        }
        """, component_spec)
    with tf.Graph().as_default():
      comp = bulk_component.BulkAnnotatorComponentBuilder(
          self.master, component_spec)

      # Expect feature extraction to generate a runtime error due to the
      # fixed feature.
      with self.assertRaises(RuntimeError):
        comp.build_greedy_training(self.master_state, self.network_states) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:21,代码来源:bulk_component_test.py

示例4: testBulkFeatureIdExtractorOkWithOneFixedFeature

# 需要导入模块: from dragnn.protos import spec_pb2 [as 别名]
# 或者: from dragnn.protos.spec_pb2 import ComponentSpec [as 别名]
def testBulkFeatureIdExtractorOkWithOneFixedFeature(self):
    component_spec = spec_pb2.ComponentSpec()
    text_format.Parse("""
        name: "test"
        network_unit {
          registered_name: "IdentityNetwork"
        }
        fixed_feature {
          name: "fixed" embedding_dim: -1 size: 1
        }
        """, component_spec)
    with tf.Graph().as_default():
      comp = bulk_component.BulkFeatureIdExtractorComponentBuilder(
          self.master, component_spec)

      # Should not raise errors.
      self.network_states[component_spec.name] = component.NetworkState()
      comp.build_greedy_training(self.master_state, self.network_states)
      self.network_states[component_spec.name] = component.NetworkState()
      comp.build_greedy_inference(self.master_state, self.network_states) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:22,代码来源:bulk_component_test.py

示例5: __init__

# 需要导入模块: from dragnn.protos import spec_pb2 [as 别名]
# 或者: from dragnn.protos.spec_pb2 import ComponentSpec [as 别名]
def __init__(self):
    self.spec = spec_pb2.MasterSpec()
    self.hyperparams = spec_pb2.GridPoint()
    self.lookup_component = {
        'previous': MockComponent(self, spec_pb2.ComponentSpec())
    } 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:8,代码来源:network_units_test.py

示例6: __init__

# 需要导入模块: from dragnn.protos import spec_pb2 [as 别名]
# 或者: from dragnn.protos.spec_pb2 import ComponentSpec [as 别名]
def __init__(self,
               name,
               builder='DynamicComponentBuilder',
               backend='SyntaxNetComponent'):
    """Initializes the ComponentSpec with some defaults for SyntaxNet.

    Args:
      name: The name of this Component in the pipeline.
      builder: The component builder type.
      backend: The component backend type.
    """
    self.spec = spec_pb2.ComponentSpec(
        name=name,
        backend=self.make_module(backend),
        component_builder=self.make_module(builder)) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:17,代码来源:spec_builder.py

示例7: testFailsOnNonIdentityTranslator

# 需要导入模块: from dragnn.protos import spec_pb2 [as 别名]
# 或者: from dragnn.protos.spec_pb2 import ComponentSpec [as 别名]
def testFailsOnNonIdentityTranslator(self):
    component_spec = spec_pb2.ComponentSpec()
    text_format.Parse("""
        name: "test"
        network_unit {
          registered_name: "IdentityNetwork"
        }
        linked_feature {
          name: "features" embedding_dim: -1 size: 1
          source_translator: "history"
          source_component: "mock"
        }
        """, component_spec)

    # For feature extraction:
    with tf.Graph().as_default():
      comp = bulk_component.BulkFeatureExtractorComponentBuilder(
          self.master, component_spec)

      # Expect feature extraction to generate a error due to the "history"
      # translator.
      with self.assertRaises(NotImplementedError):
        comp.build_greedy_training(self.master_state, self.network_states)

    # As well as annotation:
    with tf.Graph().as_default():
      comp = bulk_component.BulkAnnotatorComponentBuilder(
          self.master, component_spec)

      with self.assertRaises(NotImplementedError):
        comp.build_greedy_training(self.master_state, self.network_states) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:33,代码来源:bulk_component_test.py

示例8: testConstantFixedFeatureFailsIfNotPretrained

# 需要导入模块: from dragnn.protos import spec_pb2 [as 别名]
# 或者: from dragnn.protos.spec_pb2 import ComponentSpec [as 别名]
def testConstantFixedFeatureFailsIfNotPretrained(self):
    component_spec = spec_pb2.ComponentSpec()
    text_format.Parse("""
        name: "test"
        network_unit {
          registered_name: "IdentityNetwork"
        }
        fixed_feature {
          name: "fixed" embedding_dim: 32 size: 1
          is_constant: true
        }
        component_builder {
          registered_name: "bulk_component.BulkFeatureExtractorComponentBuilder"
        }
        """, component_spec)
    with tf.Graph().as_default():
      comp = bulk_component.BulkFeatureExtractorComponentBuilder(
          self.master, component_spec)

      with self.assertRaisesRegexp(ValueError,
                                   'Constant embeddings must be pretrained'):
        comp.build_greedy_training(self.master_state, self.network_states)
      with self.assertRaisesRegexp(ValueError,
                                   'Constant embeddings must be pretrained'):
        comp.build_greedy_inference(
            self.master_state, self.network_states, during_training=True)
      with self.assertRaisesRegexp(ValueError,
                                   'Constant embeddings must be pretrained'):
        comp.build_greedy_inference(
            self.master_state, self.network_states, during_training=False) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:32,代码来源:bulk_component_test.py

示例9: testNormalFixedFeaturesAreDifferentiable

# 需要导入模块: from dragnn.protos import spec_pb2 [as 别名]
# 或者: from dragnn.protos.spec_pb2 import ComponentSpec [as 别名]
def testNormalFixedFeaturesAreDifferentiable(self):
    component_spec = spec_pb2.ComponentSpec()
    text_format.Parse("""
        name: "test"
        network_unit {
          registered_name: "IdentityNetwork"
        }
        fixed_feature {
          name: "fixed" embedding_dim: 32 size: 1
          pretrained_embedding_matrix { part {} }
          vocab { part {} }
        }
        component_builder {
          registered_name: "bulk_component.BulkFeatureExtractorComponentBuilder"
        }
        """, component_spec)
    with tf.Graph().as_default():
      comp = bulk_component.BulkFeatureExtractorComponentBuilder(
          self.master, component_spec)

      # Get embedding matrix variables.
      with tf.variable_scope(comp.name, reuse=True):
        fixed_embedding_matrix = tf.get_variable(
            network_units.fixed_embeddings_name(0))

      # Get output layer.
      comp.build_greedy_training(self.master_state, self.network_states)
      activations = self.network_states[comp.name].activations
      outputs = activations[comp.network.layers[0].name].bulk_tensor

      # Compute the gradient of the output layer w.r.t. the embedding matrix.
      # This should be well-defined for in the normal case.
      gradients = tf.gradients(outputs, fixed_embedding_matrix)
      self.assertEqual(len(gradients), 1)
      self.assertFalse(gradients[0] is None) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:37,代码来源:bulk_component_test.py

示例10: testBulkFeatureIdExtractorOkWithMultipleFixedFeatures

# 需要导入模块: from dragnn.protos import spec_pb2 [as 别名]
# 或者: from dragnn.protos.spec_pb2 import ComponentSpec [as 别名]
def testBulkFeatureIdExtractorOkWithMultipleFixedFeatures(self):
    component_spec = spec_pb2.ComponentSpec()
    text_format.Parse("""
        name: "test"
        network_unit {
          registered_name: "IdentityNetwork"
        }
        fixed_feature {
          name: "fixed1" embedding_dim: -1 size: 1
        }
        fixed_feature {
          name: "fixed2" embedding_dim: -1 size: 1
        }
        fixed_feature {
          name: "fixed3" embedding_dim: -1 size: 1
        }
        """, component_spec)
    with tf.Graph().as_default():
      comp = bulk_component.BulkFeatureIdExtractorComponentBuilder(
          self.master, component_spec)

      # Should not raise errors.
      self.network_states[component_spec.name] = component.NetworkState()
      comp.build_greedy_training(self.master_state, self.network_states)
      self.network_states[component_spec.name] = component.NetworkState()
      comp.build_greedy_inference(self.master_state, self.network_states) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:28,代码来源:bulk_component_test.py


注:本文中的dragnn.protos.spec_pb2.ComponentSpec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。