{'fraction_non_alphanumeric': 0.03686670687575392, 'fraction_numerical': 0.006973763570566948, 'mean_word_length': 4.272058823529412, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Optimal Tagging with Markov Chain Optimization

Many information systems use tags and keywords to describe and annotate content. These allow for efficient organization and categorization of items, as well as facilitate relevant search queries. As such, the selected set of tags for an item can have a considerable effect on the volume of traffic that eventually reaches an item. In settings where tags are chosen by an item's creator, who in turn is interested in maximizing traffic, a principled approach for choosing tags can prove valuable. In this paper we introduce the problem of optimal tagging, where the task is to choose a subset of tags for a new item such that the probability of a browsing user reaching that item is maximized. We formulate the problem by modeling traffic using a Markov chain, and asking how transitions in this chain should be modified to maximize traffic into a certain state of interest. The resulting optimization problem involves maximizing a certain function over subsets, under a cardinality constraint. We show that the optimization problem is NP-hard, but nonetheless has a simple (1-1/e)-approximation via a simple greedy algorithm. Furthermore, the structure of the problem allows for an efficient implementation of the greedy step.To demonstrate the effectiveness of our method, we perform experiments on three tagging datasets, and show that the greedy algorithm outperforms other baselines.


Introduction
To allow for efficient navigation and search, modern information systems rely on the usage of nonhierarchical tags, keywords, or labels to describe items and content. These tags are then used either explicitly by users when searching for content, or implicitly by the system to augment search results or to recommend related items.
Many online systems where users can create or upload content support tagging. Examples of such systems are media-sharing platforms, social bookmarking websites, and consumer to consumer auctioning services. Typically, an item's creator is free to select any set of tags or keywords which they believe best describe their item, where the only concrete limitation is on the number of tags, words, or characters used. Tags are often chosen on a basis of their ability to best describe, classify, or categorize items and content. By choosing relevant tags, users aid in creating a more organized information system. However, content creators may have their own individual objective, such as maximizing the exposure of other users to their items.
This suggests that choosing tags should in fact be done strategically. For instance, tagging a song as 'Rock' may be informative, but will probably only contribute marginally to the song's traffic, as the competition for popularity under this tag can be fierce. On the other hand, choosing a unique, obscure tag may be appealing, but will probably not help much either. Strategic tagging or keyword selection is more clearly exhibited in search-supporting systems, where keywords are explicitly used for filtering and ordering search results or ad placements, and users have a clear incentive of maximizing the exposure of their item. Nonetheless, their selections are typically heuristic or manual.
Recent years have seen an abundance of work on methods for user-specific tag recommendations [8,5]. Such methods aim to support collaborative tagging systems, where any user can tag any item in the repository. We take a complementary perspective and focus on taxonomic tagging systems where only the creator of an item can determine its tags. In this paper we formalize the task of optimal tagging and suggest an efficient, provably-approximate algorithm. While the problem is shown to be NP-hard, we prove that the objective is in fact monotone and submodular, which suggests a straightforward greedy (1 − 1 e )-approximation algorithm [13]. We also show how the greedy step, which consists of solving a set of linear equations, can be greatly simplified as well as parallelized, resulting in a significant improvement in runtime.
We begin by modeling a user browsing a tagged information system as a random walk. Items and tags act as states in a Markov chain, whose transition probabilities describe the probability of users jumping between items and tags. Our framework can incorporate many web search click models [3]. Given a new item, our task is to choose a subset of k tags for this item. When an item is tagged, positive probabilities are assigned to transitioning from the item to the tag and vice versa. Our objective is to choose the subset of k tags which will maximize traffic to that item, namely the probability of a random walk reaching the item at some point. Intuitively, tagging an item causes probability to flow from the tag to the item, on account of other items with this tag. Our goal is hence to 'leach' as much probability mass as possible from the system as a whole.
As mentioned, we are interested in maximizing the probability of a random walk reaching the state corresponding to a new item. Although this measure resembles the notion of the probability of an item under a stationary distribution (on which the popular PageRank metric is based), it is in fact quite different. First, while a state's stationary probability increases with incoming links, it may decrease with outgoing links. Since assigning a tag results in the addition of both an incoming and an outgoing link, using the stationary probability of an item will lead to an undesired nonmonotone objective [1]. Second, a stationary distribution does not always exist, and hence may require modifications of the Markov chain. Finally, we argue that maximizing the probability of reaching an item, as opposed to maximizing the proportion of time an infinite random walk spends in the item's state, is a better suited objective for the applications we consider.
Although the Markov chain model we propose for optimal tagging is bipartite, our results apply to general Markov chains. We therefore first formulate a general problem in Sec. 3, where the task is to choose k states to link a new state to such that the probability of reaching that state is maximal. Then, in Sec. 4 we prove that this problem is NP-hard by a reduction from vertex cover. In Sec. 5 we prove that for a general Markov chain the optimal objective is both monotonically non-decreasing and submodular. Based on this, in Sec. 6 we suggest a basic greedy (1 − 1 e )-approximation algorithm, and offer a way of significantly improving its runtime. In Sec. 7 we revisit the optimal tagging problem and show how to construct a bipartite Markov chain for a given tag-supporting information system. In Sec. 8 we present experimental results on three real-world tagging datasets (musical artists in Last.fm, bookmarks in Delicious, and movies in Movielens) and show that our algorithm outperforms plausible heuristics. Concluding remarks are given in Sec. 9.

Related Work
One the main roles of tags is to aid in the categorization and classification of content. The hallmark of tags is that they are not constrained to a fixed vocabulary or structure. An active line of research in tagging systems focuses on the task of tag recommendations, where the goal is to predict the set of tags a given user may attribute to an item. This setting is especially useful for collaborative tagging systems and folksonomies, where any user can tag any item. Popular methods for tag recommendation are based on random walks [8] or tensor factorization [5].While the goal in tag recommendation is also to output a set of tags, our task is very different in nature. Tag recommendation is a prediction task for item-user pairs, is based on ground-truth evaluation, and target collaborative tagging systems. In contrast, ours is an item-centric optimization task for tag-based taxonomies, and is counterfactual in nature. As such, tag recommendation methods do not apply to our setting.
A line of work similar to ours is optimizing the PageRank of web pages in different settings. In [4] the authors consider the problem of computing the maximal and minimal PageRank value for a set of "fragile" links. The authors of [1] analyze the effects of additional outgoing links on the PageRank value. Perhaps the work most closely related to ours is [14], where a constant-factor approximation algorithm is given for the problem of maximizing the PageRank value by adding at most k incoming links. The authors prove that the probability of reaching a web page is submodular and monotone in a fashion similar to ours (but with a different parameterization), and use it as a proxy for PageRank.
Links between absorbing Markov chains and submodular optimization have been studied for opinion maximization [6] and for computing centrality measures [12] in networks. Following the classic work of Nemhauser [13], submodular optimization is now a very active line of research. Many interesting optimization problems across diverse domains have been shown to be submodular. Examples of these are sensor placement [11] and influence maximization in social networks [9], to name a few.

Problem Formulation
Before we present our approach to optimal tagging, we first describe a general ocombinatorial ptimization task over Markov chains, of which our task is a special case. Consider a Markov chain over n + 1 states. Assume there is a state σ for which we would like to add a set of k new incoming transitions. In the tagging problem σ = n + 1 will be an item (e.g., song or product) and the incoming transitions will be from possible tags for the item, or from related items.
The optimization problem is then to choose a subset S ⊆ [n] of k states so as to maximize the probability of visiting σ at some point in time. Formally, let X t be the random variable corresponding to the state of the Markov chain at time t. Then the optimal tagging problem is: max At first glance, it is not clear how to compute the objective function in Eq. (1). However, with a slight modification of the Markov chain, the objective function can be expressed as a simple function of the Markov chain parameters, as explained next.
In general, σ may have outgoing edges, and random walks reaching σ may continue to other states afterward. Nonetheless, as we are only interested in the probability of reaching σ, the states visited after σ have no effect on our objective. Hence, σ's outgoing edges can be safely replaced with a single self-edge without affecting the probability of reaching σ. This essentially makes σ an absorbing state, and our task becomes to maximize the probability of the Markov chain being absorbed in σ.
In the remainder of the paper we consider this equivalent formulation.
When the Markov chain includes other absorbing states, optimizing over S can be intuitively thought of as trying to "leach" as much probability mass from the contending absorbing states to σ, under a budget on the number of states σ can be connected to. 1 As we discuss in Section 7, having contending absorbing states arises naturally in optimal tagging.
To fully specify the problem, we need the Markov chain parameters. Denote the initial distribution by π. For the transition probabilities, each node i will have two sets of transitions: one when it is allowed to transition to σ (i.e., i ∈ S) and one when no transition is allowed. Using two distinct sets is necessary since in both cases outgoing probabilities must sum to one. We use q ij to denote the transition probability from state i to j when transition to σ is allowed, andq ij when it is not. We also denote the corresponding transition matrices by Q andQ. Note thatq iσ = 0 for all i ∈ [n].
It is natural to assume that when adding σ, transition into σ will become more likely, and transition to other states can only be less likely. Thus, we add the assumption that: Given a subset S of states from which transitions to σ are allowed, we construct a new transition matrix, taking corresponding rows from Q andQ. We denote this matrix by ρ(S), with In what follows, we focus on the optimization problem in Eq. (1). Sec. 4 shows that it is NP hard. Sec. 5 then shows that the objective of Eq. (1) is monotone and submodular and therefore the optimization problem has a 1 − 1 e factor approximation via a simple greedy algorithm.

NP-Hardness
We now show that for a general Markov chain, the optimal tagging problem in Eq. (1) is NP-hard by a reduction from vertex cover. Given an undirected graph G = (V, E) with n nodes as input to the vertex cover problem, we construct an instance of optimal tagging such that there exists a vertex cover S ⊆ V of size at most k iff the probability of reaching σ reaches some threshold.
To create the absorbing Markov chain, we create a transient state i for every node i ∈ V , and add two absorbing states ∅ and σ. We set the initial distribution to be uniform, and for some 0 < ǫ < 1 set the transitions for transient states i as follows: Let U ⊆ V of size k, and S(U ) the set of states corresponding to the nodes in U . We claim that U is a vertex cover in G iff the probability of reaching σ when S(U ) is chosen is 1 − (n−k) n ǫ. Assume U is a vertex cover. For every i ∈ S(U ), as noted a walk starting in i will reach σ with probability 1. For every i ∈ S(U ), with probability ǫ a walk will reach ∅ in one step, and with probability 1 − ǫ it will visit one of its neighbors j. Since U is a vertex cover, it will then reach σ in one step with probability 1. Hence, in total it will reach σ with probability 1 − ǫ. Overall, the probability of reaching σ is k+(n−k)(1−ǫ) n = 1 − (n−k) n ǫ as needed. Note that this is the maximal possible probability of reaching σ for any subset of V of size k.
Assume now that U is not a vertex cover, then there exists an edge (i, j) ∈ E such that both i ∈ S(U ) and j ∈ S(U ). A walk starting in i will reach ∅ in one step with probability ǫ, and in two steps (via j) with probability ǫ·q ij > 0. Hence, it will reach σ with probability strictly smaller than 1 − ǫ, and the overall probability of reaching ǫ will be strictly smaller than 1 − (n−k) n ǫ.

Proof of Monotonicity and Submodularity
Denote by P S [A] the probability of event A when transitions from S to σ are allowed. We define: We now prove that f (S) is both monotonically non-decreasing and submodular.

Monotonicity
When a link is from i σ, the probability of reaching it directly from i goes up. However, due to the renormalization constraints, the probability of reaching it via other paths may go down. Nonetheless, our proof of monotonicity shows that the overall probability cannot decrease, as stated next.
Proof. We prove by induction on k. For k = 0, as π is independent of S and z, we have: Assume now that the claim holds for some k ≥ 0. We separate into cases. When i = z, we have: for i ∈ S and i / ∈ S, respectively. If i = z then: due to toq ij ≥ q ij , c ≤ 1, n j=1q ij = 1, and n j=1 q ij = 1 − q iσ . Corollary 5.2. ∀i ∈ [n], c i (S) is non-decreasing, hence f (S) = π, c(S) is non-decreasing.

Submodularity
Submodularity captures the principle of diminishing returns. A function f (S) is submodular if: It turns out that f (S) as defined in Eq. (7) is submodular, as shown in following theorem and corollary.  Proof. We prove by induction on k. The case for k = 0 is trivial since π is independent of S and hence c 0 i is modular. Assume now that the claim holds for some k ≥ 0. For brevity we define: We'd like to show that c (k+1) . For every j ∈ [n], we'll prove that: which together with Eq. (8) and subtracting ρ iσ 1 {i∈T } from both sides will conclude our proof. We separate into different cases for i. If i ∈ S, then we have ρ ij (S ∪ {z 1 , z 2 }) = ρ ij (S ∪ {z 1 }) = ρ ij (S ∪{z 2 }) = ρ ij (S) = q ij . Similarly, if i / ∈ S ∪{z 1 , z 2 }, then all terms now equalq ij . Therefore by the inductive assumption Eq. (9) follows. Assume i = z 1 = z (and analogously i = z 2 ). From the assumption in Eq. (2) we can writeq ij = (1 + α)q ij for some α ≥ 0. Then Eq. (9) becomes: Reorder to get: c This indeed holds since the first four terms are non-negative from the inductive assumption, and the last term is non-negative because of monotonicity and α ≥ 0.

Optimization
Maximizing submodular functions is hard in general. However, a classic result by Nemhauser [13] shows that a non-decreasing submodular set function, such as our f (S), can be efficiently optimized via a simple greedy algorithm, with a guaranteed (1− 1 e )-approximation of the optimum. The greedy algorithm initializes S = ∅, and then sequentially adds elements to S. For a given S, the algorithm iterates over all z ∈ [n] \ S and computes f (S ∪ {z}). Then, it adds the highest scoring z to S, and continues to the next step. We now discuss its implementation for our problem. We would like to calculate f (S). From Eq. (6), the probability of reaching σ given initial state i is: The above series has a closed form solution: Thus, c(S) is the solution of the set of linear equations, whose solution readily gives us f (S): The greedy algorithm can thus be implemented by sequentially considering candidate sets S of increasing size, and for each z calculating f (S ∪ {z}) by solving a set of linear equations (see Algo. 1). Though parallelizable, this naïve implementation may be quite costly as it requires solving O(n 2 ) sets of n − r linear equations, one for every addition of z to S. Fast submodular solvers such as CELF++ [7] can reduce the number of calls to f (S) by an order of magnitude. As we now show, a significant speedup in the computation of f (S) itself can be achieved using problem's structure.
A standard method for solving the set of linear equations (I − A)c = b if to first compute an LU P decomposition for (I − A), namely find lower and upper diagonal matrices L, U and a permutation matrix P such that LU = P (I − A). Then, if suffices to solve Ly = P b and U c = y. Since L and U are diagonal, solving these equations can be performed efficiently; the costly operation is computing the decomposition in the first place. Recall that ρ(S) is composed of rows from Q corresponding to S and rows fromQ corresponding to [n] \ S. This means that ρ(S) and ρ(S ∪ {z}) differ only in one row, or equivalently, that ρ(S ∪ {z}) can be obtained from ρ(S) by adding a rank-1 matrix.
With this in mind, given an LU P decomposition of ρ(S), we can efficiently compute f (S ∪ {z}) (and its corresponding decomposition) using rank-1-update techniques such as Bartels-Golub-Reid [15] or others.Such methods are especially efficient for sparse matrices. As a result, it suffices to compute only a single LU P decomposition for the input at the beginning, and perform cheap updates at every step. See the supplementary material for an efficient implementation.

Optimal Tagging
In this section we return to the task of optimal tagging and show how the Markov chain optimization framework described above can be applied. We use a random surfer model, where a browsing user hops between items and tags in a bipartite Markov chain. In its explicit form, our model captures the activity of browsing users whom, when viewing an item, are presented with the item's tags and may choose to click on them (and similarly when viewing tags).
In reality, many systems also (or mainly) include direct links between related items, often in the form of a ranked list of item recommendations. The relatedness of two items is often, at least to some extent, based on the set of mutual tags. Our model captures this notion of similarity by the (implicit) transitions to and from tag states. This allows us to encode tags as variables in the objective. As our results apply to general Markov chains, adding direct transitions between items is straightforward. Our framework easily incorporates click models [3], in which adding an item to a rank list modifies the clicking probabilities. Note that in contrast to models for tag recommendations, we do not need to explicitly model the system's users, as our setup defines only one distinct optimization task per item.
In what follows we formalize the above notions. Consider a system of m items Ω = {ω 1 , . . . , ω m } and n tags T = {τ 1 , . . . , τ n }. Each item ω i has a set of tags T i ⊆ T , and each tag τ j has a set of items Ω j ⊆ Ω. The items and tags constitute the states of a bipartite Markov chain, where users hop between items and tags. Specifically, the transition matrix ρ can have non-zero entries ρ ij and ρ ji for items ω i tagged by τ j . To model the fact that browsing users eventually leave the system, we add a global absorbing state ∅ and add transition probabilities ρ i∅ = ǫ i > 0 for all items ω i . For simplicity we assume that ǫ i = ǫ for all i, and that π can be non-zero only for tag states.
In our setting, when a new item σ is uploaded, the uploader may choose a set S ⊆ T of at most k tags for σ. Her goal is to choose S such that the probability of an arbitrary browsing user reaching (or equivalently, being absorbed in) σ while browsing the system is maximal. As in the general case, the choice of S effects the transition matrix ρ(S).
Denote by P ij the transition probability from item ω i to tag τ j , by R ji (S) the transition probability from τ j to ω i under S, and let r j (S) = R jσ (S). Using Eq. (12), ρ can be written as: where 0 and 1 are appropriately sized vectors or matrices. Since the graph is bipartite, since we assume the walks start at a tag state, and since we are interested only in choosing tags, the Markov chain can be "folded" to include only the tag-states and the absorbing states. Looking at ρ 2 (S), the transition probabilities between tags are now given by the matrix R(S)P , while the transition probabilities from tags to σ remain r(S). Our objective of the probability of reaching σ under S is: which is a special case of the general objective presented in Eq. (13), and hence can be optimized efficiently. In the supplementary material we prove that this special case is still NP-hard.

Experiments
To demonstrate the effectiveness of our approach, we perform experiments on optimal tagging in data collected from Last.fm, Delicious, and Movielens.taken from the HetRec 2011 workshop [2]. The datasets include all items (between 10,197 and 59,226) and tags (between 11,946 and 53,388) reached from crawling a set of about 2,000 users in each system, as well as some metadata.
For each dataset, we first created a bipartite graph of items and tags. Next, we generated 100 different instances of our problem per dataset by expanding each of the 100 highest-degree tags and creating a Markov chain for their items and all their associate tags. We discarded nodes with less than 10 edges.
To create an interesting tag selection setup, for each item in each instance we augmented its true tags with up to 100 similar tags (based on [16]). These served as the set of candidate tags for that item. We focused on items which were ranked first in at least 10 of their 100 candidate tags, giving a total of 18,167 focal items for comparison. For each such item, our task was to choose the k tags out of the 100 candidate tags which maximize the probability of reaching the focal item.
Transition probabilities from tags to items were set to be proportional to the item weights -number of listens for artists in Last.fm, tag counts for bookmarks in Delicious, and averaged ratings for movies in Movielens. As the datasets do not include weights for tags, we used uniform transition probabilities from items to tags. The initial distribution was set to be uniform over the set of candidate tags, and the transition probability from items to the absorbing state ∅ was set to ǫ = 0.1.
We compared the performance of our greedy algorithm with several baselines. Random-walk based methods included PageRank and a variant 2 of BiFolkRank [10], a state-of-the-art tag recommendation method that operates on item-tag relations. Heuristics included taking the k tags with highest degree, lowest degree, the true labels (for relevant k-s), and random. To measure the added value of taking into account long random walks, we also display the probability of reaching σ in one step.
Results for all three datasets are provided in Figure 1, which shows the average probability of reaching the focal item for values of k ∈ {1, . . . , 25}. As can be seen, the greedy method clearly outperforms other baselines. In our setup choosing low degree tags outperforms both random-walk based methods and heuristics. Considering paths of all lengths improves results by a considerable 20-30% for k = 1, and roughly 5% for k = 25. An interesting observation is that the performance of the true tags is rather poor. A plausible explanation for this is that the data we use are taken from collaborative tagging systems, where items can be tagged by any user. In such systems, tags typically play a categorical or hierarchical role, and as such are probably not optimal for promoting item popularity.

Conclusions
In this paper we introduced the problem of optimal tagging, along with the general problem of optimizing probability mass in Markov chains, by adding links. We proved that the problem is NP-hard, but can be (1 − 1 e )-approximated due to the submodularity and monotonicity of the objective. Our efficient greedy algorithm can be used in practice for choosing optimal tags or keywords in various domains. Our experimental results show that simple heuristics and PageRank variants underperform our disciplined approach, and naïvely selecting the true tags is typically suboptimal.
In our work we assumed access to the transition probabilities between tags and items and vice versa. While the transition probabilities for existing items can be easily estimated by a system's operator, estimating the probabilities from tags to new items is non-trivial. This is an interesting problem to pursue. Even so, users do not typically have access to the information required for estimation. Our results suggest that users can simply apply the greedy steps sequentially via trial-and-error. Finally, as our task is of a counterfactual nature, it is hard to draw conclusions from the experiments as to the effectiveness of our method in real settings. It would be interesting to test it in realty, and compare it to strategies used by both lay users and experts. Especially interesting in this context are competitive domains such as ad placements and viral marketing. We leave this for future research.