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


Python bulk_component.BulkFeatureExtractorComponentBuilder方法代码示例

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


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

示例1: testFailsOnNonIdentityTranslator

# 需要导入模块: from dragnn.python import bulk_component [as 别名]
# 或者: from dragnn.python.bulk_component import BulkFeatureExtractorComponentBuilder [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

示例2: testFailsOnRecurrentLinkedFeature

# 需要导入模块: from dragnn.python import bulk_component [as 别名]
# 或者: from dragnn.python.bulk_component import BulkFeatureExtractorComponentBuilder [as 别名]
def testFailsOnRecurrentLinkedFeature(self):
    component_spec = spec_pb2.ComponentSpec()
    text_format.Parse("""
        name: "test"
        network_unit {
          registered_name: "FeedForwardNetwork"
          parameters {
            key: 'hidden_layer_sizes' value: '64'
          }
        }
        linked_feature {
          name: "features" embedding_dim: -1 size: 1
          source_translator: "identity"
          source_component: "test"
          source_layer: "layer_0"
        }
        """, 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(RuntimeError):
        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(RuntimeError):
        comp.build_greedy_training(self.master_state, self.network_states) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:37,代码来源:bulk_component_test.py

示例3: testConstantFixedFeatureFailsIfNotPretrained

# 需要导入模块: from dragnn.python import bulk_component [as 别名]
# 或者: from dragnn.python.bulk_component import BulkFeatureExtractorComponentBuilder [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

示例4: testNormalFixedFeaturesAreDifferentiable

# 需要导入模块: from dragnn.python import bulk_component [as 别名]
# 或者: from dragnn.python.bulk_component import BulkFeatureExtractorComponentBuilder [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

示例5: testFailsOnNonIdentityTranslator

# 需要导入模块: from dragnn.python import bulk_component [as 别名]
# 或者: from dragnn.python.bulk_component import BulkFeatureExtractorComponentBuilder [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:
    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:
    self.setUp()
    comp = bulk_component.BulkAnnotatorComponentBuilder(self.master,
                                                        component_spec)

    with self.assertRaises(NotImplementedError):
      comp.build_greedy_training(self.master_state, self.network_states) 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:32,代码来源:bulk_component_test.py

示例6: testFailsOnRecurrentLinkedFeature

# 需要导入模块: from dragnn.python import bulk_component [as 别名]
# 或者: from dragnn.python.bulk_component import BulkFeatureExtractorComponentBuilder [as 别名]
def testFailsOnRecurrentLinkedFeature(self):
    component_spec = spec_pb2.ComponentSpec()
    text_format.Parse("""
        name: "test"
        network_unit {
          registered_name: "FeedForwardNetwork"
          parameters {
            key: 'hidden_layer_sizes' value: '64'
          }
        }
        linked_feature {
          name: "features" embedding_dim: -1 size: 1
          source_translator: "identity"
          source_component: "test"
          source_layer: "layer_0"
        }
        """, component_spec)

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

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

    # As well as annotation:
    self.setUp()
    comp = bulk_component.BulkAnnotatorComponentBuilder(self.master,
                                                        component_spec)

    with self.assertRaises(RuntimeError):
      comp.build_greedy_training(self.master_state, self.network_states) 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:36,代码来源:bulk_component_test.py


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