當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。