def _encode_view_hierarchy(self, features, object_selector, training):
    'Encodes view hierarchy.'
    logging.info('Using Transformer screen encoder')
    developer_embeddings = self._word_embedding_layer(features['developer_token_id'])
    resource_embeddings = self._word_embedding_layer(features['resource_token_id'])
    developer_embeddings = self._aggregate_text_embedding(features['developer_token_id'], developer_embeddings)
    resource_embeddings = self._aggregate_text_embedding(features['resource_token_id'], resource_embeddings)
    type_embedding = self._type_embedding_layer(tf.maximum(features['obj_type'], 0))
    clickable_embedding = self._clickable_embedding_layer(features['obj_clickable'])
    object_info = []
    if ('text' in self._hparams['screen_embedding_feature']):
        object_info.append(developer_embeddings)
        object_info.append(resource_embeddings)
    if ('type' in self._hparams['screen_embedding_feature']):
        object_info.append(type_embedding)
    if ('pos' in self._hparams['screen_embedding_feature']):
        pos_embedding = self._embed_composite_feature(features['obj_screen_pos'], self._pos_embedding_layers)
        object_info.append(pos_embedding)
    if ('click' in self._hparams['screen_embedding_feature']):
        object_info.append(clickable_embedding)
    if ('dom' in self._hparams['screen_embedding_feature']):
        dom_embedding = self._embed_composite_feature(features['obj_dom_pos'], self._dom_embedding_layers)
        object_info.append(dom_embedding)
    object_embed = tf.concat(object_info, (- 1))
    object_embed = self._vh_final_layer(object_embed)
    object_mask = tf.cast(tf.not_equal(features['obj_type'], (- 1)), tf.float32)
    object_embed = (object_embed * tf.expand_dims(object_mask, (- 1)))
    att_bias = model_utils.get_padding_bias(object_mask)
    if training:
        object_embed = tf.nn.dropout(object_embed, rate=self._hparams['dropout'])
    encoder_output = self._transformer_encoder(object_embed, attention_bias=att_bias, inputs_padding=None, training=training)
    object_embed = tf.reshape(object_embed, [(- 1), self._hparams['hidden_size']])
    encoder_output = tf.reshape(encoder_output, [(- 1), self._hparams['hidden_size']])
    valid_object_embed = tf.gather(object_embed, object_selector)
    valid_screen_encoding = tf.gather(encoder_output, object_selector)
    return (valid_screen_encoding, valid_object_embed)
Encodes view hierarchy.
def _encode_view_hierarchy(self, features, object_selector, training):
    
    logging.info('Using Transformer screen encoder')
    developer_embeddings = self._word_embedding_layer(features['developer_token_id'])
    resource_embeddings = self._word_embedding_layer(features['resource_token_id'])
    developer_embeddings = self._aggregate_text_embedding(features['developer_token_id'], developer_embeddings)
    resource_embeddings = self._aggregate_text_embedding(features['resource_token_id'], resource_embeddings)
    type_embedding = self._type_embedding_layer(tf.maximum(features['obj_type'], 0))
    clickable_embedding = self._clickable_embedding_layer(features['obj_clickable'])
    object_info = []
    if ('text' in self._hparams['screen_embedding_feature']):
        object_info.append(developer_embeddings)
        object_info.append(resource_embeddings)
    if ('type' in self._hparams['screen_embedding_feature']):
        object_info.append(type_embedding)
    if ('pos' in self._hparams['screen_embedding_feature']):
        pos_embedding = self._embed_composite_feature(features['obj_screen_pos'], self._pos_embedding_layers)
        object_info.append(pos_embedding)
    if ('click' in self._hparams['screen_embedding_feature']):
        object_info.append(clickable_embedding)
    if ('dom' in self._hparams['screen_embedding_feature']):
        dom_embedding = self._embed_composite_feature(features['obj_dom_pos'], self._dom_embedding_layers)
        object_info.append(dom_embedding)
    object_embed = tf.concat(object_info, (- 1))
    object_embed = self._vh_final_layer(object_embed)
    object_mask = tf.cast(tf.not_equal(features['obj_type'], (- 1)), tf.float32)
    object_embed = (object_embed * tf.expand_dims(object_mask, (- 1)))
    att_bias = model_utils.get_padding_bias(object_mask)
    if training:
        object_embed = tf.nn.dropout(object_embed, rate=self._hparams['dropout'])
    encoder_output = self._transformer_encoder(object_embed, attention_bias=att_bias, inputs_padding=None, training=training)
    object_embed = tf.reshape(object_embed, [(- 1), self._hparams['hidden_size']])
    encoder_output = tf.reshape(encoder_output, [(- 1), self._hparams['hidden_size']])
    valid_object_embed = tf.gather(object_embed, object_selector)
    valid_screen_encoding = tf.gather(encoder_output, object_selector)
    return (valid_screen_encoding, valid_object_embed)