Predictive Querying for Autoregressive Neural Sequence Models
Abstract
In reasoning about sequential events it is natural to pose probabilistic queries such as “when will event A occur next” or “what is the probability of A occurring before B”, with applications in areas such as user modeling, medicine, and finance.
However, with machine learning shifting towards neural autoregressive models such as RNNs and transformers, probabilistic querying has been largely restricted to simple cases such as next-event prediction.
This is in part due to the fact that future querying involves marginalization over large path spaces, which is not straightforward to do efficiently in such models.
In this paper we introduce a general typology for predictive queries in neural autoregressive sequence models and show that such queries can be systematically represented by sets of elementary building blocks.
We leverage this typology to develop new query estimation methods based on beam search, importance sampling, and hybrids.
Across four large-scale sequence datasets from different application domains, as well as for the GPT-2 language model, we demonstrate the ability to make query answering tractable for arbitrary queries in exponentially-large predictive path-spaces, and find clear differences in cost-accuracy tradeoffs between search and sampling methods.
Introduction
One of the major successes in machine learning in recent years has been the development of neural sequence models for categorical sequences, particularly in natural language applications but also in other areas such as automatic code generation and program synthesis [Shin et al., 2019, Chen et al., 2021], computer security [Brown et al., 2018], recommender systems [Wu et al., 2017], genomics [Shin et al., 2021, Amin et al., 2021] and survival analysis [Lee et al., 2019].
Many of the models (although not all) rely on autoregressive training and prediction, allowing for the sequential generation of sequence completions in a recursive manner conditioned on sequence history.
A natural question in this context is how to compute answers to predictive queries that go beyond traditional one-step-ahead predictions.
Examples of such queries are “how likely is event A to occur before event B ?”
and “how likely is event C to occur (once or more) within the next K steps of the sequence?”
These types of queries are very natural across a wide variety of application contexts, for example, the probability that an individual will finish speaking or writing a sentence within the next
K words, or that a user will use one app before another.
See Fig.
1 and Appendix A for examples.
In this paper we develop a general framework for answering such predictive queries in the context of autoregressive (AR) neural sequence models.
This amounts to computing conditional probabilities of propositional statements about future events, conditioned on the history of the sequence as summarized by the current hidden state representation.
We focus in particular on how to perform near
[Figure]
real-time computation of such queries, motivated by use-cases such as answering human-generated queries and utilizing query estimates within the optimization loop of training a model.
Somewhat surprisingly, although there has been extensive prior work on multivariate probabilistic querying in areas such as graphical models and database querying, as well as for restricted types of queries for traditional sequence models such as Markov models, querying for neural sequence models appears to be unexplored.
One possible reason is that the problem is computationally intractable in the general case (as we discuss later in Section 3), typically scaling as O (cid:0) V K − 1 (cid:1) or worse for predictions K -steps ahead, given a sequence model with a V -ary alphabet (e.g. compared to O (cid:0) KV 2 (cid:1) for Markov chains).
Our contributions are three-fold:
We introduce and develop the problem of predictive querying in neural sequence models by reducing complex queries to elementary building blocks.
These elementary queries define restricted path spaces over future event sequences.
We show that the underlying autoregressive model can always be constrained to the restricted path space satisfying a given query.
This gives rise to a new proposal distribution that can be used for importance sampling, beam search, or a new hybrid approach.
We evaluate these methods across three user behavior and two language data datasets.
While all three methods significantly improve over naive forward simulation, the hybrid approach further improves over importance sampling and beam search.
We furthermore explore how the performance of all methods relates to the model entropy.
Code for this work is available at https://github.com/ajboyd2/prob_seq_queries.
Related Work
Research on efficient computation of probabilistic queries has a long history in machine learning and AI, going back to work on exact inference in multivariate graphical models [Pearl, 1988, Koller and Friedman, 2009].
Queries in this context are typically of two types.
The first are conditional probability queries , the focus of our attention here: computing probabilities defined for a subset
X of variables of interest, conditioned on a second subset Y =
y of observed variable values, and marginalizing over the set Z of all other variables.
The second type of queries can broadly be referred to as assignment queries , seeking the most likely (highest conditional probability) assignment of values x for X , again conditioned on Y =
y and marginalizing over the set Z .
Assignment queries are also referred to as most probable explanation (MPE) queries, or as maximum a posteriori (MAP) queries when Z is the empty set
[Koller et al., 2007].
For models that can be characterized with sparse Markov dependence structure, there is a significant body of work on efficient inference algorithms that can leverage such structure [Koller and Friedman, 2009], in particular for sequential models where recursive computation can be effectively leveraged [Bilmes, 2010].
However, autoregressive neural sequence models are inherently non-Markov since the real-valued current hidden state is a function of the entire history of the sequence.
Each hidden state vector induces a tree containing V k unique future trajectories with state-dependent probabilities for each path.
Techniques such as dynamic programming (used effectively in Markov-structured sequence models) are not applicable in this context, and both assignment queries and conditional probability queries are NP-hard in general Chen et al.
For assignment-type queries there has been considerable work in natural language processing with neural sequence models, particularly for the MAP problem of generating high-quality/high-probability sequences conditioned on sequence history or other conditioning information.
A variety of heuristic decoding methods have been developed and found to be useful in practice, including beam search [Sutskever et al., 2014], best-first search [Xu and Durrett, 2021], sampling methods [Holtzman et al., 2019], and hybrid variants [Shaham and Levy, 2022].
However, for conditional probability queries with neural sequence models (the focus of this paper), there has been no prior work in general on this problem to our knowledge.
While decoding techniques such as beam search can also be useful in the context of conditional probability queries, as we will see later in Section 4, such techniques have significant limitations in this context, since by definition they produce lower-bounds on the probabilities of interest and, hence, are biased estimators.
Probabilistic Queries
Notation Let X 1: N :=
[ X 1 , X 2 , . . .
, X N ] be a sequence of random variables with arbitrary length
N .
Additionally, let x 1: N :=
[ x 1 , x 2 , . . .
, x N ] be their respective observed values where each x i takes on values from a fixed vocabulary V := { 1 , . .
, V } .
Examples of these sequences include sentences where each letter or word is a single value, or streams of discrete events generated by some process or user.
We will refer to individual variable-value pairs in the sequence as events.
We consider an autoregressive model p θ ( X 1: N ) =
(cid:81)
Ni =1 p θ ( X i | X 1: i − 1 ) , parameterized by θ and trained on a given dataset of M independent draws from a ground truth distribution P ( X 1: N ) .
We assume that this model can be conditioned on a subsequence, termed the history H .
We will remap the indices of subsequent random variables to start at 1 2 .
We abbreviate conditioning on a history by an asterisk ∗ , i.e., P ∗ ( · ) :=
P ( ·|H ) and p ∗ θ ( · ) :
= p θ ( ·|H ) .
Defining Probabilistic Queries Given a specific history of events H , there are a variety of different questions one could ask about the future continuing where the history left off: (Q 1 )
What event is likely to happen next?
(Q 2 )
Which events are likely to occur k > 1 steps from now?
(Q 3 )
What is the distribution of when the next instance of a ∈ V occurs?
(Q 4 )
How likely is it that we will see event a ∈ V occur before b ∈ V ?
(Q 5 )
How likely is it for a ∈ V to occur n times in the next k steps?
We define a common framework for such queries by defining probabilistic queries to be of the form p ∗ θ ( X 1: K ∈ Q ) with Q ⊂ V K .
This can be extended to the infinite setting (i.e., p ∗ θ ([ X k ] k ∈ Q )
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
[Table]
Will
[Table]
happen
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
where Q ⊂ V ∞ ).
Exact computation of an arbitrary query is straightforward to represent:
[Equation]
X [Equation] Depending on |Q| , performing this calculation can quickly become intractable, motivating lower bounds or approximations (developed in more detail in Section 4).
In this context it is helpful to impose structure on the query Q to make subsequent estimation easier, in particular by breaking Q into the following structured partition:
[Equation]
and Q ( i ) =
[Equation]
[Equation]
where
[Equation]
K
[Equation]
In words, this means a given query Q can be broken into a partition of simpler queries Q ( i ) which take the form of a set cross product between restricted domains V ( i ) k , one domain for each token X k .
An illustration of an example query set can be seen in Fig.
A natural consequence of this is that:
[Equation]
which lends itself to more easily estimating each term in the sum.
This will be discussed in Section 4.
Queries of Interest All of the queries posed earlier in this section can be represented under the framework detailed in Eq.
(2) and Eq.
(3), as illustrated in Table 1.
Q 1 & Q
The queries p ∗ θ ( X 1 = a ) and p ∗ θ ( X K = a ) for some a ∈ V can be represented with
Q = { a } and Q = V K − 1 × { a } respectively.
Q
The probability of the next instance of a ∈ V occurring at some point in time K ≥ 1 , p ∗ θ ( τ ( a ) = K ) where τ ( · ) is the hitting time , can be represented as Q =
( V \ { a } )
K − 1 × { a } .
This can be adapted for a set A ⊂ V by replacing { a } in Q with A .
Q
The probability of a ∈ V occurring before b ∈ V , p ∗ θ ( τ ( a ) < τ ( b )) , is represented as
Q = ∪ ∞ i =
1 Q ( i ) where Q ( i ) =
( V \ { a, b } )
i − 1 × { a } .
Lower bounds to this can be computed by limiting i < i ′ .
Like Q3, this can also be extended to disjoint sets A, B ⊂ V .
Q
The probability of a ∈ V occurring n times in the next K steps, p ∗ θ ( N a ( K ) = n ) , is represented as Q = ∪ C
( K,n ) i =
Q ( i ) , where N a ( K ) is a random variable for the number of occurrences of events of type a from steps 1 to K and Q ( i ) ’s are defined to cover all unique permutations of orders of products composed of: { a } n and ( V \ { a } ) K − n .
Like above, this can easily be extended for A ⊂ V .
Query Complexity From Eq.
(1), exact computation of a query involves computing K · | Q | conditional distributions (e.g., p ∗ θ ( X k | X <k
= x <k ) ) in an autoregressive manner.
Under the structured representation, the number of conditional distributions needed is equivalently (cid:80) i (cid:81)
Kk =1 |V ( i ) k | .
Non-attention based neural sequence models often define p ∗ θ ( X k | X <k
= x <k ) :
= f θ ( h k ) where h k =
RNN θ
( h k − 1 , x k − 1 ) .
As such, the computation complexity for any individual conditional distribution remains constant with respect to sequence length.
We will refer to the complexity of this atomic action as being O (1) .
Naturally, the actual complexity depends on the model architecture and has a multiplicative scaling on the cost of computing a query.
The number of atomic operations needed to exactly compute Q 1 -Q 5 for this class of models can be found in Table 1.
Should p θ be an attention based model (e.g., a transformer [Vaswani et al., 2017]) then the time complexity of computing a single one-step-ahead distribution becomes O ( K ) , further exacerbating the exponential growth of many queries.
Note that with some particular parametric forms of p θ , query computation can be more efficient, e.g., see Appendix C for a discussion on query complexity for Markov models.
Query Estimation Methods
Since exact query computation can scale exponentially in K it is natural to consider approximation methods.
In particular we focus on importance sampling, beam search, and a hybrid of both methods.
All methods will be based on a novel proposal distribution, discussed below.
4.1 Proposal Distribution
For various estimation methods which will be discussed later, it is beneficial to have a proposal distribution q ( X 1: K = x 1: K ) whose domain matches that of the query Q .
For importance sampling, we will need this distribution as a proposal distribution, while we use it as our base model for selecting high-probability sequences in beam search.
We would like the proposal distribution to resemble our original model while also respecting the query.
One thought is to have q ( X 1: K = x 1: K ) =
p ∗ θ ( X 1: K = x 1: K | X 1: K ∈ Q ) .
However, computing this probability involves normalizing over p ∗ θ ( X 1: K ∈ Q ) which is exactly what we are trying to estimate in the first place.
Instead of restricting the joint distribution to the query, we can instead restrict every conditional distribution to the query’s restricted domain.
To see this, we first partition Q = ∪ i Q ( i ) and define an autoregressive proposal distribution for each Q ( i ) =
(cid:81)
Kk =1 V ( i ) k as follows:
[Equation]
where 1 ( · ) is the indicator function.
That is, we constrain the outcomes of each conditional probability to the restricted domains V ( i ) k and renormalize them accordingly.
To evaluate the proposal distribution’s probability, we multiply all conditional probabilities according to the chain rule.
Since the entire distribution is computed for a single model call p ∗ θ ( X k | X <k = x <k ) , it is possible to both sample a K -length sequence and compute its likelihood under q ( i ) with only K model calls.
Thus, we can efficiently sample sequences from a distribution that is both informed by the underlying model p θ and that respects the given domain Q .
As discussed in the next section, this proposal will be used for importance sampling and for the base distribution on which beam search is conducted.
4.2 Estimation Techniques
Sampling One can naively sample any arbitrary probability value using Monte Carlo samples to estimate p ∗ θ ( X 1: K ∈ Q ) =
E p ∗ θ [ 1 ( X 1: K ∈ Q )] ; however, this typically will have high variance.
This can be substantially improved upon by exclusively drawing sequences from the query space
Q .
Arbitrary queries can be written as a sum of probabilities of individual sequences, as seen in Eq.
This summation can be equivalently written as an expected value,
[Equation]
where U is a uniform distribution.
It is common for p ∗ θ to concentrate most of the available probability mass on a small subset of the total possible space V K .
Should |Q| be large, then |Q| p ∗ θ ( X 1: K = x 1: K ) will have very large variance for x 1: K ∼ U ( Q ) .
One way to mitigate this is to use importance sampling with our proposal distribution q (Section 4.1):
[Equation]
It is worth noting that this estimator could be further improved by augmenting the sampling process to produce samples without replacement from q (e.g., [Meister et al., 2021, Kool et al., 2019, Shi et al., 2020]); for the purposes of the scope of this paper we focus on sampling with replacement.
Search An alternative to estimating a query by sampling is to instead produce a lower bound,
[Equation]
where B ⊂ Q .
In many situations, only a small subset of sequences x 1: K in Q have a non-negligible probability of occurring due to the vastness of the total path space V K .
As such, it is possible for |B| ≪ |Q| while still having a minimal gap between the lower bound and the actual query value.
One way to produce a set B ⊂ Q is through beam search.
To ensure that beam search only explores the query space, instead of searching with p θ we utilize q for ranking beams.
Since beam search is a greedy algorithm and for a given conditional q ( X k = a | X <k ) ∝ p ∗ θ ( X k = a | X <k ) for a ∈ V k , the rankings will both respect the domain and be otherwise identical to using p θ to rank.
Typically, the goal of beam search is to find the most likely completion of a sequence without having to explore the entire space of possible sequences.
This is accomplished by greedily selecting the top- B most likely next step continuations, or beams , at each step into the future.
Rather than finding a few high-likelihood beams, we are more interested in accumulating a significant amount of probability and less so in the specific quantity of beams collected.
Traditional beam search has a fixed beam size B that is considered for its search; however, this is not ideal for collecting probability mass.
As an alternative we develop coverage-based beam search where at each step in a sequence we restrict the set of beams being considered not to the top- B but rather to the smallest set of beams that collectively exceed a predetermined probability mass α , referred to as the “coverage”.
4 More specifically, let B k ⊂ { x 1: k | x 1: K ∈ Q} be a set containing |B
k | beams for subsequences of length k .
For brevity, we will assume that
Q = V 1 × · · · × V K .
5 B k +1 is a subset of
B k × V k +
and is selected specifically to minimize |B k +1 | such that q ( X 1:
k +1 ∈ B k +1 ) ≥
α .
It can be shown that p ∗
[Equation]
) (and is often quite less).
See Appendix F for a proof.
There is one slight problem with having α be constant throughout the search.
Since we are pruning based on the joint probability of the entire sequence, any further continuations of B k will reduce the probability q ( X 1: k +1 ∈ B k +1 ) .
This may lead to situations in which every possible candidate sequence is kept in order to maintain minimal joint probability coverage.
This can be avoided by filtering by α k where α 1 > · · · > α K
= α , e.g., the geometric series α k
= α k/K .
A Hybrid Approach Importance sampling produces an unbiased estimate, but can still experience large variance in spite of a good proposal distribution q when p θ is a heavy tailed distribution.
Conversely, the beam search lower bound can be seen as a biased estimate with zero variance.
We can remedy the limitations of both methods by recognizing that since p ∗ θ ( X 1: K ∈ Q ) = (cid:80) x 1: K ∈B K p ∗ θ ( X 1: K = x 1: K ) + (cid:80) x 1: K ∈Q\B K p ∗ θ ( X 1: K = x 1: K ) where B K is the set of sequences resulting from beam search, we can use importance sampling on the latter summation.
The only caveat to this is that the proposal distribution must match the same domain of the summation: Q\B K .
The proposal distribution we use to accomplish this is q ( X 1: K = x 1: K | X 1: K / ∈ B K ) (see Eq. 4).
This is implemented by storing all intermediate distributions (both original p θ and proposal q ) found during beam search and arranging them into a tree structure.
All leaf nodes that are associated with x 1: K ∈ B K have their transition probability zeroed out and then the effect of restriction and normalization is propagated up the tree to their ancestor nodes (details provided in Appendix D and
E).
Sampling from this new proposal distribution involves sampling from this normalized tree until we reach either an existing K -depth leaf node, in which case we are done, or a < K -depth leaf node in which case we complete the rest of the sequence by sampling from q in Eq.
(4) as usual.
Lastly, since our ultimate goal is to sample from the long tail of p θ , targeting a specific coverage α during beam search is no longer effective since achieving meaningfully large coverage bounds for non-trivial path spaces is generally intractable.
Instead, we propose tail-splitting beam search to better match our goals.
Let w ( i ) k
= p ∗ θ ( X 1: k +1 =
x ( i ) 1: k +1 ) for x ( i ) 1: k +1 ∈ B k × V k +1 such that w ( i ) k ≥ w ( j ) k
if i < j .
In this regime, B k +1 =
{ x ( i ) 1: k +1 } Bi
=1 where B = arg min
b σ ( w (1: b ) k
[Equation]
σ ( w ( u : v ) k ) is the empirical variance of w ( i ) k for i = u, . .
. , v .
This can be seen as performing 2-means clustering on the w k ’s and taking the cluster with the higher cumulative probability.
4.3 Saving Computation on Multiple Queries
Should multiple queries need to be performed, such as p ∗ θ ( τ ( a )
= k ) for multiple values of k , then there is potential to be more efficient in computing estimates for all of them.
The feasibility of reusing intermediate computations is dependent on the set of queries considered.
For simplicity, we will consider two base queries Q = V 1 × · · · × V K and Q ′ =
V ′ 1 × · · · × V ′ K ′
where K < K ′ .
Due to the autoregressive nature of p θ , if
V i
= V ′
i for i = 1 , . .
, K − 1 then all of the distributions and sequences needed for estimating p ∗ θ ( X 1: K ∈ Q ) are guaranteed to be intermediate results found when estimating p ∗ θ ( X 1: K ′ ∈ Q ′ ) .
To be explicit, when estimating the latter query with beam search the intermediate
B K is the same as what would be directly computed for the former query.
Likewise, for importance sampling
if x 1: K ′ ∼ q
( X 1: K ′ )
using Eq.
(4) then the subsequence x 1: K ∼ q ( X 1: K ) .
This does not apply when the sample path domain is further restricted, such as with the hybrid approach, in which case we cannot directly use intermediate results to compute other queries for “free.”
Experiments and Results
Experimental Setting We investigate estimates of hitting time queries across various datasets, comparing beam search, importance sampling, and the hybrid method.
We find that hybrid systematically outperforms both pure search and sampling given a comparable computation budget across queries and datasets.
We also investigate the dependence of all three methods on the model entropy.
It is worth noting that we focus almost exclusively on hitting time queries in our primary experiments as more complex queries often decompose into operations over individual hitting times .
For example.
consider the following decomposition of the “A before B” query (Q4):
[Equation]
Decompositions of other queries and their impact on approximation error are found in Appendix B.
Datasets We evaluate our query estimation methods on three user behavior and two language sequence datasets.
Reviews [Ni et al., 2019] contains sequences of Amazon customer reviews for products belonging to one of V = 29 categories; Mobile Apps [Aliannejadi et al., 2021] consists of app usage records over V = 88 unique applications; MOOCs consists of student interaction with online course resources over V = 98 actions.
We also use the works of William Shakespeare [Shakespeare] by modeling the occurrence of V = 67 unique ASCII characters.
Lastly, we examine
WikiText [Merity et al., 2017] to explore word-level sequence modeling applications with GPT-2, a large-scale language model with a vocabulary of V = 50257 word-pieces [Radford et al., 2019, Wu et al., 2016].
After preprocessing, no datasets contain personal identifiable information.
Base Models While our proposed methods are amenable to autoregressive models of arbitrary structure, we focus our analysis specifically on recurrent neural networks.
For all datasets except
WikiText, we train Long-short Term Memory (LSTM) networks until convergence.
To explore
3 4 5 6 7 8 9 10 11 K 0 .0 .0 .0 .0 .1 .
M e d i a n
R e l a t i v e A b s .
E rr o r
Reviews
Method
ImportanceSamplingBeamSearchHybrid 3 4 5 6 7 8 9 10 11 K
MOOCs 3 4 5 6 7 8 9 10 11 K
Shakespeare 3 4 5 6 7 8 9 10 11 K
Mobile Apps
Ground truth values used to determine error are exact for K ≤ 4 and approximated otherwise.
modern applications of sequence modeling with WikiText, we utilize GPT-2 with pre-trained weights from HuggingFace
[Wolf et al., 2020].
Model training and experimentation utilized roughly
NVIDIA GeForce 2080ti GPU hours.
Please refer to Appendix G for additional details.
Experimental Methods We investigate computation-accuracy trade-offs between 3 estimation methods (beam search, importance sampling, and the hybrid) across all datasets.
Query histories H are defined by randomly sampling N = 1000 sequences from the test split for all datasets except
WikiText, from which we sample only N = 100 sequences due to computational limitations.
For each query history and method, we compute the hitting time query estimate p ∗ θ ( τ ( a ) = K ) over
K = 3 , . .
11 , with a determined by the K th symbol of the ground truth sequence.
To ensure an even comparison of query estimators, we fix the computation budget per query in terms of model calls f θ ( h k ) to be equal across all 3 methods, repeating experiments for different budget magnitudes roughly corresponding to O (10) , O (10 2 ) , O (10 3 ) model calls (see Appendix H for full details).
We intentionally select relatively small computation budgets per query to support systematic large-scale experiments over multiple queries up to relatively large values of K .
Results for queries with GPT-2 are further restricted because of computational limits and are reported separately below.
To evaluate the accuracy of the estimates for each query and method, we compute the true probability of K using exact computation for small values of K ≤ 4 .
For larger values of K , we run importance sampling with a large number of samples S , where S is adapted per query to ensure the resulting unbiased estimate has an empirical variance less than ϵ ≪ 1 (see Appendix G.3).
This computationally-expensive estimate is then used as a surrogate for ground truth in error calculations.
Coverage-based beam search is not included in our results: we found that it experiences exponential growth with respect to K and does not scale efficiently due to its probability coverage guarantees.
Additional details are provided in Appendix H.3.
Results: Accuracy and Query Horizon Using the methodology described above, for each query, we compute the relative absolute error (RAE) | p − ˆ p | /p , where ˆ p is the estimated query probability generated by a particular method and p is the ground truth probability or the surrogate estimate using importance sampling.
For each dataset, for each of the 3 levels of computation budget, for each value of K , this yields N = 1000 errors for the N queries for each method.
Fig.
3 shows the median RAE of the N queries, per method, as a function of K , for each dataset, using the medium computation budget in terms of model calls.
Across the 4 datasets the error increases systematically as K increases.
However, beam search is significantly less robust than the other methods for 3 of the 4 datasets: the error rate increases rapidly in a non-linear fashion compared to importance sampling and hybrid.
Beam search is also the most variable across datasets relative to other methods.
The hybrid method systematically outperforms importance sampling along across all 4 datasets and for all values of K .
In Appendix H we provide additional results; for the lowest and highest levels of computational budget, for mean (instead of median) RAEs, and scatter plots for specific values of K with more detailed error information.
The qualitative conclusions are consistent across all plots.
[Figure] [Figure]
- mented for 4 ≤ K ≤ 15 to highlight the regime where ground truth cannot be tractably computed.
Results: The Effect of Model Entropy We conjecture that the entropy of the proposal distribution q conditioned on a given history H ∗ q
( X 1: K ) =
− E x 1: K ∼ q [log q ( X 1: K = x 1: K )] , which we refer to as restricted entropy , is a major factor in the performance of the estimation methods.
Fig.
4(a) shows the RAE per query (with a linear fit) as a function of estimated restricted entropy for importance sampling and beam search.
The results clearly show that entropy is driving the query error in general and that the performance of beam search is much more sensitive to entropy than sampling.
The difference in entropy characteristics across datasets explains the differences in errors we see in Fig.
In particular, the Mobile Apps dataset is in a much lower entropy regime than the other 3 datasets.
To further investigate the effect of entropy, we alter each model by applying a temperature T >to every conditional factor: p θ,T ( X k | X <k )
∝ p θ ( X k | X <k ) 1 /T , effectively changing the entropy ranges for the models.
Fig. 4(b) shows the median RAE, for query p ∗ θ,T ( τ ( · ) = 4) , as a function of model temperature for the Mobile Apps data.
As predicted from Fig. 4(a), the increase in T , and corresponding increase in entropy, causes beam search’s error to converge to 1, while the sampling error goes to 0.
As T increases, each individual sequence will approach having 1 / |Q| mass, thus needing many more beams to have adequate coverage.
Results for other queries and the otherdatasets (in Appendix H) further confirm the fundamental bifurcation of error between search and sampling (that we see in Fig. 4(b)) as a function of entropy.
Results: Relative Efficiency of Proposal Distribution over Naive Query Estimation We also examine the relative efficiency improvements of our proposal distribution against naive Monte Carlo sampling:
[Equation]
Our relative efficiency calculations in Fig.
5 represent the variance ratio of naive naive sampling efficiency and often by a significant margin.
We also observe that relative efficiency is largest for shorter query horizons, approaching naive sampling efficiency as K increases.
Results: Queries with a Large Language Model We further explore entropy’s effect on query estimation with GPT-2 and the WikiText dataset for N = 100 , K = 3 , 4 , across 3 computation budgets.
With a vocabulary 500x larger than the other models, GPT-2 allows us to examine queries relevant to NLP applications.
The resulting high entropy causes beam search to fail to match surrogate ground truth given the computation budgets (consistent with earlier experiments), with a median
RAE of 82% (for K = 4 and a budget of O (10 3 ) ).
By contrast, importance sampling’s median RAE under the same setting is 13%, a 6x reduction .
Additional results are in Appendix H.5.
Discussion
Future Directions: This work provides a starting point for multiple different research directions beyond the scope of this paper.
One such direction is exploring more powerful search and sampling methods for query estimation.
This includes methods for sampling without replacement, such as the Gumbel-max method [Huijben et al., 2022, to appear], sampling importance-resampling (SIR)
[Skare et al., 2003], as well as new heuristics for automatically trading off search and sampling on a per-query basis.
Another direction for exploration is amortized methods, such as learning models before queries are issued, that are specifically designed to help answer queries.
Learning models that include queries as part of regularization terms in objective functions can also build on this work, e.g., learning models that don’t only rely on one-step-ahead losses [Meister and Cotterell, 2021].
The work in this paper could also be broadened to continuous-time models for marked temporal point processes (requiring marginalization over time as well as event types).
Limitations: Our results rely on only four datasets with a single autoregressive neural sequence model trained for each, naturally limiting the breadth of conclusions that we can draw.
However, given that the results are consistent and validated by algorithm-independent entropy and efficiency analyses, we believe these findings have general validity and provide a useful starting point for others interested in the problem of querying neural sequence models.
Another potential limitation is that our four datasets have relatively small vocabularies ( V = O (10 2 ) , small by NLP standards at least); this choice was largely driven by computational limitations in terms of being able to conduct conclusive experiments (e.g. averaging over many event histories).
Our (limited) results with GPT-2 provide clues on what may be achievable with much larger vocabularies: systematic analysis of querying for such models is a natural target for future work.
Our work also does not address the issue of model inaccuracy: our results are entirely focused on computing query estimates in terms of a model’s distribution instead of the data-generating process.
Exploring the effect of miscalibration errors in autoregressive models on k -step-ahead query estimates is a promising avenue for future work.
Potential Negative Societal Impacts: Since the focus of this work is making predictions with data that is typically generated by individuals (language, online activity), there is naturally a potential for abuse of such methods.
For example, if the underlying model in a system is miscalibrated, decisions could be made that negatively impact individuals.
Examples include recommending a student be dropped from an online course if the model incorrectly predicts they will not participate in course modules.
Even if the underlying model is well-calibrated, predictive queries could potentially be used in a proactive manner to bias decisions against individuals whose event sequences are atypical, e.g., in a chatbot context, inaccurately predicting future language patterns for certain individuals, leading to interruption and generation of an inappropriate response.
Acknowledgements: We thank the NeurIPS reviewers for their suggestions on improving the original version of this paper.
This work was supported by National Science Foundation Graduate
Research Fellowship grant DGE-1839285 (AB and SS), by an NSF CAREER Award (SM), by the
National Science Foundation under award numbers 1900644 (PS), 2003237 (SM), and 2007719 (SM), by the National Institute of Health under awards R01-AG065330-02S1 and R01-LM013344 (PS), by the Department of Energy under grant DE-SC0022331 (SM)
A Query Estimation Process and Examples (Section 1 in paper)
Below, we outline in clear terms the process of conducting query estimation experiments that we leverage in the main paper.
Furthermore, we include demonstrative examples of potential queries of interest.
Query Estimation Process
Sample a sequence x of length n from the test set.
Using a model p θ that was trained on the training split of the dataset, condition on the firstelements, x 1:5 . 3.
Then, using the proposed method of interest (e
g., importance sampling, coverage-based beam search, etc.), approximate the query of interest for the future continuation of the sequence–typically K steps into the future, x 6:6+ K .
As mentioned in lines 256 andof the main paper
the main experiments pertain to hitting time queries τ ( a ) =
K where K = 3 , . .
, 11 and a is determined as being equal to the actual value of x 6+ K from the sampled sequence.
We ensure 6 + K ≤ n . 4.
Repeat steps 1-3 over 1000 sequences (unless the dataset is WikiText, in which case dosequences).
Against either p determined by absolute ground truth, or pseudo-ground truth p computed via sampling, compute relative absolute error (RAE) of the form | ˆ p − p | p .
For a given dataset, query estimation method, and budget, compute the median RAE over all 1000 (or 100 in the case of WikiTest) sampled sequences, where a sampled sequence is a history-target tuple [ H , a ] .
MOOCs Query Example:
• History H =
[ log on , open assignment , watch lecture ] • Query Class : “A” before “B” query (Q4) • Formalism : p ∗ θ ( τ ( A ) < τ
( B ))
= p ∗ θ ( τ ( purchase ) <
τ ( log off ))
• Description :
Given a user’s online class engagement history, what is the probability that they turn in their assignment before they navigate away from the page?
Shakespeare Query Example:
• History H =
[ “t” , “h” , “o” , “u” , “<space>” ]
• Query Class : Combination query (Q5) • Formalism : p ∗ θ ( N vowel (10) = 4) • Description :
In the next 10 characters, what is the probability that 4 of them are vowels?
B Query Decomposition (Section 3 in paper)
All of the questions posed in Table 1 in the main paper can be decomposed into readily available components that our model p θ can estimate.
Should we not utilize the proposed query structure ( Q = ∪ i
V ( i ) 1 ×· · ·×V ( i ) K ) then these are the derivations that would need to be performed individually in order to compute these values exactly on a case-by-case basis.
Q
P ∗ ( X 1 ) is already naturally in a form that our model can directly estimate due to the autoregressive factorization imposed by the architecture: p ∗ θ ( X 1 ) .
Furthermore, if we are interested in any potential continuing sequence X 1: K = x 1: K this can easily be computed via p ∗ θ ( X 1: K = x 1: K ) =
(cid:81)
Kk =1 p ∗ θ ( X k = x
k | X <k = x <k ) .
Q
To evaluate p ∗ θ ( X K ) , terms X <K need to be marginalized out.
This is naturally represented like so:
[Equation]
It is helpful to show both the exact summation form as well as the expected value representation as both will be useful in Section 4.
Q
The “hitting time” or the next occurrence of a specific event type a ∈ V is defined as τ ( a ) .
Evaluating the distribution of the hitting time with our model can be done like so:
[Equation]
The value a ∈ V can be easily replaced with a set of values A ⊂ V in these representations.
[Equation]
Interestingly
[Equation]
we can see that Q 3 is a generalization of Q 2 by noting that they are identical when
A = {} .
Q
To evaluate p ∗ θ ( τ ( a ) < τ ( b )) , we must consider the possible instances where this condition is fulfilled.
In doing so
[Equation]
we end up evaluating multiple queries similar in form to Q 3 , like so:
[Equation]
In practice, computing this exactly is intractable due to it being an infinite sum.
There are two potential approaches one could take to subvert this.
The first of which is to ask a slightly different query:
[Equation]
The other option is to produce a lower bound on this expression by evaluating the sum in Eq.
(5) for the first K terms.
We can achieve error bounds on this estimate by noting that p ∗ θ ( τ ( a ) < τ ( b ))
+ p ∗ θ ( τ ( a ) > τ ( b ))
= 1 .
As such, if we evaluate Eq.
(5) up to K terms for both p ∗ θ ( τ ( a ) < τ ( b )) and p ∗ θ ( τ ( b ) < τ ( a )) , the difference between the sums will be the maximum error either lower bound can have.
Similar to Q3, we can also ask this query with sets A ⊥ B ⊂ V instead of values a, b .
[Equation]
Q
Evaluating p ∗ θ ( N a ( K ) = n ) also involves decomposing this value of interest into statements involving hitting times.
Let τ ( l ) ( a ) be the l th hitting time of a specific event of interest a .
In other words, the time of the l th occurrence of a .
Assuming n ≤ K :
[Equation]
Approximation Errors With queries that fall under the Q5 category (e.g., how likely will the event a happen n times in the next K steps?
p ∗ θ ( N a ( K ) = n ) ), while in the limiting case C(K,n) will become the dominant scaling factor for the size of the query space, in many circumstances this actually isn’t as impactful as one might expect.
For instance, it can be shown that the query space of a Q5 query is larger than that of a hitting time query (Q3) evaluated one step further (at K + 1 ) if n (cid:112) C ( K, n ) > V where V is the vocabulary size.
Looking at our main set of experiments from
Section 5, we can see that when evaluating hitting time queries up to 11 steps into the future ( K = 11 ), these queries had a slightly larger query space of than that of p ∗ θ ( N a ( K ) = n ) for K = 10 , ∀ 0 ≤ n ≤ K and thus can be seen as comparable in complexity.
This behavior easily extends to larger values of
K (e.g., K ≈ 100 ), especially for larger vocabulary sizes.
This is due to the n th root dramatically slowing down the factorial growth in the inequality shared above.
C Complexity of Predictive Querying with First-Order Markov Models
(Section 3 in paper)
As a point of reference for neural sequence models we summarize below the cost of various queries for Markov models (using basic results from the theory of finite Markov chains, e.g., see [Kemeny and Snell, 1983]).
Consider a first-order ergodic homogeneous Markov chain with a V × V transition matrix with elements p ( x k +1 | x k ) .
We analyze below the complexity of various queries for such a chain, conditioned on the current observation X
= v , where v ∈ V (this is analogous to conditioning on H for neural sequence models).
We use p ( ·| v ) as shorthand for p ( ·| X 0 = v ) .
Q2:
computing p ( X k | v )
This can be computed recursively by computing the conditional distrubution p ( X 1 | v ) , then p ( X 2 | v ) =
(cid:80) v ′ p
( X 2 | v ′ )
p ( v ′ | v ) , and so on, resulting in k matrix multiplications, with complexity O ( kV 2 ) .
Q3:
computing p ( τ ( a ) =
k | v ) For finite k , we can compute the result for all values k ′ ≤ k using k − 1 matrix multiplications where, at each step k ′ = 2 , . . .
, k − 1 , all states (events) except a are marginalized over.
Thus, the complexity is O ( kV 2 ) .
In general it is straightforward to show that
[Equation]
and
[Equation]
where p ( a | ¯ a ) is the probability of transitioning to state a given that the chain is not in state a .
Computation of p ( a | ¯ a ) requires knowledge of the steady-state probabilities of the chain π a and π ¯ a = (cid:80) v ′ ̸
= a π v ′ .
Computing the steady-state probabilities requires inversion of a V × V matrix, with a complexity of O ( V 3 ) .
This general solution will be faster to compute than the version using matrix multiplication (up to horizon k ) whenever k > V .
Q4: computing p ( τ ( a ) < τ ( b ) | v ) Let c be the set of all states (events) in V except for a and b .
It is straightforward to show that
[Equation]
and
[Equation]
where p ( a | c ) and p ( b | c ) are the probabilities of transitioning to a and b , respectively, given that the system is currently in a state that is neither a or b .
Computing these probabilities again requires knowledge of the steady-state probabilities π a , π b , π c , resulting in O ( V 3 ) time complexity.
General Queries and Higher Order Markov Models For simplicity, we will assume that a query takes the form Q = V 1 × · · · × V K and we are interested in p ( X 1: K ∈ Q|H ) for
a m th -order Markov model p .
This model can be defined with an ( m + 1)
-dimensional tensor Π
[Equation]
with elements π i 1 ,...,i m ,i m +
such that (cid:80) Vj
=
1 π
i 1 ,...,i m ,j = 1 for all i 1 , . . .
, i m ∈ V .
Alternatively, π i 1 ,...,i m ,i m +
= p ( X j + m +
= i m +1 |
X j +1:
j + m = i 1: m ) for j ≥ 0 .
To marginalize out X m +1 and compute the conditional distribution p ( X m +2 | X 1: m ) , that requires the following computation:
[Equation]
x 1 ,...,x m − 1 ,x m ,v
If we perform this over all values of x 1: m , we can construct a new transition tensor representing p ( X m +2 | X 1: m ) .
We will denote this new tensor as being equal to Π ⊗ Π where (Π ⊗ Π) i 1 ,...,i m ,v = p
( X j + m +
= v | X j +1:
j + m = i 1: m ) .
This operation has a computation complexity of O
( V m +1 ) .
This special product can be done repeatedly to further marginalize out.
For instance, performing this operation on Π ( n − 1) -times results in (Π ⊗· · ·⊗ Π) i 1 ,...,i m ,v = p
( X j + m + n = v | X j +1:
j + m = i 1: m ) , thus marginalizing out n
[Equation]
terms
[Equation]
Transitioning into a restricted space V can be done easily by defining a restricted transition tensor Π V such that (Π V )
i 1 ,...,i m ,v ∝ π
i 1 ,...,i m ,v if v ∈ V , otherwise (Π V ) i 1 ,...,i m ,v = 0 for all i 1 , . .
, i m , v ∈ V .
With this, we have everything we need to compute p ( X 1: K ∈ Q|H ) .
If the last m -values of the history
H are equal to i 1 , . .
, i m , then:
[Equation]
i m ,v .
The dominant factor in the computational complexity of this is computing all of the special products of Π .
As such, this has a total computational complexity of O (( k − 1) V m +1 ) .
D Details for the Hybrid Method (Section 4 in paper)
The hybrid method estimates an arbitrary probabilistic query p ∗ θ ( X 1: K ∈ Q ) by first using some variant of beam search (in our results we use our proposed tail-splitting beam search, see Section 3) to find a lower bound p ∗ θ ( X 1: K ∈ B ) , and then using a sampling method (we use importance sampling, see Section 3) to estimate the remainder p ∗ θ ( X 1: K ∈ Q \ B ) .
The only complicated portion of this process lies in how we derive an acceptable proposal distribution for the sampling phase that respects the domain Q \ B .
The following paragraphs detail how we construct such a distribution.
Viewing V K and p ∗ θ as Trees
In the space of all possible sequences of length K , X 1: K ∈ V K , one can represent these sequences as paths in a tree.
Each node in this tree represents a single element in a sequence X k ∈ V with depth k , with parent and children nodes representing previous and potential future values in the sequence respectively.
The root node either represents the very beginning of a sequence, or a concrete history H to condition on.
This tree can be augmented into a probabilistic one by defining edges between nodes as the conditional probability of a child node being next in a sequence, conditioned on all ancestors of that child.
These probabilities are naturally determined by p ∗ θ ( X k
=
x
k | X <k = x <k ) where x k is the child node value and x <k are the ancestors’ values.
Building the Tree Any subset of V K can also be represented as a tree, and in fact will be a sub-tree of the one that represents V K .
As such, there exists a tree that represents Q .
Our usual proposal distribution q is a natural source of conditional probabilities for the edges.
While none of these trees with their edge weights are fully known ahead of time, we do explore and uncover them through the process of beam search.
As such, during the beam search phase of the hybrid method we keep track of any conditional distributions q ( X k
=
x
k | X <k = x <k ) that are computed and use them to construct a partial view of the tree for Q .
Note that the end result of this process is a tree that will likely have many paths that do not fully reach depth K ; however, there will be at least |B| many that do.
For our purposes, it is also useful to keep track of p ∗ θ ( X k = x
k | X< k = x <k ) over this restricted set, as well as model byproducts such as hidden states to reduce computation redundancy later.
Pruning the Tree After beam search has completed, we are left with a resulting set of beams B and a probabilistic tree representing q .
We would now like to alter this tree such that its weights represent q B ( X 1: K = x 1: K ) :
=
q ( X 1: K = x 1: K | X 1: K / ∈ B ) .
This alteration can be accomplished by adjusting the edge weights in the tree recursively as detailed below.
New weight assignments will be denoted by q ′ to differentiate from old weights q .
The steps to the procedure are defined as follows:
At the final depth K , assign edge weights q ′
( X K = x K | X <K = x <K )
=
for all x 1: K ∈ B .
All other edge weights in the final depth will have new weights q ′
( X K = x K | X <K = x <K ) =
q ( X K = x K | X <K = x <K ) .
At the next layer above with depth k = K − 1 , assign edge weights as q ′ (
X k = x k | X <k
= x <k )
=
q ( X k = x
k | X <k = x <k ) (cid:80) v ∈ V q ′ (
X k +1 =
v | X ≤ k = x ≤ k ) for all sub-sequences x 1: k ∈ B . 3.
Repeat step 2 iteratively for k = K − 2 , K − 3 , . .
Finally, normalize every conditional distribution for every node whose children edges were altered such that they each sum to 1.
After these steps are completed, q B ( X 1: K = x 1: K )
= (cid:81)
Kk =1 q ′ ( X k
=
x
k | X <k = x <k ) .
Note that weights related to sequences that were not discovered during beam search, and are thus not in the tree, are not altered and still match the original proposal distribution q .
As such, to sample sequences from the tree, we start at the root node and sample from each successive conditional distribution until either depth K or a leaf node at depth k < K is reached.
In the former scenario, the sampling is complete.
In the latter, the remaining values of the sequence are sampled from q ( ·| X ≤ k = x ≤ k ) like usual.
E Variance of Estimates from the Hybrid Method (Section 4 in paper)
We are assuming to be under the hybrid method regime where a collection of sequences B ⊂ Q relevant to answering p ∗ θ ( X 1: K ∈ Q ) have been deterministically found and are interested in using sampling methods to estimate the remainder p ∗ θ ( X 1: K ∈ Q \ B ) .
For brevity, we will assume that
Q = V 1 × · · · × V K .
As mentioned in the previous section, we leverage our originally presented proposal distribution q by further restricting the domain to
Q \ B in order to be used in this scenario.
This will be represented by
[Equation]
Note that an associated autoregressive form q B ( X k = x k | X <k = x <k ) exists and is well defined; however, the exact definition is a bit unwieldy.
Please refer to the previous section for more details.
Using this proposal distribution, we can easily estimate the remaining probability:
[Equation]
Let ω B ( x 1: K ) :
= p ∗ θ ( X 1: K = x 1: K ) q B ( X 1: K = x 1: K ) and for brevity we will refer to p ∗ θ ( X 1: K ∈ Q \ B ) as ¯ ω B .
If we assume B ′ =
B∪{ ˆ x 1: K } for some ˆ x 1: K ∈ Q\B , then it is interesting to determine when exactly there will be a reduction in sampling variance for p ∗ θ ( X 1: K ∈ Q \ B ′ ) versus p ∗ θ ( X 1: K ∈ Q \ B ) as this will give insight into when the hybrid method is successful.
In other words, we would like to show when the following inequality holds true:
[Equation]
If this is true for a given ˆ x 1: K , then this finding can be applied recursively for more general (but still possibly restricted) B ′ ⊃ B .
[Equation]
It then follows that
[Equation]
We will now analyze each of the three terms in Eq.
(6) to determine when ∆ Var ≥ 0 .
For the first term, it follows that:
[Equation]
The other two terms in Eq.
(6) must sum to a positive value with as large or larger magnitude to
Eq.
(7) for ∆ Var ≥ 0 .
Looking at the second term, we see that
[Equation]
This inequality becomes strict should p ∗ θ (ˆ x 1: K ) > 0 .
We will now look at the final summation in
Eq.
[Equation]
Since all terms in Eq.
(6) have a common factor p ∗ θ (ˆ x 1: K )
[Equation]
we can see that ∆ Var ≥ 0 iff the following holds:
[Equation] [Equation]
for ρ ( x 1: K ) = (cid:81)
Kk =1 p ∗ θ ( X k ∈ V k
| X <k
= x <k ) .
Should this hold true, then by taking B ′ instead of
B during the beam search segment of the hybrid approach would the variance of the sampling subroutine reduce.
Generalizing this further, it is not guaranteed that the hybrid estimate will have a lower variance than regular importance sampling; however, our experimental results across a variety of settings (see Fig.
3 in the main paper) seem to indicate that the variance is reduced on average.
All of the terms to the left of the inequality in Eq.
(8) are quantities that would require either expansive computations or estimation in order to know their values.
Conversely, all the values to the right of the inequality are readily available as a byproduct of beam search.
Incorporating this into decision making for our hybrid method is left for future work.
F Proof for Coverage-Based Beam Search Error Upper Bound (Section 4.2 in paper)
Theorem 1.
For a given set of decoded sequences B ⊂ Q with coverage q ( X 1: K ∈ B ) , the error between the true probabilistic query value p ∗ θ ( X 1: K ∈ Q ) and the lower bound p ∗ θ ( X 1: K ∈ B ) is bounded above by the complement of the coverage:
[Equation]
Proof.
For brevity, we will assume that Q = V 1 × · · · × V K (although this can easily be extended to the general case).
Since q ( X k = x
k | X <k = x <k )
=
p ∗ θ ( X k = x k | X <k = x <k ) 1 ( x k ∈V k ) p ∗ θ ( X k ∈V k | X <k
= x <k ) and p ∗ θ ( · ) ≤ 1 , it follows that q ( X k = x k | X <k
= x <k ) ≥ p ∗ θ ( X k = x k |
X <k
= x <k ) .
This becomes a strict inequality should p ∗ θ ( X k ∈ V k
| X <k
= x <k ) < 1 (which is often the case should V k ⊂ V ).
Since this holds for arbitrary k and x k , it then follows that q ( X 1: K = x 1: K ) ≥ p ∗ θ ( X 1: K = x 1: K ) for any x 1: K ∈ Q .
This inequality becomes strict should any sequence not in the query set have non-zero probability, i.e., p ∗ θ ( X 1: K = x 1: K ) > 0 for any x 1: K ∈ V K \ Q .
The target value that we are estimating can be broken up into the following terms:
[Equation]
Rearranging these terms yields us the error of our lower bound.
We can easily derive an upper bound on the error for an arbitrary set B :
[Equation]
where α is the targeted coverage probability used to find B with coverage-based beam search.
This inequality becomes strict should any sequence not in the query set have non-zero probability, i.e., p ∗ θ ( X 1: K = x 1: K ) > 0 for any x 1: K ∈ V K \ Q .
G Experimental Setup and Preparation (Section 5 in paper)
In this section we disclose all dataset preparation and modeling details necessary for reproducing our experimental results.
G.1 Datasets
We evaluate our query estimation methods on three user behavior and two language datasets.
We provide details on the preparation and utilization of each below.
For all datasets, users are associated with anonymous aliases to remove personally identifiable information (PII).
Reviews [Ni et al., 2019] contains sequences of 233 million timestamped Amazon product reviews spanning from May 1996 to October 2018, with each product belonging to one of 30 product categories.
We restrict our consideration of this dataset to reviews generated by users with at least 15 product reviews and products with a defined category, retaining 63 million reviews on which the model was trained.
This dataset is publicly available under the Amazon.com Conditions of Use
License.
Mobile Apps [Aliannejadi et al., 2021] consists of 3.6 million app usage records from 200 Android users from September 2017 to May 2018, where each event is an interaction of an individual with an application.
User behavior spans 87 unique applications, which we use as the vocabulary for events for our experiments.
This dataset is released under the Creative Commons License, and all users contain at least 15 mobile app interactions so no data was removed before training.
MOOCs [Kumar et al., 2019] is a dataset of sequences of anonymized user interactions with online course materials from a set of massive open online courses (MOOCs).
In total, the dataset includesunique types of interactions.
Data from users with fewer than 15 interaction events are not considered, resulting in a dataset of 72% of users and 93% of the events (350,000 interactions) of the original dataset.
The MOOCs dataset is available under the MIT License.
Shakespeare We also examine character-level language models, using the complete works of
William Shakespeare [Shakespeare], comprising 125,000 lines of text and 67 unique characters and released under the Project Gutenberg License.
WikiText The WikiText-v2 dataset [Merity et al., 2017] includes word-level language data from "verified Good" and featured articles of Wikipedia.
All sentences are provided in English and the dataset is available under the Creative Commons Attribution-ShareAlike License.
G.2 Neural Sequence Models
For all datasets except WikiText (word-level language), we trained a 2-layer LSTM with a dropout rate of 0.3 and the ReLU activation function.
Each network was trained against cross entropy loss with the Adaptive Moments (Adam) optimizer initialized with a learning rate of 0.001.
A constant learning rate decay schedule and 0.01 warm-up iteration percentage was also used.
All LSTM models maintain a hidden state size of 512 except the model for Shakespeare, which possesses a reduced hidden state size of 128 to reflect the size of the dataset.
Model checkpoints were collected for all models every 2 epochs, and the checkpoint with the highest validation accuracy was selected to be used for query estimation experiments.
All models were trained on NVIDIA GeForce 2080ti GPUs.
For WikiText-v2, we leveraged the GPT-2 medium (350 million parameters) Architecture from HuggingFace with pre-trained weights provided by OpenAI.
The WikiText-v2 dataset was preprocessed using the tokenization scheme provided by HuggingFace for GPT-2, assigning numeric token indices to work pieces.
No finetuning of GPT-2 is conducted.
G.3 Ground Truth Calculations
Exact computation of ground truth is intractable for queries with large path spaces.
We circumvent this issue via the law of large numbers by computing surrogate ground truth query estimates with a large computational budget, leveraging the variance of the query’s samples as a convergence criterion.
Specifically, our algorithm is conducted as follows.
We first specify a minimum number of samples S low = 10000 to be drawn for the surrogate ground-truth estimate.
Once S low samples have been drawn, we compute the variance of our estimate ˆ p ∗ θ ( X 1: K ∈ Q ) :
= 1 S (cid:80) Si
=1 p ∗ θ ( X 1: K = x ( i ) 1: K ) q
( X 1: K = x ( i ) 1: K ) for x (1)1: K , . . .
, x ( S ) 1: K iid ∼ q ( X 1: K ) : (cid:99)
[Equation]
We then evaluate (cid:99)
Var q
[ˆ p ∗ θ ( X 1: K ∈ Q )] every 1000 additional samples until either it drops below tolerance δ = 1 e − 7 or S meets our maximum sample budget S high = 100000 .
This procedure is done in all of our experiments in which a method’s performance is being compared to a query’s ground truth value and exact ground truth cannot be computed due to resource constraints (typically when
K > 4 ).
G.4 Model Budget Determination
Each of the estimation methods that have been discussed can use varying amounts of computation depending on their configuration.
To ensure an even comparison between methods, we configure them throughout our experiments to have roughly the same amount of computation.
We measure amount of computation by the number of model calls f θ ( h k ) used within a given method.
This can be controlled directly for all of the methods except the hybrid approach.
For this reason, in our experiments we typically use fix the number of samples S for the importance sampling component of the hybrid method, where S is the number of samples used by the hybrid method after conducting tail-splitting beam search.
We then use the resulting number of total model calls used by the hybrid method (including both beam search and sampling with S samples) to determine a fixed computation budget (number of model calls to compute f θ ( h k ) ) for all other methods.
Should the hybrid method not be used in an experiment, the budget is set by determining the number of model calls used in drawing S samples for importance sampling.
H Additional Experimental Details and Results (Section 5 in paper)
This section discusses additional experimental details and results that were not included in sectionof our main paper due to space constraints.
In all experiments, all means and medians reported are with respect to N Q = 1000 randomly selected sequence locations/histories/queries per datapoint in each plot, unless stated otherwise.
For each randomly selected current location, the event a used in the query for k steps ahead
M e d i a n
R e l a t i v e A b s .
E rr o r
Reviews
Method
ImportanceSamplingBeamSearchHybrid 0 .0 .0 .0 .0 .1 .
MOOCs # Samples =0 .0 .0 .0 .0 .1 .
Shakespeare 0 .0 .0 .0 .0 .1 .
Mobile Apps 0 .0 .0 .
M e d i a n
R e l a t i v e A b s .
E rr o r
Reviews 0 .0 .0 .0 .0 .1 .
MOOCs # Samples =0 .0 .0 .0 .0 .1 .
Shakespeare 0 .0 .0 .0 .0 .1 .
Mobile Apps 3 4 5 6 7 8 9 10 11 K 0 .0 .0 .
[Figure]
M e d i a n
R e l a t i v e A b s .
E rr o r
Reviews
[Figure] [Figure]
[Figure] [Figure]
MOOCs # Samples =
[Figure]
[Figure] [Figure]
Shakespeare
[Figure] [Figure]
[Figure]
Mobile Apps method, with varying computation budgets determined by 10, 100, and 1000 samples for the hybrid method.
Ground truth values used to determine error in these plots are exact for K ≤ 4 and approximated otherwise.
H.1 Query Estimation Error as a Function of Horizon K
Fig.
3 in the main paper shows the median relative absolute error (RAE) (across N Q = 1000 queries) as a function of query horizon K for 4 datasets, comparing beam search, importance sampling, and the hybrid method, with a computation budget fixed at S = 100 hybrid samples.
Here we provide a number of extensions of these results.
Fig.
6 shows the median RAE, for three levels of computation budget: S = 10 , 100 , 1000 and Fig.shows the same results but now reporting mean RAE on the y-axis.
While the details differ across different settings, the qualitative conclusions in these Figures agree with those for Fig.
3 in the main paper, namely that beam search is more sensitive (in its error) to both the horizon query K and to individual datasets, compared to both importance sampling and the hybrid method.
More granular perspectives of this information for one of the datasets (MOOCs) can be seen in Figures 8 to 10 in the form of scatter plots of each of the individual query estimates against (surrogate) ground truth for that query.
Different budgets are shown in different figures, and the results for K = 3 , 5 , 7 , 9 , 11 are shown in each column.
H.2 Query Estimation Error as a Function of Computation Budget
In addition to identifying optimal query estimation methodologies for a low and fixed computation budget, we also explore the impact of increasing computation budget for query lengths
K = 3 , 7 , 11 , roughly corresponding to short, medium, and long horizon queries.
These experiments are conducted in the same manner as the query estimation experiments with a fixed model budget, but are then repeated for many different budgets derived from S = 10 , 30 , 50 , 100 , 300 , 500 , 1000 , 3000 , 5000 , 10000 hybrid samples.
The intention with these experiments is to observe if any query estimation methods disproportionately benefit from increased
M e a n
R e l a t i v e A b s .
E rr o r
Reviews 0 .0 .0 .0 .0 .1 .1 .
2 MOOCs
# Samples =0 .0 .0 .0 .0 .1 .1 .
2 Shakespeare 0 .0 .0 .0 .0 .1 .1 .
2 Mobile Apps 0 .0 .0 .0 .0 .
[Figure]
M e a n
R e l a t i v e A b s .
E rr o r
Reviews 0 .0 .0 .0 .0 .1 .
MOOCs # Samples =0 .0 .0 .0 .0 .1 .
Shakespeare 0 .0 .0 .0 .0 .1 .
Mobile Apps
[Figure]
i
[Figure] [Figure]
# Samples =
[Figure]
ImportanceSamplingBeamSearchHybrid
[Figure]
τ (
[Figure]
i
[Figure]
t
[Figure]
d P r o
[Figure]
a b ili t y
[Figure]
i d
[Figure]
[Figure] [Figure]
∗
[Figure]
τ ( ·
[Figure] [Figure]
computation and exhibit behavior that was not present at lower computation budgets.
We also include two additional baselines.
The full set of methods explored is listed below.
Importance sampling (informative proposal distribution q derived from model p θ ) 2.
Beam search 3.
Hybrid search and sampling 4.
Monte-Carlo sampling with a uniform proposal distribution 5.
Naive model sampling (direct MC sampling for E p ∗ θ 1 ( X 1: K ∈ Q ) )
As a clarifying point, naive sampling is conducted by sampling sequences from the model and determining if they fall within the query set Q ; the proportion of samples that exist in Q serves as a naive means of determining the query estimate in question.
In addition, Monte-Carlo sampling with a uniform proposal distribution samples sequences in Q uniformly and the estimates the query probability for that sample.
These two methods were not included in the main paper due to their consistently poor performance.
Fig.
11 (median error) and Fig.
12 (mean error), show that increasing the computation budget by an order of magnitude roughly corresponds to a three times reduction in RAE for both importance sampling and the hybrid method.
Naive sampling sees almost no benefit from the increased budget regardless of the size of the query path space.
Monte Carlo sampling sees some reduction in error from increased computation budget for some configurations, but also often sees no benefit.
[Figure] [Figure]
[Figure] [Figure]
M e d i a n
R e l a t i v e
A b s .
E rr o r f o r p ∗ θ ( τ ( · ) = 3 )
Reviews
Method ImportanceSampling
BeamSearch
Hybrid
MCSampling
NaiveSampling
[Figure] [Figure]
[Figure]
MOOCs
[Figure]
Shakespeare
[Figure]
Mobile Apps
[Figure]
M
[Figure]
d i a n
R e l a t i v e
A b s .
E rr o r f o r p ∗ θ ( τ ( · ) =
[Figure]
M e d i a n
R e l a t i v e
A b s .
E rr o r f o r p ∗ θ ( τ ( · ) =
[Figure]
For the provided budgets, the query estimates resulting from naive model sampling are consistently 0, resulting in an RAE of 1.
While naive model sampling can be useful in some contexts in general, these results indicate that it is not well-suited for estimating query probabilities.
This is likely because many of the ground truth probabilities for these queries have values on the order of 10 − 1 or smaller.
For queries that are highly unlikely under the model, the probability of even a single sampled sequence belonging to Q is very low.
Monte-Carlo sampling also includes high error estimates, but for a different reason.
Since the
Monte-Carlo estimate can be decomposed into an expectation over p ( X 1: K = x 1: K , x 1: K ∈ Q ) that is then re-scaled by |Q| ≫ 0 , the scaling term magnifies any error in the expectation dramatically, inducing extremely high variance and the potential to produce query estimates that exceed 1.
This high variance can persist even for high computation budgets.
By contrast, beam search improves with an increased computational budget, but only as a function of the total path space.
The larger the path space and the higher the entropy of the distribution, the worse the beam search estimates are as measured by RAE.
H.3 Coverage-based Beam Search Ablation
As described in the main paper, a variant of beam search well-suited to query estimation is coveragebased beam search .
However, this method was not explored further in our analysis as it could not scale to non-trivial query types and large query path spaces.
Depicted in Fig.
13, the minimum number
[Figure]
M e a n
R e l a t i v e
A b s .
E rr o r f o r p ∗ θ ( τ ( · ) = 3 )
[Figure]
M
[Figure]
n
R e l a t i v e
A b s .
E rr o r f o r p ∗ θ ( τ ( · ) = 7 )
[Figure]
M e a n
R e l a t i v e
A b s .
E rr o r f o r p ∗ θ ( τ ( · ) =
[Figure] [Figure]
[Figure]
of beams needed to cover 50%, 75%, and 90% of the query path space
increases exponentially with the query length K .
Though coverage-based beam search comes with desirable coverage guarantees and is a consistent (albeit biased) query estimator, naively applying coverage-based beam search to queries of practical interest is ill-posed and computationally intractable.
However, the hybrid method preserves some of beam search’s desirable traits while making it suitable for queries of practical interest.
See Appendix D for more information.
H.4 Long-horizon Query Estimation
The empirical results of our experiments tell us much of the abilit, but we still do not have clarity on the extent to which importance sampling can yield low-error estimates in the limit of large sequence lengths.
To that end, we conducted an experiment to directly assess the performance of importance sampling when estimating long horizons.
Our primary conclusion was that (i) with reasonable sample sizes the error remains below 25%, even at K = 100 , and (ii) the error does not increase substantially as K increases beyond K = 5 .
In more detail, a set of 100 history sequences H of length 5 was collected from each dataset.
We then compute ground truth or pseudo ground truth (PGT) for query 2 (probability of event at K without restriction) over sequence lengths K
=
Pseudo-ground truth estimates are generated with a tolerance δ = 1 e − 7 and a maximum sampling budget of 250 , 000 .
The same estimates are then computed using importance sampling with sampling budgets [10 , ..., 10000] .
Similar to the experiments in Section Section 5, we aggregate and present the results as the median relative absolute error, shown in the tables below.
Since we are not focusing on a specific event type of interest, this median also marginalizes over all event types in the vocabulary as well as the sampled query sequences.
All results are reported as percentages # Samples         31.
[Table]
[Table] [Table] [Table]
[Table] [Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table]
[Table]
5 , 10 , 20 , ..., 100 and sample budgets 10 , 100 , 1000 , 10000 for Shakespeare.
In general, we see (not surprisingly) that the increase in sequence length leads to a consistent and non-trivial increase in error for most sampling budgets.
In addition, as expected the increase in sampling budget consistently reduces the query estimation error.
However, we do witness the
[Table] [Table]
interesting phenomenon that the error occasionally decreases as the sequence length increases.
We conjecture that this may be happening because as the sequence length increases, the relevance of the history context H decreases and the distribution may regress to a base stationary distribution (as if no history context were provided at all) indicating that the conditional model entropy may be the main driving factor in estimation complexity.
This intuition is further supported by the fact that in many datasets, budgets exist where query estimation error first increases but then begins to decrease again.
Regardless, as the largest budget of 10 , 000 we witness that median RAE remains at or under 25% in all cases, often significantly so.
H.
5 Query Estimation with Large-Scale Language Models
In order to explore the feasibility of applying our query estimation methods to real-world sequence data, we also analyze a subset of our query estimation methods against GPT-2 and WikiText language data.
GPT-2 decomposes English words into V = 50257 work pieces, a vocabulary over 500 times larger than our other datasets.
For this reason, we only conduct experiments using only 100 sequence histories per dataset due to computational limitations.
For the same reason, we do not explore the hybrid method and restrict ourselves to analyzing the following query estimators:
Importance sampling (informative proposal distribution q derived from model p θ ) 2.
Beam search 3.
Monte-Carlo sampling with a uniform proposal distribution
Fixed-budget query experiments with GPT-2 are conducted identically to those on the other 4 datasets.
We find query estimation error closely mirrors the results we see in datasets with smaller vocabulary sizes, suggesting our findings may generalize well to practical domains.
Our analysis is reported in
Table 6 and includes estimates of the restricted model entropy H ( q ) for different query lengths K , with the entropy increasing much faster than small-vocabulary models, as expected.
With that said, there is still much exploration to be done on large-scale sequence models and is a promising avenue for future work.
H.6 Entropy Relationship with Query Estimation Error
Fig. 4(b) in the main paper demonstrated how indirectly controlling the entropy of a given model through an applied temperature affected the performance of beam search and importance sampling.
In Fig.
14 we can see similar plots for all of four of our main datasets.
M e d i a n
R e l a t i v e A b s .
E rr o r
Reviews
Method ImportanceSamplingBeamSearch 0.
MOOCs
[Figure]
[Figure] [Figure]
[Figure] [Figure]
Temperature
[Figure] [Figure]
[Figure]
M e d i a n
R e l a t i v e A b s .
E rr o r
Shakespeare 0.
10.0 Temperature T 0 .0 .0 .0 .0 .1 .
Mobile Apps
H.7 Investigation of Query 4 (“A" before “B")
Most of our analysis was conducted on hitting time queries, and justifiably so as more advanced queries decompose into individual operations on hitting times.
This includes Q4, colloquially stated as the probability an item from token set A occurs before an item in token set B .
More formally:
[Equation]
While this cannot be computed exactly, a lower bound can.
The other option is to produce a lower bound on this expression by evaluating the sum in Eq.
(5) for the first K terms.
We can achieve error bounds on this estimate by noting that p ∗ θ ( τ ( a ) < τ ( b ))
+ p ∗ θ ( τ ( a ) > τ ( b ))
= 1 .
As such, if we evaluate Eq.
(5) up to K terms for both p ∗ θ ( τ ( a ) < τ ( b )) and p ∗ θ ( τ ( b ) < τ ( a )) , the difference between the sums will be the maximum error either lower bound can have.
This difference will be referred to as unaccounted probability and will approach 0 as K → ∞ .
A natural question to ask is what is the minimum value of K sufficient to compute these lower bounds to in order to have negligible unaccounted probability.
Though this will surely vary based on the entropy of the model and the specific query in question, we explore this question across all datasets except WikiText and note some general trends.
Fig.
15 plots the unaccounted probability 1 − ˆ p ∗ θ ( τ ( A ) <
τ ( B )) − ˆ p ∗ θ ( τ ( A ) >
τ ( B )) as a function of query length K .
We observe that for many datasets, a query horizon of k = 30 is largely sufficient to reduce the remaining probability to under 10%.
One notable exception is the Mobile Apps dataset, which, due to its lower entropy and high self-transition rate, maintains a much longer query horizon.
This discovery implies that a successful partition of probability space with a given Q4 query can be sensitive to the model distribution, but also that approximate partitions are possible for relatively low values of K .
H.8 Linearly Compounding Errors in Complex Query Estimation
As mentioned in Section Section 5 of the main paper, hitting time queries can often be seen as components of more involved queries, such as “a” before “b” queries p ∗ θ ( τ ( a ) <
τ ( b )) or countingstyle queries p ∗ θ ( N a ( K ) = n ) .
These queries can be rewritten as summations of more basic hitting time queries.
For instance, p ∗ θ ( τ ( a ) <
τ ( b )) =
(cid:80) ∞
k =1 p ∗ θ ( τ ( a ) =
k, τ ( b ) > k ) .
In practice, each
[Figure] [Figure]
M e a n
U n a cc o un t e d
P r o b a b ili t y
Reviews
[Figure] [Figure]
[Figure] [Figure]
M e a n
U n a cc o un t e d
P r o b a b ili t y
[Figure]
summand probability is estimated using our proposed techniques so it can be seen that the error compounds additively with respect to the different basic hitting time queries.
More generally, our framework proposes representing general queries as Q = ∪ i Q
i = ∪ i (cid:81)
j V ( i ) j such that the Q i ’s form a minimal partition on Q .
With this representation, we can see that for an arbitrary query, the error when estimating will compound additively and scale linearly with respect to the number of different Q i .
Note that the actual values of p ∗ θ ( x ∈ Q i ) do have an impact on the errors when estimating due to the values ∈ [0 , 1] .
Lastly, as mentioned in the paper we can additionally control this error either by utilizing the coverage-based beam search, or by leveraging the Central
Limit Theorem with importance sampling.
H.9 Qualitative Exploration and Practical Applications
In addition to systematic quantitative analysis of query estimators, we also qualitatively explore specific applications of our methods that lend practical insights.
First, we consider the question of “given a partial sentence, predict when the sentence will end".
Using our query estimation methods, we can not only answer this question with relatively low error but also effectively re-use intermediate computational results.
This necessarily correlates query estimates over steps K , but this confers little negative impact upon the analysis since our sampling methods are unbiased estimators and beam search, though biased, offers a deterministic lower bound.
The results of our analysis are seen in
Fig.
1 in the main paper and align with basic intuition about English sentences, with open ended prefixes possessing a long-tailed end-of-sentence probability distribution relative to more structured and declarative phrases.
A second practical question that can be asked with our query estimation methods utilizes the Mobile
Apps dataset: given someone’s mobile usage history, predict what will occur first: the individual will go on social media or directly interact with someone via video chat, call, text, or email.
This question is a practical application of query 4, p ∗ θ ( τ ( a ) <
τ ( b )) .
Other, equally interesting equivalents of this question include “will an online shopper purchase something before leaving the website?".
Below, we have conducted an experiment where we synthetically generate mobile app behavior histories with specific percentages of social media activity present.
By computing these queries over several histories and then averaging the estimates, we obtain the results seen in Fig.
As expected, we see a clear linear trend between a user’s social media usage and the likelihood they will return to
[Figure]
E s t i m a t e d P
r o b a b ili t y it before conducting other tasks like directly communication.
Such a result, though contrived and purely demonstrative in this setting, could be applied to many practical applications that analyze the characteristics of online user behavior.