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