{'fraction_non_alphanumeric': 0.05345468992668039, 'fraction_numerical': 0.012316249503377036, 'mean_word_length': 3.6833558863328824, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
TopRank: A practical algorithm for online stochastic ranking

Online learning to rank is a sequential decision-making problem where in each round the learning agent chooses a list of items and receives feedback in the form of clicks from the user. Many sample-efficient algorithms have been proposed for this problem that assume a specific click model connecting rankings and user behavior. We propose a generalized click model that encompasses many existing models, including the position-based and cascade models. Our generalization motivates a novel online learning algorithm based on topological sort, which we call TopRank. TopRank is (a) more natural than existing algorithms, (b) has stronger regret guarantees than existing algorithms with comparable generality, (c) has a more insightful proof that leaves the door open to many generalizations, (d) outperforms existing algorithms empirically.


Introduction
Learning to rank is an important problem with numerous applications in web search and recommender systems [13]. Broadly speaking, the goal is to learn an ordered list of K items from a larger collection of size L that maximizes the satisfaction of the user, often conditioned on a query. This problem has traditionally been studied in the offline setting, where the ranking policy is learned from manuallyannotated relevance judgments. It has been observed that the feedback of users can be used to significantly improve existing ranking policies [2,20]. This is the main motivation for online learning to rank, where the goal is to adaptively maximize the user satisfaction.
Numerous methods have been proposed for online learning to rank, both in the adversarial [15,16] and stochastic settings. Our focus is on the stochastic setup where recent work has leveraged click models to mitigate the curse of dimensionality that arises from the combinatorial nature of the action-set. A click model is a model for how users click on items in rankings and is widely studied by the information retrieval community [3]. One popular click model in learning to rank is the cascade model (CM), which assumes that the user scans the ranking from top to bottom, clicking on the first item they find attractive [8,4,9,22,12,7]. Another model is the position-based model (PBM), where the probability that the user clicks on an item depends on its position and attractiveness, but not on the surrounding items [10].
The cascade and position-based models have relatively few parameters, which is both a blessing and a curse. On the positive side, a small model is easy to learn. More negatively, there is a danger that a simplistic model will have a large approximation error. In fact, it has been observed experimentally that no single existing click model captures the behavior of an entire population of users [6]. Zoghi et al. [21] recently showed that under reasonable assumptions a single online learning algorithm can learn the optimal list of items in a much larger class of click models that includes both the cascade and position-based models.
We build on the work of Zoghi et al. [21] and generalize it non-trivially in multiple directions. First, we propose a general model of user interaction where the problem of finding most attractive list can be posed as a sorting problem with noisy feedback. An interesting characteristic of our model is that the click probability does not factor into the examination probability of the position and the attractiveness of the item at that position. Second, we propose an online learning algorithm for finding the most attractive list, which we call TopRank. The key idea in the design of the algorithm is to maintain a partial order over the items that is refined as the algorithm observes more data. The new algorithm is simultaneously simpler, more principled and empirically outperforms the algorithm of Zoghi et al. [21]. We also provide an analysis of the cumulative regret of TopRank that is simple, insightful and strengthens the results by Zoghi et al. [21], despite the weaker assumptions.

Online learning to rank
We assume the total numbers of items L is larger than the number of available slots K and that the collection of items is [L] = {1, 2, . . . , L}. A permutation on finite set X is an invertible function σ : X → X and the set of all permutations on X is denoted by Π(X). The set of actions A is the set of permutations Π([L]), where for each a ∈ A the value a(k) should be interpreted as the identity of the item placed at the kth position. Equivalently, item i is placed at position a −1 (i). The user does not observe items in positions k > K so the order of a(k + 1), . . . , a(L) is not important and is included only for notational convenience. We adopt the convention throughout that i and j represent items while k represents a position.
The online ranking problem proceeds over n rounds. In each round t the learner chooses an action A t ∈ A based on its observations so far and observes binary random variables C t1 , . . . , C tL where C ti = 1 if the user clicked on item i. We assume a stochastic model where the probability that the user clicks on position k in round t only depends on A t and is given by with v : A × [L] → [0, 1] an unknown function. Another way of writing this is that the conditional probability that the user clicks on item i in round t is P(C ti = 1 | A t = a) = v(a, a −1 (i)).
The performance of the learner is measured by the expected cumulative regret, which is the deficit suffered by the learner relative to the omniscient strategy that knows the optimal ranking in advance.
Remark 1. We do not assume that C t1 , . . . , C tL are independent or that the user can only click on one item.

Modeling assumptions
In previous work on online learning to rank it was assumed that v factors into v(a, k) = α(a(k))χ(a, k) where α : [L] → [0, 1] is the attractiveness function and χ(a, k) is the probability that the user examines position k given ranking a. Further restrictions are made on the examination function χ. For example, in the document-based model it is assumed that χ(a, k) = 1{k ≤ K}. In this work we depart from this standard by making assumptions directly on v. The assumptions are sufficiently relaxed that the model subsumes the document-based, position-based and cascade models, as well as the factored model studied by Zoghi et al. [21]. See the appendix for a proof of this. Our first assumption uncontroversially states that the user does not click on items they cannot see. Assumption 1. v(a, k) = 0 for all k > K.
Although we do not assume an explicit factorization of the click probability into attractiveness and examination functions, we do assume there exists an unknown attractiveness function α : [L] → [0, 1] that satisfies the following assumptions. In all classical click models the optimal ranking is to sort the items in order of decreasing attractiveness. Rather than deriving this from other assumptions, we will Algorithm 1 TopRank Choose A t uniformly at random from A(P t1 , . . . , P td ) 8: Observe click indicators C ti ∈ {0, 1} for all i ∈ [L] 9: for all (i, j) ∈ [L] 2 do 10: simply assume that v satisfies this criteria. We call action a optimal if α(a(k)) = max k ≥k α(a(k )) for all k ∈ [K]. The optimal action need not be unique if α is not injective, but the sequence α(a(1)), . . . , α(a(K)) is the same for all optimal actions. Assumption 2. Let a * ∈ A be an optimal action. Then max a∈A The next assumption asserts that if a is an action and i is more attractive than j, then exchanging the positions of i and j can only decrease the likelihood of clicking on the item in slot a −1 (i). Fig. 1 illustrates the two cases. The probability of clicking on the second position is larger in a than in a . On the other hand, the probability of clicking on the fourth position is larger in a than in a. The assumption is actually slightly stronger than this because it also specifies a lower bound on the amount by which one probability is larger than another in terms of the attractiveness function. Assumption 3. Let i and j be items with α(i) ≥ α(j) and let σ : A → A be the permutation that exchanges i and j and leaves other items unchanged. Then for any action a ∈ A, v(a, a −1 (i)) ≥ α(i) α(j) v(σ • a, a −1 (i)) .
Our final assumption is that for any action a with α(a(k)) = α(a * (k)) the probability of clicking on the kth position is at least as high as the probability of clicking on the kth position for the optimal action. This assumption makes sense if the user is scanning the items from the first position until the last, clicking on items they find attractive until some level of satisfaction is reached. Under this assumption the user is least likely to examine position k under the optimal ranking. Assumption 4. For any action a and optimal action a * with α(a(k)) = α(a * (k)) it holds that v(a, k) ≥ v(a * , k).

Algorithm
Before we present our algorithm, we introduce some basic notation. Given a relation G ⊆ [L] 2 and X ⊆ [L], let min G (X) = {i ∈ X : (i, j) / ∈ G for all j ∈ X}. When X is nonempty and G does not have cycles, then min G (X) is nonempty. Let P 1 , . . . , P d be a partition of [L] so that ∪ c≤d P c = [L] and P c ∩ P c = ∅ for any c = c . We refer to each subset in the partition, P c for c ≤ d, as a block. Let A(P 1 , . . . , P d ) be the set of actions a where the items in P 1 are placed at the first |P 1 | positions, the items in P 2 are placed at the next |P 2 | positions, and so on. Specifically, Our algorithm is presented in Algorithm 1. We call it TopRank, because it maintains a topological order of items in each round. The order is represented by relation G t , where G 1 = ∅. In each round, TopRank computes a partition of [L] by iteratively peeling off minimum items according to G t . Then it randomizes items in each block of the partition and maintains statistics on the relative number of clicks between pairs of items in the same block. A pair of items (j, i) is added to the relation once item i receives sufficiently more clicks than item j during rounds where the items are in the same block. The reader should interpret (j, i) ∈ G t as meaning that TopRank collected enough evidence up to round t to conclude that α(j) < α(i). Remark 2. The astute reader will notice that the algorithm is not well defined if G t contains cycles. The analysis works by proving that this occurs with low probability and the behavior of the algorithm may be defined arbitrarily whenever a cycle is encountered. Assumption 1 means that items in position k > K are never clicked. As a consequence, the algorithm never needs to actually compute the blocks P td where min I td > K because items in these blocks are never shown to the user.
Shortly we give an illustration of the algorithm, but first introduce the notation to be used in the analysis. Let I td be the slots of the ranking where items in P td are placed, Furthermore, let D ti be the block with item i, so that i ∈ P tDti . Let M t = max i∈[L] D ti be the number of blocks in the partition in round t. This indicates the algorithm has collected enough data to believe that item 3 is less attractive than item 1 and that item 5 is less attractive than items 2 and 3. The relation is depicted in Fig. 2 where an arrow from j to i means that (j, i) ∈ G t . In round t the first three positions in the ranking will contain items from P t1 = {1, 2, 4}, but with random order. The fourth position will be item 3 and item 5 is not shown to the user. Note that M t = 3 here and D t2 = 1 and D t5 = 3. Remark 3. TopRank is not an elimination algorithm. In the scenario described above, item 5 is not shown to the user, but it could happen that later (4, 2) and (4, 3) are added to the relation and then TopRank will start randomizing between items 4 and 5 for the fourth position.

Regret analysis
Theorem 1. Let function v satisfy Assumptions 1-4 and α(1) > α(2) > · · · > α(L). Let ∆ ij = α(i) − α(j) and δ ∈ (0, 1). Then the n-step regret of TopRank is bounded from above as By choosing δ = n −1 the theorem shows that the expected regret is at most The algorithm does not make use of any assumed ordering on α(·), so the assumption is only used to allow for a simple expression for the regret. The only algorithm that operates under comparably general assumptions is BatchRankfor which the problem-dependent regret is a factor of K 2 worse and the dependence on the suboptimality gap is replaced by a dependence on the minimal suboptimality gap.
The core idea of the proof is to show that (a) if the algorithm is suffering regret as a consequence of misplacing an item, then it is gaining information about the relation of the items so that G t will gain elements and (b) once G t is sufficiently rich the algorithm is playing optimally. Let For each t ∈ [n] let F t to be the failure event that there exists i = j ∈ [L] and s < t such that N sij > 0 and Lemma 1. Let i and j satisfy α(i) ≥ α(j) and d ≥ 1. On the event that i, j ∈ P sd and d ∈ [M s ] and U sij = 0, the following hold almost surely: Proof. For the remainder of the proof we focus on the event that i, j ∈ P sd and d ∈ [M s ] and U sij = 0. We also discard the measure zero subset of this event where P s−1 (U sij = 0) = 0. From now on we omit the 'almost surely' qualification on conditional expectations. Under these circumstances the definition of conditional expectation shows that where in the second equality we added and subtracted P s−1 (C si = 1, C sj = 1). By the design of TopRank, the items in P td are placed into slots I td uniformly at random. Let σ be the permutation that exchanges the positions of items i and j. Then using Assumption 3, where the second equality follows from the fact that a −1 (i) = (σ • a) −1 (j) and the definition of the algorithm ensuring that P s−1 (A s = a) = P s−1 (A s = σ • a). The last equality follows from the fact that σ is a bijection. Using this and continuing the calculation in Eq. (1) shows that The second part follows from the first since U sji = −U sij .
The next lemma shows that the failure event occurs with low probability. Lemma 2. It holds that P(F n ) ≤ δL 2 .
Proof. The proof follows immediately from Lemma 1, the definition of F n , the union bound over all pairs of actions, and a modification of the Azuma-Hoeffding inequality in Lemma 6.
Lemma 3. On the event F c t it holds that (i, j) / ∈ G t for all i < j.
Proof. Let i < j so that α(i) ≥ α(j). On the event F c t either N sji = 0 or When i and j are in different blocks in round u < t, then U uji = 0 by definition. On the other hand, when i and j are in the same block, E u−1 [U uji | U uji = 0] ≤ 0 almost surely by Lemma 1. Based on these observations, which by the design of TopRank implies that (i, j) / ∈ G t .
Lemma 4. Let I * td = min P td be the most attractive item in P td . Then on event F c t , it holds that Proof. Let i * = min ∪ c≥d P tc . Then i * ≤ 1 + c<d |P td | holds trivially for any P t1 , . . . , P tMt and d ∈ [M t ]. Now consider two cases. Suppose that i * ∈ P td . Then it must be true that i * = I * td and our claim holds. On other hand, suppose that i * ∈ P tc for some c > d. Then by Lemma 3 and the design of the partition, there must exist a sequence of items i d , . . . , i c in blocks P td , . . . , P tc such that i d < · · · < i c = i * . From the definition of I * td , I * td ≤ i d < i * . This concludes our proof.

Lemma 5.
On the event F c n and for all i < j it holds that S nij ≤ 1 + Proof. The result is trivial when N nij = 0. Assume from now on that N nij > 0. By the definition of the algorithm arms i and j are not in the same block once S tij grows too large relative to N tij , which means that On the event F c n and part (a) of Lemma 1 it also follows that Combining the previous two displays shows that Using the fact that N nij ≤ n and rearranging the terms in the previous display shows that

The result is completed by substituting this into Eq. (2).
Proof of Theorem 1. The first step in the proof is an upper bound on the expected number of clicks in the optimal list a * . Fix time t, block P td , and recall that I * td = min P td is the most attractive item in P td . Let k = A −1 t (I * td ) be the position of item I * td and σ be the permutation that exchanges items k and I * td . By Lemma 4, I * td ≤ k; and then from Assumptions 3 and 4, we have that v(A t , k) ≥ v(σ • A t , k) ≥ v(a * , k). Based on this result, the expected number of clicks on I * td is bounded from below by those on items in a * , where we also used the fact that TopRank randomizes within each block to guarantee that P t−1 (A −1 t (I * td ) = k) = 1/|I td | for any k ∈ I td . Using this and the design of TopRank, Therefore, under event F c t , the conditional expected regret in round t is bounded by The last inequality follows by noting that To see this use part (a) of Lemma 1 to show that E t−1 [U tij ] ≥ 0 for i < j and Lemma 4 to show that when I * td > K, then neither I * td nor j are not shown to the user in round t so that U tI * td j = 0. Substituting the bound in Eq. (3) into the regret leads to where we used the fact that the maximum number of clicks over n rounds is nK. The proof of the first part is completed by using Lemma 2 to bound the first term and Lemma 5 to bound the second. The problem independent bound follows from Eq. (4) and by stopping early in the proof of Lemma 5. The details are given in the appendix.
Lemma 6. Let (F t ) n t=0 be a filtration and X 1 , X 2 , . . . , X n be a sequence of F t -adapted random variables with X t ∈ {−1, 0, 1} and See Appendix B for the proof.
We also provide a minimax lower bound, the proof of which is deferred to Appendix D. Theorem 2. Suppose that L = N K with N an integer and n ≥ K and n ≥ N and N ≥ 8. Then for any algorithm there exists a ranking problem such that The proof of this result only makes use of ranking problems in the document-based model. This also corresponds to a lower bound for m-sets in online linear optimization with semi-bandit feedback. Despite the simple setup and abundant literature, we are not aware of any work where a lower bound of this form is presented for this unstructured setting.

Experiments
We experiment with the Yandex dataset [19], a dataset of 167 million search queries. In each query, the user is shown 10 documents at positions 1 to 10 and the search engine records the clicks of the user. We select 60 frequent search queries from this dataset, and learn their CMs and PBMs using PyClick [3]. The parameters of the models are learned by maximizing the likelihood of observed clicks. Our goal is to rerank L = 10 most attractive items with the objective of maximizing the expected number of clicks at the first K = 5 positions. This is the same experimental setup as in Zoghi et al. [21]. This is a realistic scenario where the learning agent can only rerank highly attractive items that are suggested by some production ranker [20].
TopRank is compared to BatchRank [21] and CascadeKL-UCB [8]. We used the implementation of BatchRank by Zoghi et al. [21]. We do not compare to ranked bandits [15], because they have already been shown to perform poorly in stochastic click models, for instance by Zoghi et al. [21] and Katariya et al. [7]. The parameter δ in TopRank is set as δ = 1/n, as suggested in Theorem 1. Fig. 3 illustrates Step n the general trend on specific queries. In the cascade model, CascadeKL-UCB outperforms TopRank. This should not come as a surprise because CascadeKL-UCB heavily exploits the knowledge of the model. Despite being a more general algorithm, TopRank consistently outperforms BatchRank in the cascade model. In the position-based model, CascadeKL-UCB learns very good policies in about two thirds of queries, but suffers linear regret for the rest. In many of these queries, TopRank outperforms CascadeKL-UCB in as few as one million steps. In the position-based model, TopRank typically outperforms BatchRank.
The average regret over all queries is reported in Fig. 4. We observe similar trends to those in Fig. 3. In the cascade model, the regret of CascadeKL-UCB is about three times lower than that of TopRank, which is about three times lower than that of BatchRank. In the position-based model, the regret of CascadeKL-UCB is higher than that of TopRank after 4 million steps. The regret of TopRank is about 30% lower than that of BatchRank. In summary, we observe that TopRank improves over BatchRank in both the cascade and position-based models. The worse performance of TopRank relative to CascadeKL-UCB in the cascade model is offset by its robustness to multiple click models.

Conclusions
We introduced a new click model for online ranking that subsumes previous models. Despite the increased generality, the new algorithm enjoys stronger regret guarantees, an easier and more insightful proof and improved empirical performance. We hope the simplifications can inspire even more interest in online ranking. We also proved a lower bound for combinatorial linear semi-bandits with m-sets that improves on the bound by Uchiya et al. [18]. We do not currently have matching upper and lower bounds. The key to understanding minimax lower bounds is to identify what makes a problem hard. In many bandit models there is limited flexibility, but our assumptions are so weak that the space of all v satisfying Assumptions 1-4 is quite large and we do not yet know what is the hardest case. This difficulty is perhaps even greater if the objective is to prove instance-dependent or asymptotic bounds where the results usually depend on solving a regret/information optimization problem [11]. Ranking becomes increasingly difficult as the number of items grows. In most cases where L is large, however, one would expect the items to be structured and this should then be exploited. This has been done for the cascade model by assuming a linear structure [22,12]. Investigating this possibility, but with more relaxed assumptions seems like an interesting future direction.

A Proof of weaker assumptions
Here we show that Assumptions 1-4 are weaker than those made by Zoghi et al. [21], who assumed that the click probability factors into v(a, k) = β(a(k))χ(a, k) where β : [L] → [0, 1] is the attractiveness function and χ : A × [L] → [0, 1] is the examination probability. They assumed that: 1. χ(a, k) = 0 for all actions a and positions k > K.

6.
K k=1 β(a(k))χ(a, k) is maximized by a * = (1, 2, . . . , L). We now show that these assumptions are stronger than Assumptions 1-4. Let β and χ be attraction and examination functions satisfying the six conditions above. We need to find choices of v and α such that v(a, k) = β(a(k))χ(a, k) for all actions a and positions k and where v and α satisfy Assumptions 1-4. First define α(i) = β(i)χ(a, 1) where a is any action. By item 4 this does not depend on the choice of a, which also means that α(i)β(j) = α(j)β(i) for any pair of items i and j. Then let v(a, k) = β(a(k))χ(a, k). Assumption 1 is satisfied trivially since item 1 implies that χ(a, k) = 0 whenever k > K. Assumption 2 is also satisfied trivially by item 6. For Assumption 3 we consider two cases. Let i and j be items with α(i) ≥ α(j) and suppose that a is an action with a −1 (i) < a −1 (j) and σ be the permutation that exchanges i and j. Then Now suppose that a −1 (i) > a −1 (j), then the claim follows from item 5. Assumption 4 follows easily from item 2 by noting that v(a, k) = β(a(k))χ(a, k) ≥ β(a(k))χ(a * , k) = β(a * (k))χ(a * , k) = v(a * , k) . Note that we did not use item 3 at all and one can easily construct a function v that satisfies Assumptions 1-4 while not satisfying items 1-6 above. Zoghi et al. [21] showed that their assumptions were weaker than the position-based and cascade models, which therefore also holds for our assumptions.

B Proof of Lemma 6
We first show a bound on the right tail of S t . A symmetric argument suffices for the left tail. Let Y s = X s − µ s |X s | and M t (λ) = exp( t s=1 (λY s − λ 2 |X s |/2)). Define filtration G 1 ⊂ · · · ⊂ G n by G t = σ(F t−1 , |X t |). Using the fact that X s ∈ {−1, 0, 1} we have for any λ > 0 that Therefore M t (λ) is a supermartingale for any λ > 0. The next step is to use the method of mixtures [14] with a uniform distribution on [0, 2]. Let M t = 2 0 M t (λ)dλ. Then Markov's inequality shows that for any G t -measurable stopping time τ with τ ≤ n almost surely, P (M τ ≥ 1/δ) ≤ δ. Next we need a bound on M τ . The following holds whenever S t ≥ 0.
The bound on the upper tail completed via the stopping time argument of [5] (see also [1]), which shows that The result follows by symmetry and union bound.

C Proof of problem independent bound in Theorem 1
Following the proof of the first part until Eq. (4) we have As before the first term is bounded using Lemma 2. Then using the first part of the proof of Lemma 5 shows that Substituting into the previous display and applying Cauchy-Schwartz shows that Writing out the definition of N nij reveals that we need to bound Expanding the two terms in the inner sum and bounding each separately leads to For the second term, Hence (A) ≤ nK 2 and R n ≤ nKP(F n ) + KL + 4K 3 Ln log c √ n δ and the result follows from Lemma 2.

D Proof of minimax lower bound in Theorem 2
Throughout the section we assume a fixed learner. The lower bound is proven for the document-based model where for attractiveness function α : [L] → [0, 1] the probability of clicking on the ith item in round t is P t−1 (C ti = 1) = α(i)1 A −1 t (i) ≤ K . We assume that C t1 , . . . , C tL are conditionally independent under P t−1 . Recall that we have assumed that L = N K for integer N , which means there is a bijection between φ : [L] → [K] × [N ]. For each k ∈ [K] the items {φ −1 (k, i) : i ∈ [N ]} are referred to as a block. From now on we abuse notation by writing α(k, i) = α(φ −1 (k, i)) and a −1 (k, i) = a −1 (φ −1 (k, i)) for any action a ∈ A. As is usual for lower bounds, we define a set of ranking problems and prove that no algorithm can do well on all of these problems simultaneously. Given m ∈ [N ] K define α m by where ∆ > 0 is a constant to be tuned subsequently. Given k ∈ [K] and m ∈ [N ] K we let α m −k be equal to α m except that α m (k, i) = 1/2 for all i ∈ [N ]. Given α(·, ·) we call item (k, i) suboptimal if α(k, i) = 1/2. Given a fixed m the optimal action satisfies α(a(k)) = 1/2 + ∆ for all k ≤ K and α(a(k)) = 1/2 for all k > K. The regret suffered by the learner in the document-based ranking problem determined by α m is denoted by R n (m). Given k ∈ [K] and i ∈ [N ] define For the final piece of notation let E k (t) be the number of suboptimal items in block k that are shown to the user in round t.
The first real step of the proof is to notice that R n (m) can be written in two ways: where in the first line we used Pinsker's inequality and the second we used the fact that the relative entropy between Bernoulli distributions with means 1/2 and 1/2 + ∆ is at most 8∆ 2 for ∆ 2 ≤ 1/8, which is easily established by bounding the relative entropy by the χ-squared distance [17]. We also used the chain rule for relative entropy. The novelty here is that we only need to calculate the relative entropy up to time τ k because T k (τ k ) is F τ k -measurable. The second last inequality follows since T k (τ k ) ≤ n + K and by Cauchy-Schwartz. The last inequality is satisfied by choosing ∆ = N 16(n + K) .
Substituting Eq. (8) into Eq. (7) shows that Since there exactly N K items appearing the sum on the left-hand side it follows there exists an m ∈ [N ] K such that R n (m) ≥ ∆N n 4 = 1 16 n 2 K 2 N n + K = 1 16 which completes the proof.