{'fraction_non_alphanumeric': 0.0299149921048647, 'fraction_numerical': 0.009171335251238347, 'mean_word_length': 4.8811855997964635, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Personalizing Search Results Using Hierarchical RNN with Query-aware Attention

Search results personalization has become an effective way to improve the quality of search engines. Previous studies extracted information such as past clicks, user topical interests, query click entropy and so on to tailor the original ranking. However, few studies have taken into account the sequential information underlying previous queries and sessions. Intuitively, the order of issued queries is important in inferring the real user interests. And more recent sessions should provide more reliable personal signals than older sessions. In addition, the previous search history and user behaviors should influence the personalization of the current query depending on their relatedness. To implement these intuitions, in this paper we employ a hierarchical recurrent neural network to exploit such sequential information and automatically generate user profile from historical data. We propose a query-aware attention model to generate a dynamic user profile based on the input query. Significant improvement is observed in the experiment with data from a commercial search engine when compared with several traditional personalization models. Our analysis reveals that the attention model is able to attribute higher weights to more related past sessions after fine training.

case that users issue the same query to express different search intents. Therefore, returning the same results to all users is not the best strategy for a search engine. Personalization potentially solves this problem: by appropriately modeling user interest profiles, personalized search is able to alleviate the ambiguity problem by providing more precise results to individual users.
Personalizing search results to particular users based on their profiles has been a hot field in both academia [4,6,32,37] and industry [15] for a long time. Among these studies, many personalization methods utilized click-through data to generate user profiles, since large-scale query logs contain strong indications on users' preferences and are also relatively cheap to acquire when compared with manual labels [4,19,32,35,41]. These studies demonstrated that through mining personalized signals from query logs, a search engine can re-rank search results and obtain more relevant rankings for individual users. In this paper, we focus on exploiting information from the sequences of past queries and sessions and build a dynamic user profile based on input query.
Previous studies have revealed that diverse features, such as click counts, user topical interests, click entropy and so on, could be extracted from user query logs to help personalize search results. [4,11,16,33,40]. However, few studies have leveraged sequential information hidden in past queries and sessions. Intuitively, a more recent query or session should contribute more than an older one to the current search. For example, a user may have searched for "cherry blossom Japan", "cherry jam" and so on, but is now interested in mechanical keyboard and intends to obtain some introductions. His query "cherry reviews" should be more related to the keyboard brand rather than the fruit or the flower. Previous studies attempted to simply apply an exponential decay to distinguish the recent and old search behaviors [41,43]. No significant difference was observed when using such temporal weightings [4]. However, the influence of a previous query depends on more complex factors than merely the time. A highly related previous query may continue to have a strong influence on the interpretation of the current query in the same session even after a long time span. In this paper, we will use a deep learning framework to account for such factors in the sequential influence patterns.
When building the user profile, another natural intuition is that previous queries and sessions are not always useful [40]. For example, the profile constructed for previous query "peanut allergy symptoms" is probably useless when the user is searching for "JAVA book". In contrast, if the user once searched "JAVA runtime environment", then we can infer that the book is about "JAVA programming" instead of "JAVA Island". Based on such observations, we also devise a query-aware attention mechanism to learn different weights for previous sessions corresponding to the input query. By doing so, we are able to build a dynamic user profile which attends to the previous sessions that are more important to the current query.
User preference evolves over time, and some previous studies attempted to capture this variation by distinguishing short-and long-term user preferences [4,21,43]. A short-term user profile is built from recent interactions within the same search session and is useful to predict the following intents in the current search task [43,44]. A long-term user profile describes more long-standing user characteristics and is less sparse than a short-term profile [23], and it is built from previous sessions. Motivated by the hierarchical structures contained in the click-through data, we propose to use hierarchical recurrent neural network as our fundamental framework to model a longer dependency in the sequential data.
More specifically, a short-term user profile is constructed from the user behaviors in the same session to reflect the current search interest. This is implemented by a RNN at low-level. In addition, the long-term user profiles are built from the past sessions, which are designed to reflect the user's long-term interests. This is created using a higher-level RNN in our model. In order to use the longterm user profiles, we attribute weights to each long-term interest profile using an attention model based on the current query. Then the linear combination of all hidden state vectors is produced as a more precise long-term interest vector. Finally, we compute the similarity score between interest vectors and documents as our personalized scores to tailor the original ranking. The whole framework is trained through a learning-to-rank approach, LambdaRank algorithm [5]. Taking advantage of the two interest vectors, we can further enhance search results personalization.
In sum, our main contributions are twofold: First, we account for the sequential information contained in click-through data and generate a better user profile through a hierarchical recurrent neural network; second, we apply attention mechanism to scrutinize all previous sessions and highlight the more important sessions dynamically according to present information need.
The rest of paper is organized as follows. Section 2 summarizes previous studies that are related to our paper. The proposed framework to mine sequential information from query log is described in Section 3. We discuss experimental setups in Section 4, and analyze the results in Section 5. We conclude the work in Section 6.

RELATED WORK
The related work to this paper principally concerns three fields: (1) Search Results Personalization, (2) Deep Learning in Information Retrieval and (3) The Applications of Hierarchical Recurrent Neural Network.
Search Results Personalization. Users' past search interactions with search engine have been revealed beneficial to web search [6]. However, the improvement of ranking quality personalization brings to users mostly depends on the richness of user profiles. Among all intriguing research on personalizing search results, great majority focused on building user profile based on click-through data, since it is both accessible and informative. The personalized features are extracted from click-through data and can be simply categorized into two groups: click features and topical features.
Users often use search engine to navigate for the same document which was satisfactory under the previously issued queries, and this fact can be used as a safe and low-risk approach in personalization. Teevan et al. [37] have demonstrated that there is a rich opportunity to personalize search results through recognizing personal navigations. Many subsequent studies [4,22,38,45] regarded click-based features as their basic features and investigated more from other angles. It is widely known that personalization sometimes plays against the goal of improving results. Therefore, click entropy is often considered to ensure the expected utility of personalization on certain queries [11,36]. More studies were focused on building an appropriate latent topical user profiles. Early studies [3,31,45] attempted to build user profiles with topics of clicked documents which are learned from a manual on-line ontology, such as the Open Directory Project (ODP) 1 . The potential problem of this approach is that some classes of documents may not appear in the on-line ontology, which could limit its application to dealing with new documents [7,16]. Recent studies applied a latent topic model to determining these topics [7,16,39,41]. Besides, topic entropy is also proposed to measure the topical ambiguity of different queries [33]. Li et al. [22] utilized semantic features produced by a deep learning model as semantic features to improve in-session contextual ranking. In addition to extracting features from query logs, other information can be utilized to improve search results as well. Bennett et al. [2] incorporated user location-based features into personalization model. Collins-Thompson et al. [9] studied and evaluated personalization by different reading levels. Different from the previous studies which simply aggregate the historical user behaviors as user profiles, our intuition is that the past behaviors should be differently conducive to current search according to, for example, the time span and the current information need.
Strategies to implement personalization also varied considerably from model to model. Wang et al. [42] and Song et al. [32] investigated adapting a generic ranking model for personalized search through updating parameters for individual users. The model proposed by Matthijs et al. [23] built user profiles with terms extracted from browsing history, and personalized the rankings with the matching between search snippets and these terms. As for the models focusing on topical user profile with Latent Dirichlet Allocation (LDA) [7,16,39,41], the authors directly calculated the similarity between each document and established user profile, and used the similarities as personalized scores to re-rank the results. Another common approach is to train a ranking model using the Lamb-daMART [46] learning algorithm as in [4,38,45]. LambdaMART is evolved from LambdaRank [5] and can distinguish the importance of features automatically based on boosted regression tree. Different from aforementioned approaches, we employ a deep learning framework to personalize search results. Instead of highly depending on the manual features, the framework does not need specific preparation and only takes raw queries and documents with one hot representation of words as inputs.
Deep Learning in Information Retrieval. Deep learning has been introduced in many information retrieval tasks because of its several advantages, such as the ability to learn word embeddings automatically and to train end-to-end [24,25]. Ad-hoc rankings have benefited enormously from deep learning methods and great results have been achieved. DSSM [18] and CDSSM [30] embedded the query-document pair into a semantic space and ranked the results by the similarity between the embeddings of documents and queries. Severyn and Moschitti [29] also used a convolutional deep neural network to represent query-document pair and computed their semantic similarity. The model developed by Palangi et al. [26] shared a similar idea but addressed the embeddings of queries and documents using Long Short-Term Memory (LSTM) [17]. More recently, some elaborate models like DRMM [14] and K-NRM [47] were proposed to model word-level similarities and achieved even better results. But little has been studied on applying deep learning to search results personalization. Song et al. [32] adapted a global ranking model with continue-train for each individual user to personalize the results. Li et al. [22] improved in-session contextual results by involving semantic features generated by deep learning models. Different from these studies which incorporate deep learning only as a component, we intend to train a complete deep learning framework to personalize the search results.
The Applications of Hierarchical Recurrent Neural Network. The hierarchical recurrent neural network (HRNN) was firstly proposed by El Hidi and Bengio [12] aiming at modeling longer dependence in the sequential data. Since then people gradually realized that many real tasks contain hierarchically sequential dependencies, and HRNN attracts increasing attention from various communities. Quadrana et al. [27] employed HRNN to deal with cross-and insession commodity information in a session-based recommendation. Besides, hierarchical recurrent encoder-decoder was designed to handle text generation, such as building dialogue system [28] and query suggestions [34]. In addition to basic hierarchical recurrent neural network, in this paper we also employ an attention model to generate dynamic user profile based on current query.

PERSONALIZATION FRAMEWORK
The one-size-fits-all retrieval models are known to be suboptimal and can be potentially improved with search results personalization. Through re-ranking the unpersonalized results for different users according to their interests, search engines can provide better search experiences to individual users. In this paper, we focus on mining sequential information and building dynamic user profiles using users' past interactions. Specifically, we employ a framework based on hierarchical recurrent neural network with query-aware attention to learn short-and long-term user profiling automatically. The short-term interest is collected from current session, and the long-term interest describes the preferences inferred by other sessions before the current session.
To start with, we formulate our problem as follows. Suppose that for each user u, there is a query log L u which includes past sessions where score(d i |q M,n M ) represents the relevance between document and query, score(d i |L u ) and score(d i |S M ) correspond to the relevance with regard to long-and short-term user interests respectively. Finally, we re-rank the document list D according to the overall score score(d i ), to produce a personalized ranking list.
As shown in Figure 1, we devise a deep learning framework based on HRNN to calculate the above personalized scores using query logs and to predict the optimal document ranking list. We elaborate our model based on three main components as follows: (1) Exploiting sequence-enhanced user interests, (2) Modeling dynamic user profiles and (3) Re-ranking.

Exploiting Sequence-enhanced User Interests
As we stated in Section 1, traditional methods for building topical user profiles have several potential problems. Most of them ignored the sequential information contained in historical user behaviors. Inspired by the ability of RNN to model sequential data and the hierarchical structure of query logs, we propose to use a Hierarchical RNN to model user interests with click-through data. Recurrent neural network has been widely used in natural language processing because of its ability to model the sequences of words and sentences. After inputs at each time point, the RNN cell is able to determine what information will be kept and passed to next state, and what to discard. More sophisticated RNN cells such as Gated Recurrent Unit (GRU) [8] and Long Short-Term Memory (LSTM) [17] were proposed to solve vanishing gradient problems and learn a long-term dependency. Specifically, we employ GRU as a basic RNN cell in our model, since it has a relatively simpler structure which is easier to train. The reasons we devise a twolevel structure include: (1) The click-through data is intrinsically hierarchical with intra-session interactions conveying short-term interest and inter-session interactions reflecting long-term preference; (2) To enhance the ability of our framework to model longer dependency, specifically to learn longer user interests.

Modeling short-term user interests.
Within a session S m , a user issues a series of queries. Sometimes this user issues a query at first and reformulates it in the following queries. During this procedure, the user probably clicks on certain documents and may be satisfied by their content. Intuitively, both the satisfactory documents and the order of these queries are highly informative to inferring the real intent and should be utilized while tailoring the ranking of the result lists.
In our model, the inputs to the low-level RNN is extracted from a subset of the session S   representations are calculated as the weighted average of the word representations w ∈ R d e multiplied by TF-IDF weights, while the words are represented by distributional vectors looked up in an embeddings matrix W ∈ R |V |×d e . This part could be replaced by a more complex model such as Doc2Vec, CNN, or RNN model, which also involves more parameters and increase the difficulty of training. Then the session-level RNN calculates a series of latent state vectors according to the inputs and previous state vectors, formally: where h 1 m,n ∈ R d h 1 and h 1 m,0 is initialized by a zero vector. Note that we use superscript 1 and 2 to distinguish the notations in low-and high-level RNN respectively such as hidden state vectors.
The RNN cell f (·) can be vanilla, LSTM, and GRU cell, which is implemented as GRU in our model: where h 1 m,n ∈ R d h 1 , the reset gate r 1 m,n and update gate z 1 m,n control the trade-off between previous states and present inputs, σ (·) is the sigmoid function, parameters W 1 r , V 1 r ,W 1 z , V 1 z ,W 1 and V 1 are shared across all sessions and updated during training. Each latent hidden state h 1 m,n models the short-term interest in session S m after issuing query q m,n . The dense vector of the last latent hidden state, denoted by h 1 m,n m , is viewed as a representation of the whole session, i.e. the short-term interest vector, which is used as h 1 m for short in the following parts.

Modeling long-term user interests.
Looking at the whole search history, some interests do not change frequently alongside time.
For example, if a user kept searching "JAVA runtime environment", "JAVA data type", and "JAVA string to int", the user was probably a programmer. Even though after a very long time this user issued another query "JAVA Book", there should still be a great chance that the user is looking for a book of JAVA programming instead of JAVA Island. Therefore, the parameters of such cell states of interests should change less frequently than the parameters of short-term model, and this fact motivates us to build a hierarchical structure in our framework. Therefore, we add another RNN to encode a higher level information flow.
where h 2 m ∈ R d h 2 , and h 2 0 is initialized by a zero vector. The RNN cell f (·) is similarly defined in the low-level RNN: where parameters W 2 r , V 2 r ,W 2 z , V 2 z ,W 2 , and V 2 are shared across all users and updated during training. Analogously, each state h 2 m of this layer models long-term interest of user u after the session S m ends. A simple way to obtain the long-term user interest vector is to adopt the last latent state vector h 2 M −1 directly. However, this could introduce unnecessary noise as we stated in Section 1. To avoid this issue, we implement an attention model to assign query-aware weights to long-term interest vectors {h 2 1 , ..., h 2 M −1 } in the end of different sessions, so as to highlight different parts of historical search behaviors dynamically. This intuitive idea is proved effective and better than plain RNN model in our experiments.

Building Dynamic User Profiles
As discussed in Section 1, the same past interactions could contribute differently to personalized rankings under different search circumstances. We believe that discriminating previous behaviors is necessary in building an effective user profile. Vu et al. built user profiles using dynamic group formation based on input query [40]. In our model, we deploy an attention model to apply different weights for each previous session based on current query. Note that in an extreme case, the weights for some interactions should be very high when a user issues a historical query to re-find the information they have searched before. Such re-finding problem has been well studied by Teevan et al. as personal navigation [37] and is a special case naturally incorporated in our model.
Attention mechanism was first proposed in machine translation to deal with the limitation of fixed-length representation of input sentences [1]. Similarly we hypothesize that encoding the click through data into a fixed-length representation is not reasonable when we are personalizing search results under different situations. Therefore, with respect to the current query, we assign query-aware weights to past interactions and compute a more precise long-term user profile. In other words, we suppose that the long-term interest vector is influenced by the current information need dynamically. At the end of session S M −1 , we calculate weights {α 1 , ..., α M −1 } for each past interest vector in {h 2 1 , ..., h 2 M −1 } as follow.
where ϕ(·) is a multilayer perceptron (MLP) with tanh(·) as activation function in our model, which is updated during training and could be replaced by more complex functions in the future. Then the query-aware long-term interest vector h In sum, we denote the final short-and long-term interest vectors as h 1 M,n m and h 2,q M −1 respectively and use them to re-rank the search results in the following.

Re-ranking
Finally we re-rank the original results using the personalized information we collect. Given the short-and long-term interest vectors, h 1 M,n m and h 2,q M −1 , we calculate the personalized ranking scores of a document by measuring its similarity to these two interest vectors: where W S ∈ R d h 1 ×d e ,W L ∈ R d h 2 ×d e are two similarity matrices whose functions are to project the interest vectors into the same semantic space as the documents, which are optimized during training. The similarity function sim(·) is defined as: In addition to personalization scores calculated by our model, we also incorporate query-document relevance feature and click-based features as additional features. Since the original query-document features are inaccessible in our dataset, here we use the original position of the document as a feature. Also, the click features include the total number of historical clicks on the candidate document by the user, the number of clicks on candidate document under the input query by the user and the click entropy of input query. The reason we incorporate click entropy is because the value of personalization varies a lot across different queries, and indiscriminately applying personalization on all queries could produce an adverse effect on the overall quality [11,36]. Note that as for fair comparison, the baseline model is a more complex model that incorporates more than these three features. And our idea is focused on building topic-based user profile instead of investigating on click-based features as discussed in Section 1. These additional features are fed into a multilayer perceptron (MLP) with tanh(·) as the activation function. Finally, we sum up the scores calculated by different parts as the final relevance score.
We choose a basic ranking algorithm, LambdaRank [5], to train the whole framework. We generate training pairs from query logs by treating the SAT-clicked documents as relevant samples and the others as irrelevant ones. Then we use the representations of document pairs to calculate the loss. Take a pair of relevant document d i and irrelevant document d j as an example. The loss function is the product of cross entropy between desired probabilities and predicted probabilities and the change of metrics, ∆, while swapping the positions of the two documents, defined as: where p i j represents the predicted probability that d i is more relevant than d j , and p i j represents the real probability. Specifically, the predicted probabilities are computed by a logistic function, ) .

EXPERIMENT SETUP 4.1 Dataset and Evaluation
The dataset in our experiment is sampled randomly by users from the logs of a commercial search engine, comprising click-through  Table 1. Following [4,41], we similarly regard the click that has a dwelling time of more than 30 seconds or is the last one in the session as a satisfied click (SAT-click). We use the first six weeks of data to generate basic user profiles and use the remaining two weeks to train and test the models. Note that we use not only sessions from the first six weeks but all sessions before current session to calculate long-term interest vector. We split the last two-week data into training and test sets according to the sessions instead of the dates. The motivation behind this is that two weeks are a relatively short time span and the distribution of queries sometimes is uneven across dates. Besides, sessions can be viewed as search activities with independent intents of users, thus can be reasonably divided into different sets. For each user, we divide the sessions into 5:1 as training and test set respectively in the time order of sessions and treat the last one fifth sessions of training set as validation set. For each URL in the logs we retrieve its content and we remove the URLs that cannot be found anymore. Then we preprocess the documents by removing stopwords and punctuations. To ensure an effective segmentation of training and test dataset, we also remove the users who had less than 4 sessions.
We measure the quality of each ranking results using mean average precision (MAP), mean reciprocal rank (MRR), precision@1 (P@1) and average click position (Avg. Click). In addition to these mainstream metrics, we further evaluate the rankings by measuring the actual improvements on inverse document pairs [20], i.e. a clicked document and the skipped documents ranked before it. Our reason behind this is that clicks are not only based on the relevance of documents but also the positions [10]. This kind of position bias may make mainstream metrics somewhat problematic. For example, the low-ranked documents have lower probabilities to be examined. Even though some of them may be relevant, they are not clicked because they are not examined by users. These results are labeled as irrelevant by traditional metrics. Consequently, if we boost the positions of the unexamined documents, the traditional evaluation metrics cannot reflect the real changes. Therefore, we use the strategy, which considers clicked documents are better than skipped documents, proposed by Joachims et al. [20] to collect inverse document pairs. We compute the number (#Better) and percentage of improved pairs (P-Improve) in each personalized ranking to evaluate the reliable improvements made by personalization methods.

Baselines
In addition to the original ranking generated by the search engine, which is usually of very high quality, we further reproduce several state-of-the-arts personalization models as follows.
P-Click: Users often issue an identical query to re-find the previously viewed information. This observation was confirmed by Teevan et al [37] as a safe opportunity to improve the quality of search engine. Dou et al. proposed P-Click [11] as a basic personalization strategy. As for a user u, P-Click calculates the personalized score of a document d as the percentage of clicks on this document from past queries that are identical to the input query q, formally: where |clicks(q, d, u)| represents the click counts on d from query q by user u in the past, |clicks(q, •, u)| is the total click counts on query q by user u, and β is a smoothing factor set as 0.5. P-Click reranks the results based on this personalized score and combines the personalized ranking with original ranking using Borda' ranking fusion method. This model is also used as a baseline in [23]. Note that this method is purely based on the click information. Besides, we also care about the quality of user profile built by our model and past studies. Many past studies built user profiles based on clicked documents over a topic space. They assume that the topic that users are interested in is reflected by the topics of documents they clicked [33]. These past studies tailored the original ranking either directly using similarity between user profile and documents [40] or training a supervised model with diverse features [4]. However, the intrinsic idea of these methods is the same -using the aggregation of topics of past documents as user profiles.
SLTB: Bennett et al [4] implemented a personalization method by extracting diverse features from short-and long-term behavior (SLTB). SLTB generates personalized features through the combination of four options: (1) feature types (click-based or topic-based), (2) document coverage (across all queries; under queries identical/generalizations/specializations to the current query.), (3) temporal angle (historic, session and aggregate) and (4) temporal decay (able or disable). The decay is defined by the function 0.95 p(q r )−1 .
Here p(q r ) refers to the number of queries preceding the current query and 0.95 is a chosen decay factor. As for the topical representation of the documents, it uses the top two levels of the Open Directory Project hierarchy as the 207 labels of documents and trains a classifier to predict the categories of documents. Besides, SLTB also implements click entropy [11], topic entropy [33], and other features. All these features are fed into a learning-to-rank model, LambdaMART [46], to generate a personalized ranking. As for the parameters used in our experiments, especially those in the Learning-to-rank models, we initialize them with parameters same as in [4] and then tune them using the validation set.
PTM: Learning document representations from manual labels is problematic according to Carmen [7], since the categories of some documents are missing in the ontology. Instead, they proposed to use an unsupervised approach to learn a multinomial distribution for documents on the latent topics, and this method is also used by Vu et al. [40] later. Here we reproduce the PTM model proposed by [16] as our baseline. PTM calculated personalized scores based on the likelihood of documents given both query and the user as: where λ balances the weight of user's topical interest influencing on the overall ranking, and P(d) is estimated with Dirichlet smoothing based on the relative frequency of clicks on d in the whole log:

SLTB+PTM:
We also replace the topical features in SLTB by the features generated by the topic model from PTM, and keep the other features the same as in SLTB. We use this method as the fourth baseline.

Our Models
To verify the effects of our personalization framework, we train two personalization models formed with different compositions but under a same learning setting. Specifically: Hierarchical RNN+Query-aware Attention (HRNN+QA): The complete model stated in Section 3; Hierarchical RNN (HRNN): The Query-aware Attention is disabled and the long-term interest vector is represented by the last latent vector of the high-level RNN layer; To determine a group of appropriate parameters, we apply a grid search according to the performance of the model on the validation set. We empirically use a two-layer network for the attention and additional MLP. We use a range of word embedding sizes d e ∈ {300, 1000}, sizes of short-term interest vector d s1 ∈ {100, 200, 300, 500}, sizes of long-term interest vector d s2 ∈ {200, 400, 600, 1000}, number of hidden units in attention MLP d a ∈ {512, 1024}, number in additional MLP d f ∈ {32, 64, 128}, and learning rates λ ∈ {1e −4 , 1e −3 , 1e −2 }. No noticeable differences are observed while changing learning rates. When embedding size is larger, a relatively smaller size of RNN state will yield worse results. Considering the balance of efficiency and result quality, we finally chose a combination of parameters as d e = 300, d s1 = 300, d s2 = 600, d a = 1024, d f = 64 and λ = 1e −3 .
Similar to [29], we initialize the word embedding matrix W with a pre-trained unsupervised model and keep it fixed during the training. In this experiment, we train an embedding matrix on the documents from training dataset using the Google word2vec tool 2 . Finally, as we state at Section 3, we use Mean Average Precision as our metric to calculate ∆ in the learning-to-rank model, since MAP encourages to rank the most relevant documents at top positions, but we still evaluate the final rankings with four different metrics. Besides, we adopt an early stop strategy to end the training when the average loss on validation set stops decreasing in three continuous epochs.

EXPERIMENTAL RESULTS AND ANALYSIS
As discussed in Section 1, the sequences of previous queries and sessions are valuable to personalization and a static user profile is not enough. Therefore, we are very interested in two research questions: (1) Is hierarchical recurrent neural network able to mine sequential information from query logs and learn a better topical user profile? (2) Does attention mechanism help to highlight different parts of search histories dynamically? To answer the questions, we firstly evaluate the overall performances of models stated in the previous section. Then we will discuss the effectiveness of attention mechanism by visualizing the provided weights. In addition, we will analyze the performances of baseline models and our models under different situations, including on queries with different click entropies, on repeated and non-repeated queries, and on queries at different positions in a session.

Overall Performance
We evaluate the results generated by the search engine, baseline models and our proposed models using MAP, MRR, P@1, Avg. Click, #Better, and P-Improve. In addition to original ranking, the baseline models include P-Click, PTM, SLTB and SLTB+PTM, and our frameworks include HRNN and HRNN+QA. All the scores are computed over all test queries. Results are shown in Table 2. We have the following observations: (1) All personalization methods except PTM successfully improve the original ranking. Directly using user profiles to re-rank the results might cause many problems. For example, applying personalization on queries with low click entropies may increase the risk of personalization. It is observed that P-Click only fixes about half of inverse document pairs of those improved by PTM. In contrast, though very simple, P-Click improves the original ranking in a relatively safe way. SLTB and SLTB-PTM significantly improve original ranking with paired t-test at p<0.01. This proves that a welltrained learning-to-rank model with rich features can effectively yield personalization under different circumstances.
(2) As shown in Table 2, our models generate great improvements over all baseline models and the differences are statistically significant with paired t-test at p<0.01 level. More specifically, HRNN+QA obtains rankings that are 0.0187 higher in MAP than the rankings generated by SLTB+PTM. As for reliable improvements, HRNN+QA produces a 12% increase in the number of improved inverse document pairs than SLTB+PTM. This outcome demonstrates that our models are able to learn more precise user profiles, and consequently yield better personalization.
(3) We find that attention mechanism works on HRNN and improves its results with 443 more inverse document pairs fixed. However, such improvement is not statistically significant. One possible reason is that the attention model is difficult to apply on a relatively long sequence (around 80 queries were issued per user). Since the attention layer calculates weights that despite the time span, some old behaviors might be assigned undeserved weights in the final profile and destroy the sequential information. One potential replacement of attention model is to apply Reinforcement Learning to discretely select the search sessions and queries, which successfully worked on sentence classification task with noise data [13].
The overall performances provide us a general evaluation on these methods. Observing the significantly improvement generated by our model, it is safe to draw conclusion that hierarchical recurrent neural network is able to model the sequential information and build better user profiles than traditional methods. To further analyze the function of attention model introduced in our framework, it is necessary to find out on what queries the model applies a higher weight. In the next section, we give a real example and visualize the weights.

Visualization of Weights Assigned by Attention Model
While personalizing search results in a specific situation, it is unnecessary for search engine to use the whole search history. Depending on the input query, some previous information is useless. Blindly using all data could bring noise into user profiles. Intuitively, sessions that have more similar intents should contribute more in building the current user profile. In this paper, we implement a query-aware attention mechanism to highlight different past interactions on the basis of input query and generate user profile dynamically. Table 2 shows that using this kind of dynamic user profiles improves personalization. To further analyze the influence of attention mechanism, we sample a user from query logs who has relatively rich search history, and visualize the weights applied on different sessions. To make it clearer, we represent the intent of each past session with a typical query from it and sum up the weights of different sessions with the same intent. We select five input queries in the test data and remove the past sessions that have weights less than 0.01 for any of the queries. As shown in Figure 2, we find that the long-term interest vector attends to past sessions that are more relevant to input queries. In general, the attention can filter the irrelevant information in the query logs. For example, when a user issues a query "virginia welfare lottery ban", the past session containing "virginia lottery" gains the largest weight and the other sessions obtain lower weights. We also find that the past sessions for "facebook" are weighted highly in all five input queries, which is contrary to our intuition. One possible reason is that queries on "facebook" have been issued frequently in the past, so the aggregation of these different past sessions leads to a higher weight for "facebook" sessions. Input queries such as "times magazine" and "weather forest" whose topics did not occur in the search history obtain weights that do not vary too much. The visualization of weights on past sessions shows that the attention model is able to distinguish the relatively important sessions in the user query logs.
In order to further verify the effects of our model, it is worthwhile to analyze on what kinds of queries that our methods could achieve larger improvements. In the following sections, we focus on comparing our frameworks with two SLTB baseline models. We use ∆MAP, the change of MAP over original ranking, as the main metric to describe results.

Performance on Navigational and Non-navigational Queries
A larger click entropy often indicates a higher potential for personalization, as it represents a larger probability of diverse user intents [11,36]. To study this problem, we firstly group the queries with cutoff of click entropy at 1.0. Teevan et al. [37] used it as an indicator of distinguishing general navigational queries. Then we compare the improvements made by different models on two groups of queries. As seen in Figure 3, all personalization models produce improved rankings on both groups of queries, and the average improvements on non-navigational queries (click entropy≥1) are much larger than on navigational queries (click entropy<1). In general, our model based on HRNN+QA outperforms any other methods and all of our models outperform the baseline methods (p<0.01). Specifically, as for navigational queries, the ∆MAP of our framework based on HRNN+QA is 0.0124 higher than the best baseline model's (SLTB+PTM). Such improvement further increases to 0.0337 when click entropy is larger than 1.0. Also, all of our two models have improvements of about 0.03 on the non-navigational queries. These results confirm that our framework works better on non-navigational queries than navigational queries.

Performance on Repeated and Non-repeated Queries
In this experiment, we categorize test queries into two groups: repeated queries and non-repeated queries. A repeated query is a query that the user has issued in the past, and this indicates that the user probably issues the current query to re-find the same information. The click-based personalization methods we discuss in Section 2 highly depend on the information extracted from these repeated queries. If a model never saw the query in the past, most click-based features will be disabled. Therefore, it is worthwhile to evaluate our framework on these non-repeated queries when click based features do not work. As shown in Figure 4, all methods significantly improve the original results on repeated queries, while our models also outperform the baseline models. The MAP of ranking generated by HRNN+QA on these queries is around 0.03 larger than by SLTB+PTM. With the topical information, the model can better promote the clicked results. Note that personalization on the non-repeated queries is very challenging when baseline models fail improving the search results. On the contrary, our framework successfully generalizes to the queries that are never seen before. Due to the lack of click information for non-repeated queries, only topical features can play a role in tailoring the search results. This observation shows that it is insufficient to simply use an aggregation of clicked documents, and it demonstrates the effectiveness of our model in learning a better user profile. In addition, it shows that applying attention model or not does not make a big difference on non-repeated queries. The majority of the improvements achieved by attention model occurs on repeated queries, which means attention model further highlight the very similar previous queries and reduce the noise.

Performances on Queries at Different Positions in Sessions
In Table 2, we find that hierarchical structure achieved the best compared with baseline models, but the roles of long-and shortterm interest vectors in our framework are still unclear. In this experiment we analyze the performances of each part on queries at different positions in a session. To avoid the influence of additional features, we focus our experiment on non-repeated queries, where click-based features are no more useful. Specifically, we train a plain RNN model whose hierarchical RNN layer is replaced by a one-layer RNN. The model unpacks the session-segmented inputs of HRNN and feeds the whole historical data to the RNN to calculate evolving latent state vectors. In addition, we set a short-term RNN model by disabling the high-level RNN and using the short-term interest vector only, and also a long-term RNN model in the similar way. Note that the long-term RNN model still depends on the low-level RNN to modeling past interests. We analyze the performances of above frameworks and compare them with the complete HRNN. From Figure 5, we find that short-term RNN steadily improves the results more with the increasing of query positions, because more information is available at a higher position during the session. This observation is consistent with Bennett et al. [4]. In contrast, long-term RNN in our model generates relatively stable benefits on queries at different positions. On the queries at first position in each session, short-term RNN fails to improve the search results, since no session information is available. In that case, the zero short-term vector is used, which turns out to be ineffective. By analyzing the queries at first positions, we find that hierarchical structure is better in modeling long-term dependency, and it produces improvements two times larger than plain structure.

CONCLUSION
Large amount of data is generated every single day alongside the interactions between users and search engines. Previous studies have demonstrated that by extracting diverse features from large-scale query logs, search engines are able to tailor the original ranking to satisfy individual users. However, none of these studies successfully exploit the sequential information contained among queries and sessions. In this paper, we propose to apply a deep learning framework to solve this problem. Specifically, we deploy a hierarchical recurrent neural network with query-aware attention mechanism to dynamically generate the topical user profiles. The evaluation on the query logs from a commercial search engine shows that our framework significantly outperforms the existing non-deep learning methods. In contrast to previous studies which assigned a timespan-based decay on historical data or ignored the sequential information, our model is able to automatically decide what to keep in the user profiles and consequently generate better user profiles. Our experiments also confirm that the query-aware attention model is able to highlight the important parts from previous queries and sessions. To further improve our framework, we can replace the attention model with a Reinforcement Learning model, leveraging its ability to discretely select past data. Besides, how to leverage documents skipped by users is also worth further studying.