本文整理匯總了Python中dragnn.python.network_units.get_attrs_with_defaults方法的典型用法代碼示例。如果您正苦於以下問題:Python network_units.get_attrs_with_defaults方法的具體用法?Python network_units.get_attrs_with_defaults怎麽用?Python network_units.get_attrs_with_defaults使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dragnn.python.network_units
的用法示例。
在下文中一共展示了network_units.get_attrs_with_defaults方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: MakeAttrs
# 需要導入模塊: from dragnn.python import network_units [as 別名]
# 或者: from dragnn.python.network_units import get_attrs_with_defaults [as 別名]
def MakeAttrs(self, defaults, key=None, value=None):
"""Returns attrs based on the |defaults| and one |key|,|value| override."""
spec = spec_pb2.RegisteredModuleSpec()
if key and value:
spec.parameters[key] = value
return network_units.get_attrs_with_defaults(spec.parameters, defaults)
示例2: __init__
# 需要導入模塊: from dragnn.python import network_units [as 別名]
# 或者: from dragnn.python.network_units import get_attrs_with_defaults [as 別名]
def __init__(self, component):
"""Initializes layers.
Args:
component: Parent ComponentBuilderBase object.
"""
layers = [
network_units.Layer(self, 'lengths', -1),
network_units.Layer(self, 'scores', -1),
network_units.Layer(self, 'logits', -1),
network_units.Layer(self, 'arcs', -1),
]
super(MstSolverNetwork, self).__init__(component, init_layers=layers)
self._attrs = network_units.get_attrs_with_defaults(
component.spec.network_unit.parameters,
defaults={
'forest': False,
'loss': 'softmax',
'crf_max_dynamic_range': 20,
})
check.Eq(
len(self._fixed_feature_dims.items()), 0, 'Expected no fixed features')
check.Eq(
len(self._linked_feature_dims.items()), 2,
'Expected two linked features')
check.In('lengths', self._linked_feature_dims,
'Missing required linked feature')
check.In('scores', self._linked_feature_dims,
'Missing required linked feature')
示例3: __init__
# 需要導入模塊: from dragnn.python import network_units [as 別名]
# 或者: from dragnn.python.network_units import get_attrs_with_defaults [as 別名]
def __init__(self, master, component_spec, attr_defaults=None):
"""Initializes the ComponentBuilder from specifications.
Args:
master: dragnn.MasterBuilder object.
component_spec: dragnn.ComponentSpec proto to be built.
attr_defaults: Optional dict of component attribute defaults. If not
provided or if empty, attributes are not extracted.
"""
self.master = master
self.num_actions = component_spec.num_actions
self.name = component_spec.name
self.spec = component_spec
self.moving_average = None
# Determine if this component should apply self-normalization.
self.eligible_for_self_norm = (
not self.master.hyperparams.self_norm_components_filter or self.name in
self.master.hyperparams.self_norm_components_filter.split(','))
# Extract component attributes before make_network(), so the network unit
# can access them.
self._attrs = {}
if attr_defaults:
self._attrs = network_units.get_attrs_with_defaults(
self.spec.component_builder.parameters, attr_defaults)
with tf.variable_scope(self.name):
self.training_beam_size = tf.constant(
self.spec.training_beam_size, name='TrainingBeamSize')
self.inference_beam_size = tf.constant(
self.spec.inference_beam_size, name='InferenceBeamSize')
self.locally_normalize = tf.constant(False, name='LocallyNormalize')
self._step = tf.get_variable(
'step', [], initializer=tf.zeros_initializer(), dtype=tf.int32)
self._total = tf.get_variable(
'total', [], initializer=tf.zeros_initializer(), dtype=tf.int32)
# Construct network variables.
self.network = self.make_network(self.spec.network_unit)
# Construct moving average.
if self.master.hyperparams.use_moving_average:
self.moving_average = tf.train.ExponentialMovingAverage(
decay=self.master.hyperparams.average_weight, num_updates=self._step)
self.avg_ops = [self.moving_average.apply(self.network.params)]
示例4: __init__
# 需要導入模塊: from dragnn.python import network_units [as 別名]
# 或者: from dragnn.python.network_units import get_attrs_with_defaults [as 別名]
def __init__(self, master, component_spec, attr_defaults=None):
"""Initializes the ComponentBuilder from specifications.
Args:
master: dragnn.MasterBuilder object.
component_spec: dragnn.ComponentSpec proto to be built.
attr_defaults: Optional dict of component attribute defaults. If not
provided or if empty, attributes are not extracted.
"""
self.master = master
self.num_actions = component_spec.num_actions
self.name = component_spec.name
self.spec = component_spec
self.moving_average = None
# Determine if this component should apply self-normalization.
self.eligible_for_self_norm = (
not self.master.hyperparams.self_norm_components_filter or self.name in
self.master.hyperparams.self_norm_components_filter.split(','))
# Extract component attributes before make_network(), so the network unit
# can access them.
self._attrs = {}
global_attr_defaults = {
'locally_normalize': False,
'output_as_probabilities': False
}
if attr_defaults:
global_attr_defaults.update(attr_defaults)
self._attrs = network_units.get_attrs_with_defaults(
self.spec.component_builder.parameters, global_attr_defaults)
do_local_norm = self._attrs['locally_normalize']
self._output_as_probabilities = self._attrs['output_as_probabilities']
with tf.variable_scope(self.name):
self.training_beam_size = tf.constant(
self.spec.training_beam_size, name='TrainingBeamSize')
self.inference_beam_size = tf.constant(
self.spec.inference_beam_size, name='InferenceBeamSize')
self.locally_normalize = tf.constant(
do_local_norm, name='LocallyNormalize')
self._step = tf.get_variable(
'step', [], initializer=tf.zeros_initializer(), dtype=tf.int32)
self._total = tf.get_variable(
'total', [], initializer=tf.zeros_initializer(), dtype=tf.int32)
# Construct network variables.
self.network = self.make_network(self.spec.network_unit)
# Construct moving average.
if self.master.hyperparams.use_moving_average:
self.moving_average = tf.train.ExponentialMovingAverage(
decay=self.master.hyperparams.average_weight, num_updates=self._step)
self.avg_ops = [self.moving_average.apply(self.network.params)]
# Used to export the cell; see add_cell_input() and add_cell_output().
self._cell_subgraph_spec = export_pb2.CellSubgraphSpec()