本文整理汇总了Python中dragnn.python.spec_builder.ComponentSpecBuilder方法的典型用法代码示例。如果您正苦于以下问题:Python spec_builder.ComponentSpecBuilder方法的具体用法?Python spec_builder.ComponentSpecBuilder怎么用?Python spec_builder.ComponentSpecBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dragnn.python.spec_builder
的用法示例。
在下文中一共展示了spec_builder.ComponentSpecBuilder方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testComponentSpecBuilderLinkedFeature
# 需要导入模块: from dragnn.python import spec_builder [as 别名]
# 或者: from dragnn.python.spec_builder import ComponentSpecBuilder [as 别名]
def testComponentSpecBuilderLinkedFeature(self):
builder1 = spec_builder.ComponentSpecBuilder('test1')
builder1.set_transition_system('shift-only')
builder1.add_fixed_feature(name='words', fml='input.word', embedding_dim=16)
builder2 = spec_builder.ComponentSpecBuilder('test2')
builder2.set_network_unit('IdentityNetwork')
builder2.set_transition_system('tagger')
builder2.add_token_link(
source=builder1,
source_layer='words',
fml='input.focus',
embedding_dim=-1)
self.assertSpecEqual(r"""
name: "test2"
linked_feature { name: "test1" source_component: "test1" source_layer: "words"
source_translator: "identity" fml: "input.focus"
embedding_dim: -1 }
backend { registered_name: "SyntaxNetComponent" }
component_builder { registered_name: "DynamicComponentBuilder" }
network_unit { registered_name: "IdentityNetwork" }
transition_system { registered_name: "tagger" }
""", builder2.spec)
示例2: _make_basic_master_spec
# 需要导入模块: from dragnn.python import spec_builder [as 别名]
# 或者: from dragnn.python.spec_builder import ComponentSpecBuilder [as 别名]
def _make_basic_master_spec():
"""Constructs a simple spec.
Modified version of nlp/saft/opensource/dragnn/tools/parser_trainer.py
Returns:
spec_pb2.MasterSpec instance.
"""
# Construct the "lookahead" ComponentSpec. This is a simple right-to-left RNN
# sequence model, which encodes the context to the right of each token. It has
# no loss except for the downstream components.
lookahead = spec_builder.ComponentSpecBuilder('lookahead')
lookahead.set_network_unit(
name='FeedForwardNetwork', hidden_layer_sizes='256')
lookahead.set_transition_system(name='shift-only', left_to_right='true')
lookahead.add_fixed_feature(name='words', fml='input.word', embedding_dim=64)
lookahead.add_rnn_link(embedding_dim=-1)
# Construct the ComponentSpec for parsing.
parser = spec_builder.ComponentSpecBuilder('parser')
parser.set_network_unit(name='FeedForwardNetwork', hidden_layer_sizes='256')
parser.set_transition_system(name='arc-standard')
parser.add_token_link(source=lookahead, fml='input.focus', embedding_dim=32)
master_spec = spec_pb2.MasterSpec()
master_spec.component.extend([lookahead.spec, parser.spec])
return master_spec
示例3: testComponentSpecBuilderEmpty
# 需要导入模块: from dragnn.python import spec_builder [as 别名]
# 或者: from dragnn.python.spec_builder import ComponentSpecBuilder [as 别名]
def testComponentSpecBuilderEmpty(self):
builder = spec_builder.ComponentSpecBuilder('test')
self.assertSpecEqual(r"""
name: "test"
backend { registered_name: "SyntaxNetComponent" }
component_builder { registered_name: "DynamicComponentBuilder" }
""", builder.spec)
示例4: testComponentSpecBuilderFixedFeature
# 需要导入模块: from dragnn.python import spec_builder [as 别名]
# 或者: from dragnn.python.spec_builder import ComponentSpecBuilder [as 别名]
def testComponentSpecBuilderFixedFeature(self):
builder = spec_builder.ComponentSpecBuilder('test')
builder.set_network_unit('FeedForwardNetwork', hidden_layer_sizes='64,64')
builder.set_transition_system('shift-only')
builder.add_fixed_feature(name='words', fml='input.word', embedding_dim=16)
self.assertSpecEqual(r"""
name: "test"
fixed_feature { name: "words" fml: "input.word" embedding_dim: 16 }
backend { registered_name: "SyntaxNetComponent" }
component_builder { registered_name: "DynamicComponentBuilder" }
network_unit { registered_name: "FeedForwardNetwork"
parameters { key: "hidden_layer_sizes" value: "64,64" } }
transition_system { registered_name: "shift-only" }
""", builder.spec)
示例5: testFillsTaggerTransitions
# 需要导入模块: from dragnn.python import spec_builder [as 别名]
# 或者: from dragnn.python.spec_builder import ComponentSpecBuilder [as 别名]
def testFillsTaggerTransitions(self):
lexicon_dir = tempfile.mkdtemp()
def write_lines(filename, lines):
with open(os.path.join(lexicon_dir, filename), 'w') as f:
f.write(''.join('{}\n'.format(line) for line in lines))
# Label map is required, even though it isn't used
write_lines('label-map', ['0'])
write_lines('word-map', ['2', 'miranda 1', 'rights 1'])
write_lines('tag-map', ['2', 'NN 1', 'NNP 1'])
write_lines('tag-to-category', ['NN\tNOUN', 'NNP\tNOUN'])
tagger = spec_builder.ComponentSpecBuilder('tagger')
tagger.set_network_unit(name='FeedForwardNetwork', hidden_layer_sizes='256')
tagger.set_transition_system(name='tagger')
tagger.add_fixed_feature(name='words', fml='input.word', embedding_dim=64)
tagger.add_rnn_link(embedding_dim=-1)
tagger.fill_from_resources(lexicon_dir)
fixed_feature, = tagger.spec.fixed_feature
linked_feature, = tagger.spec.linked_feature
self.assertEqual(fixed_feature.vocabulary_size, 5)
self.assertEqual(fixed_feature.size, 1)
self.assertEqual(fixed_feature.size, 1)
self.assertEqual(linked_feature.size, 1)
self.assertEqual(tagger.spec.num_actions, 2)
示例6: _make_basic_master_spec
# 需要导入模块: from dragnn.python import spec_builder [as 别名]
# 或者: from dragnn.python.spec_builder import ComponentSpecBuilder [as 别名]
def _make_basic_master_spec():
"""Constructs a simple spec.
Modified version of dragnn/tools/parser_trainer.py
Returns:
spec_pb2.MasterSpec instance.
"""
# Construct the "lookahead" ComponentSpec. This is a simple right-to-left RNN
# sequence model, which encodes the context to the right of each token. It has
# no loss except for the downstream components.
lookahead = spec_builder.ComponentSpecBuilder('lookahead')
lookahead.set_network_unit(
name='FeedForwardNetwork', hidden_layer_sizes='256')
lookahead.set_transition_system(name='shift-only', left_to_right='true')
lookahead.add_fixed_feature(name='words', fml='input.word', embedding_dim=64)
lookahead.add_rnn_link(embedding_dim=-1)
# Construct the ComponentSpec for parsing.
parser = spec_builder.ComponentSpecBuilder('parser')
parser.set_network_unit(name='FeedForwardNetwork', hidden_layer_sizes='256')
parser.set_transition_system(name='arc-standard')
parser.add_token_link(source=lookahead, fml='input.focus', embedding_dim=32)
master_spec = spec_pb2.MasterSpec()
master_spec.component.extend([lookahead.spec, parser.spec])
return master_spec