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


Python dragnn_ops.extract_fixed_features方法代码示例

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


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

示例1: fixed_feature_lookup

# 需要导入模块: from dragnn.python import dragnn_ops [as 别名]
# 或者: from dragnn.python.dragnn_ops import extract_fixed_features [as 别名]
def fixed_feature_lookup(component, state, channel_id, stride):
  """Looks up fixed features and passes them through embeddings.

  Embedding vectors may be scaled by weights if the features specify it.

  Args:
    component: Component object in which to look up the fixed features.
    state: MasterState object for the live nlp_saft::dragnn::MasterState.
    channel_id: int id of the fixed feature to look up.
    stride: int Tensor of current batch * beam size.

  Returns:
    NamedTensor object containing the embedding vectors.
  """
  feature_spec = component.spec.fixed_feature[channel_id]
  check.Gt(feature_spec.embedding_dim, 0,
           'Embeddings requested for non-embedded feature: %s' % feature_spec)
  embedding_matrix = component.get_variable(fixed_embeddings_name(channel_id))

  with tf.op_scope([embedding_matrix], 'fixed_embedding_' + feature_spec.name):
    indices, ids, weights = dragnn_ops.extract_fixed_features(
        state.handle, component=component.name, channel_id=channel_id)
    size = stride * feature_spec.size
    embeddings = embedding_lookup(embedding_matrix, indices, ids, weights, size)
    dim = feature_spec.size * feature_spec.embedding_dim
    return NamedTensor(
        tf.reshape(embeddings, [-1, dim]), feature_spec.name, dim=dim) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:29,代码来源:network_units.py

示例2: fixed_feature_lookup

# 需要导入模块: from dragnn.python import dragnn_ops [as 别名]
# 或者: from dragnn.python.dragnn_ops import extract_fixed_features [as 别名]
def fixed_feature_lookup(component, state, channel_id, stride):
  """Looks up fixed features and passes them through embeddings.

  Embedding vectors may be scaled by weights if the features specify it.

  Args:
    component: Component object in which to look up the fixed features.
    state: MasterState object for the live ComputeSession.
    channel_id: int id of the fixed feature to look up.
    stride: int Tensor of current batch * beam size.

  Returns:
    NamedTensor object containing the embedding vectors.
  """
  feature_spec = component.spec.fixed_feature[channel_id]
  check.Gt(feature_spec.embedding_dim, 0,
           'Embeddings requested for non-embedded feature: %s' % feature_spec)
  embedding_matrix = component.get_variable(fixed_embeddings_name(channel_id))

  with tf.op_scope([embedding_matrix], 'fixed_embedding_' + feature_spec.name):
    indices, ids, weights = dragnn_ops.extract_fixed_features(
        state.handle, component=component.name, channel_id=channel_id)
    size = stride * feature_spec.size
    embeddings = embedding_lookup(embedding_matrix, indices, ids, weights, size)
    dim = feature_spec.size * feature_spec.embedding_dim
    return NamedTensor(
        tf.reshape(embeddings, [-1, dim]), feature_spec.name, dim=dim) 
开发者ID:rky0930,项目名称:yolo_v2,代码行数:29,代码来源:network_units.py

示例3: fixed_feature_lookup

# 需要导入模块: from dragnn.python import dragnn_ops [as 别名]
# 或者: from dragnn.python.dragnn_ops import extract_fixed_features [as 别名]
def fixed_feature_lookup(component, state, channel_id, stride, during_training):
  """Looks up fixed features and passes them through embeddings.

  Embedding vectors may be scaled by weights if the features specify it.

  Args:
    component: Component object in which to look up the fixed features.
    state: MasterState object for the live ComputeSession.
    channel_id: int id of the fixed feature to look up.
    stride: int Tensor of current batch * beam size.
    during_training: True if this is being called from a training code path.
      This controls, e.g., the use of feature ID dropout.

  Returns:
    NamedTensor object containing the embedding vectors.
  """
  feature_spec = component.spec.fixed_feature[channel_id]
  check.Gt(feature_spec.embedding_dim, 0,
           'Embeddings requested for non-embedded feature: %s' % feature_spec)
  if feature_spec.is_constant:
    embedding_matrix = tf.get_variable(fixed_embeddings_name(channel_id))
  else:
    embedding_matrix = component.get_variable(fixed_embeddings_name(channel_id))

  with tf.op_scope([embedding_matrix], 'fixed_embedding_' + feature_spec.name):
    indices, ids, weights = dragnn_ops.extract_fixed_features(
        state.handle, component=component.name, channel_id=channel_id)

    if during_training and feature_spec.dropout_id >= 0:
      ids, weights = apply_feature_id_dropout(ids, weights, feature_spec)

    if component.master.build_runtime_graph:
      # To simplify integration with NN compilers, assume that each feature in
      # the channel extracts exactly one ID and no weights.
      # TODO(googleuser): Relax this restriction?
      embeddings = []
      for index in range(feature_spec.size):

        feature_id = component.add_cell_input(
            tf.int32, [1], 'fixed_channel_{}_index_{}_ids'.format(
                channel_id, index))
        embeddings.append(tf.gather(embedding_matrix, feature_id))
      embeddings = tf.concat(embeddings, 1)
    else:
      size = stride * feature_spec.size
      embeddings = embedding_lookup(embedding_matrix, indices, ids, weights,
                                    size)

    dim = feature_spec.size * feature_spec.embedding_dim
    return NamedTensor(
        tf.reshape(embeddings, [-1, dim]), feature_spec.name, dim=dim) 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:53,代码来源:network_units.py


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