Title: Training Chain-of-Thought via Latent-Variable Inference
Venue: NeurIPS 2023
Accepted: yes
Keywords: Large language models

latent-variable models

control variates

chain-of-thought

MCMC
Abstract: Large language models (LLMs) solve problems more accurately and interpretably when instructed to work out the answer step by step using a "chain-of-thought" (CoT) prompt. One can also improve LLMs' performance on a specific task by supervised fine-tuning, i.e., by using gradient ascent on some tunable parameters to maximize the average log-likelihood of correct answers from a labeled training set. 
Naively combining CoT with supervised tuning requires supervision not just of the correct answers, but also of detailed rationales that lead to those answers; these rationales are expensive to produce by hand. Instead, we propose a fine-tuning strategy that tries to maximize the \emph{marginal} log-likelihood of generating a correct answer using CoT prompting, approximately averaging over all possible rationales. The core challenge is sampling from the posterior over rationales conditioned on the correct answer; we address it using a simple Markov-chain Monte Carlo (MCMC) expectation-maximization (EM) algorithm inspired by the self-taught reasoner (STaR), memoized wake-sleep, Markovian score climbing, and persistent contrastive divergence. This algorithm also admits a novel control-variate technique that drives the variance of our gradient estimates to zero as the model improves. Applying our technique to GSM8K and the tasks in BIG-Bench Hard, we find that this MCMC-EM fine-tuning technique typically improves the model's accuracy on held-out examples more than STaR or prompt-tuning with or without CoT.

Training Chain-of-Thought via Latent-Variable Inference

Abstract

Large language models (LLMs) solve problems more accurately and interpretably when instructed to work out the answer step by step using a 'chain-of-thought' (CoT) prompt. One can also improve LLMs' performance on a specific task by supervised fine-tuning, i.e., by using gradient ascent on some tunable parameters to maximize the average log-likelihood of correct answers from a labeled training set. Naively combining CoT with supervised tuning requires supervision not just of the correct answers, but also of detailed rationales that lead to those answers; these rationales are expensive to produce by hand. Instead, we propose a fine-tuning strategy that tries to maximize the marginal log-likelihood of generating a correct answer using CoT prompting, approximately averaging over all possible rationales. The core challenge is sampling from the posterior over rationales conditioned on the correct answer; we address it using a simple Markov-chain Monte Carlo (MCMC) expectation-maximization (EM) algorithm inspired by the self-taught reasoner (STaR), memoized wake-sleep, Markovian score climbing, and persistent contrastive divergence. This algorithm also admits a novel control-variate technique that drives the variance of our gradient estimates to zero as the model improves. Applying our technique to GSM8K and the tasks in BIG-Bench Hard, we find that this MCMC-EM fine-tuning technique typically improves the model's accuracy on held-out examples more than STaR or prompt-tuning with or without CoT.

1 Introduction

For many mathematical, logical, and common-sense reasoning problems, large language models solve problems more accurately when instructed to work out the answer step by step in a chain of thought or a scratchpad (Wei et al., 2022; Nye et al., 2021; Kojima et al., 2022; Rajani et al., 2019; Shwartz et al., 2020). These methods encourage the model to produce a rationale , that is, text describing a sequence of reasoning steps that leads to an answer; the motivation is that it seems to be easier for the model to generate a sequence of correct reasoning steps than to generate the final answer directly. Because of the striking performance of chain-of-thought methods, many variants have been proposed (Wang et al., 2022b; Zhou et al., 2022; Creswell et al., 2022; Ye & Durrett, 2023), but there are still many cases in which the rationales are incorrect.

One way to improve these methods is to fine-tune models to generate better rationales. If goldstandard rationales can be obtained, such as via crowdsourcing (Rajani et al., 2019) or automatically (Nye et al., 2021), then supervised methods can be applied, but obtaining this data can be difficult. An appealing alternative is to start from datasets that contain questions and correct answers only, which are more readily available, and bootstrap rationales during learning. A version of this strategy

was proposed as the self-taught reasoner (STaR) (Zelikman et al., 2022), which generates proposed rationales from an LLM, and then fine-tunes on rationales that lead to the correct answer.

In this paper, we approach the problem of bootstrapping rationales from a different conceptual direction: chain-of-thought methods are probabilistic latent-variable models . The LLM defines a joint probability distribution over questions, rationales, and answers; this joint distribution implies a marginal distribution of answers given questions, averaging over all possible rationales weighted by their probability given the question. The problem of self-training for reasoning then becomes one of learning with incomplete data, a core task in probabilistic machine learning (Murphy, 2022) to which we can apply methods from a large and sophisticated literature.

This perspective raises a technical challenge, because computing the marginal distribution requires averaging over a vast set of potential rationales. To address this, we introduce a learning algorithm for rationale generation, which we call TRICE. 3 TRICE is a simple Markov-chain Monte Carlo (MCMC) expectation-maximization (EM) algorithm combined with a novel control-variate scheme, inspired by ideas from STaR (Zelikman et al., 2022), memoized wake-sleep (Hewitt et al., 2020), Markovian score climbing (Naesseth et al., 2020), and persistent contrastive divergence (Tieleman, 2008).

This view unifies several threads of work in reasoning using LLMs: It provides an alternative interpretation of STaR as a kind of biased stochastic expectation-maximization algorithm (Nielsen, 2000) that underweights difficult examples when its rationalization process fails. Self-consistency (Wang et al., 2022a) can be seen as a Monte Carlo algorithm for computing the most likely answer under the marginal distribution. Compared to self-consistency, the probabilistic learning approach of TRICE allows us to average over rationales not only at inference time, but also at training time . Compared to STaR, TRICE is less likely to ignore difficult examples (which stabilizes convergence and improves performance), and is also able to learn from incorrect rationales as well as correct ones.

We apply our technique to the GSM8K dataset (Cobbe et al., 2021) and to the BIG-Bench Hard benchmark (Suzgun et al., 2022a). We find that TRICE improves the model's performance significantly, outperforming models tuned with STaR, direct tuning with or without CoT, and even supervised fine-tuning on human-generated rationales.

2 Method

Given a training set of N questions x 1: N and answers y 1: N , we formalize CoT tuning as optimizing a parameter vector θ to maximize the average marginal log-likelihood of answers given questions:

where z is an unobserved latent rationale, p θ ( z | x ) is the probability 4 of obtaining the rationale z by prompting an LLM with the question x and tunable parameters θ , and p θ ( y | z, x ) is the probability of obtaining the answer y given rationale z , question x , and parameters θ . We will be particularly interested in models where the likelihood p θ ( y | x, z ) ∈ { 0 , 1 } , that is, where the answer y is a deterministic function of z . For example, we might say that the model's answer is y = '(a)' if z ends with the string "The answer is (a)." For this deterministic model, we define p ( y | z, x ) = c ( z, y ) ∈ { 0 , 1 } . Details of c ( z, y ) for each task can be found in Appendix F. We believe that such a binary likelihood model is appropriate for question-answering tasks where z is a rationale-a good rationale should leave no ambiguity about the correct answer. The derivations below will therefore assume a binary likelihood function. It is straightforward to generalize our methods to cases where the relationship between z and y is weaker and therefore p ( y | x, z ) is more complicated; Appendix A shows how.

Algorithm 1 outlines the method. A notebook with a reference implementation can be found at https://github.com/google-research/cascades/tree/main/cascades/ examples/notebooks/trice.ipynb .

We start by initializing a memory containing a latent rationale z n for each example pair x n , y n by sampling z n from a hinted guide distribution q ( z | x n , y n ) that may condition on the correct answer y n as well as the question x n . For example, the guide might prompt an LLM specifically to give an

rationale for the answer; more details about the precise prompts used by the guide are in Appendix F. In some cases sampling from the guide instead of the model p θ ( z | x n ) increases the chances of generating a correct rationale (Zelikman et al., 2022).

We then proceed to the main optimization loop. Each iteration, we sample a minibatch of M questions and answers from the dataset, and retrieve the rationales associated with those examples from the memory. We then propose new rationales ˜ z from the current model p θ ( z | x ) , and whenever the new rationale ˜ z is correct (i.e., c (˜ z, y ) = 1 ) replace the old rationale in memory with the new one.

At this point we have all we need to compute a gradient estimate; we can just average the gradients ∇ θ log p θ ( z i m | x i m ) that we obtain from those rationales in the updated memory that are correct (i.e., we ignore examples where both the proposed rationale and the previous rationale were wrong). BASIC_GRADIENT_ESTIMATE in Algorithm 1 shows how.

But we can also reduce the variance of our gradient estimator by incorporating a control variate, as in CONTROL_VARIATE_GRADIENT_ESTIMATE in Algorithm 1. We first compute leave-one-out estimates β 1: M of the average probability of accepting a new rationale. For each example m , we subtract off a scaled control variate β m ∇ θ log p θ (˜ z m | x i m ) whose expected value is zero (since it is a score function). If the proposed rationale ˜ z m for example m is correct, then z i m = ˜ z m , and the m th gradient contribution becomes (1 -β m ) ∇ θ log p θ ( z i m | x i m ) , i.e., it is scaled down by 1 -β m . If ˜ z m is incorrect, then we adjust the gradient estimate to try to make ˜ z m less likely under p θ . As the model becomes more accurate (i.e., β gets closer to 1), we give more weight to incorrect rationales (when they occur) and less weight to correct rationales (most of the time).

CONTROL_VARIATE_GRADIENT_ESTIMATE is more expensive than BASIC_GRADIENT_ESTIMATE, since we must compute gradients not only for the rationales in memory but also for any incorrect rationales we generate. This may be wasteful, especially if many of the weights on those gradients ( 1 -β for correct proposals, β for incorrect proposals) are close to zero because β is close to zero or one. To reduce this cost, in SUBSAMPLED_CONTROL_VARIATE_GRADIENT_ESTIMATE, we use systematic resampling (Hol et al., 2006) to generate a subsample of L question-rationale pairs, from which we obtain an unbiased estimate of the output of CONTROL_VARIATE_GRADIENT_ESTIMATE. We preferentially sample gradients with higher scalar weights; if β is small, we are less likely to sample incorrect rationales (which have weight β ), and if β is large, we are less likely to sample correct proposed rationales (which have weight 1 -β ). This can be seen as a generalization of the strategy of Burda et al. (2015, Section 3) for reducing the cost of computing IWAE gradients.

Below, we derive this variance-reduced stochastic MCMC-EM procedure in more detail.

2.1 Derivation

The true gradient. The gradient of the marginal log-likelihood log p θ ( y | x ) with respect to θ is

that is, it is the expectation with respect to the posterior p θ ( z | x, y ) of the gradient of the conditional log-prior log p θ ( z | x ) , since the likelihood p ( y | z, x ) = c ( z, y ) does not depend on θ . So if we can sample from the posterior over rationales z conditioned on the question-answer pair x, y , then we can compute an unbiased estimate of the gradient of the marginal log-likelihood log p θ ( y | x ) . We can interpret this as 'bootstrapping' rationales z that are consistent with both the prior on rationales p θ ( z | x ) and the observed answer y (cf. Zelikman et al., 2022).

Independence sampler for p θ ( z | x, y ) . We cannot directly sample from p θ ( z | x, y ) , so we resort to Markov chain Monte Carlo (MCMC). We maintain a memory (cf. Hewitt et al., 2020) of a single rationale z n for each question-answer pair x n , y n , and each iteration we apply a random update to z n that leaves the posterior p θ ( z n | x n , y n ) invariant (cf. Tieleman, 2008). Each MCMC update brings the z n 's closer in distribution to p θ ( z n | x n , y n ) (Cover, 1999; Murray & Salakhutdinov, 2008). However, updates to θ may change the posterior p θ ( z n | x n , y n ) , so we must keep updating the chains to control the bias of our gradient estimates.

To update the chains, we use a simple, hyperparameter-free independence sampler (Tierney, 1994); a Metropolis-Hastings (Hastings, 1970) update that proposes updating the current state z with a draw ˜ z from a distribution r x,y that does not depend on z , and accepts the update with probability

Algorithm 1 TRICE

Input: Generative model p θ ( z, y | x ) , is-correct function c ( z, y ) , dataset x 1: N , y 1: N , hinted guide distribution q ( z | x, y ) , initial parameters θ , optimizer update function h ( θ, g, t ) , minibatch size M , gradient minibatch size L , number of iterations T .

Remarks: Independence samplers can be understood as 'Metropolized' importance samplers that spread the work of generating and evaluating proposals over time. In our setting, the update can also be interpreted as attempting to sample from the posterior by rejection sampling, then falling back on an old sample if that fails. The expected number of iterations between successful updates is p ( y | x ) -1 , so mixing will be faster for easier questions x , and will accelerate as the model improves.

Basic gradient estimator. This MCMC/rejection-sampling procedure lets us approximate the gradient of the marginal log-likelihood in Equation (2). Denoting as z the state 5 of the Markov chain for an example x, y before the update, we sample a proposal ˜ z from p θ ( z | x ) , accept the new state if it is correct (i.e., if c (˜ z, y ) = 1 ), and compute the gradient of the log-probability of the result:

where E z, ˜ z [ · | θ ] denotes an expectation with respect to both the proposal ˜ z and the previous state z .

Remarks: The estimate will have low bias if the distribution of z ′ is close to the posterior p ( z | x, y ) , which we expect to be true if the chain is mixing quickly enough relative to how fast θ is changing. This will happen if either the probability of getting a correct answer is high, or if θ is changing slowly due to a small learning rate and/or gradient. If the model's training-set accuracy improves with training and we use a decaying learning-rate schedule, then as training proceeds both of these factors should work to reduce the bias of the gradient estimate.

Adding a control variate. The mean of an estimator ˆ g is not affected by subtracting a zero-mean random variable b from it. If b is positively correlated with ˆ g , then ˆ g -b can have lower variance than ˆ g , and we say that b can be used as a 'control variate' (Owen & Zhou, 2000). Since, by the score-function identity, E p z | x [ β ∇ θ log p θ ( z | x )] = 0 (for any scalar β independent of z ), we can use the proposed samples ˜ z to generate control variates for our gradient estimator:

Remarks: The value of this estimator will depend on whether or not we accept the proposal ˜ z :

where we use the shorthand ˜ c glyph[defines] c (˜ z, y ) .

This control variate can drive the variance of the gradient estimator to zero as the model converges to perfect accuracy on the training set (cf. Roeder et al., 2017). If we set β = π , where π is the probability of a correct answer (i.e., that ˜ c = 1 ), then as π gets large, most of the time ˜ c = 1 and we multiply our gradient estimator by 1 -π (multiplying its variance by a factor of (1 -π ) 2 ). If ˜ c = 0 , then we make use of both a correct and incorrect rationale; the weights attached to these updates will not be small, but if incorrect rationales are relatively rare then their contribution to the variance of the gradient estimator will be correspondingly small. On the other hand, if the model has not yet learned to frequently generate good rationales for the training examples, then we should set β closer to 0, since in this case the signal from the incorrect rationale is less informative-in Appendix C.1 we show that the variance of gradient estimators based on incorrect rationales depends strongly on the model's accuracy π . In Appendix B, we show that choosing β = π is in fact optimal up to O ((1 -π ) 2 ) terms, and that the variance of the resulting estimator is proportional to 1 -π .

Estimating β . For each example x m , y m , we need to compute a β m ≈ E [˜ c m ] in a way that ensures that β m is independent of ∇ θ log p θ (˜ z m | x m ) . We assume that E [˜ c m ] ≈ 1 M ∑ m E [˜ c m ] (i.e., that the per-example acceptance probability is close to the average acceptance probability across the minibatch 6 ), and compute the leave-one-out estimate β m = ∑ m ′ glyph[negationslash] = m c ′ m ′ ˜ c m ′ ∑ m ′ glyph[negationslash] = m c ′ m ′ , where c ′ m := c ( z ′ m , y ) .

We restrict the estimate to consider only examples for which we have a correct rationale (i.e., where c ′ m = 1 ), since these are the only examples that influence our gradient estimate. Leaving out ˜ c m and c ′ m from the estimate β m ensures that β m is independent of ˜ z m .

Gradient subsampling. Finally, as described above, we can reduce the cost of our gradient estimator by using systematic resampling to select a subset of rationales. This does not affect the expected value of the estimator as long as the marginal probability of selecting a rationale is proportional to the corresponding weight ˜ w m , and the averaged gradient is reweighted by ∑ 2 m M =1 ˜ w m ∑ m c ′ m .

2.2 Why not variational inference, reweighted wake-sleep, or rejection sampling?

We considered three alternatives to the MCMC-EM approach that we pursue in this paper: variational EM (e.g., Bishop, 2006), reweighted wake-sleep (RWS; Bornschein & Bengio, 2015; Le et al., 2019), and rejection sampling.

Variational expectation-maximization is a common strategy for training latent-variable models, but variational inference with discrete latent variables is challenging (e.g., Tucker et al., 2017).

RWS is an attractive alternative that avoids high-variance score-function gradients; it proceeds by sampling M samples z 1: M from a guide model q φ ( z | x, y ) , assigning the samples weights w m ∝ p θ ( y,z | x ) q φ ( z | x,y ) , and updating both the model parameters θ and the guide parameters φ to maximize the reweighted log-probabilities ∑ m w m log p θ ( z m | x ) and ∑ m w m log q φ ( z m | x, y ) . Unfortunately, we found that RWS training sometimes led to degenerate zero-length rationales z . Figure 1 suggests a partial explanation: shorter sequences get higher weights, so the model and guide learn to produce shorter and shorter sequences until they consistently produce empty rationales.

Why do longer sequences tend to get lower weights? We can write the unnormalized weights as ˜ w m = c ( y, z m ) p θ ( z m | x ) q φ ( z m | x,y ) = c ( y, z m ) ∏ T m t =1 p θ ( z m,t | x,z m, 1:( t -1) ) q φ ( z m,t | x,y,z m, 1:( t -1) ) , where T m is the length of z m and glyph[epsilon1] is added to address the case where none of the samples are correct. If there is a mismatch between q ( z m,t | x, z m, 1:( t -1) )) and p ( z m,t | x, z m, 1:( t -1) ) , then p θ ( z m,t | x,z m, 1:( t -1) ) q φ ( z m,t | x,y,z m, 1:( t -1) ) will usually be less than one, with rare high-weight exceptions that ensure that E q [ p ( z | x ) /q ( z | x )] = 1 .

If these exceptions are rare enough to not typically appear in a sample of M sequences z 1: M , then the normalized weights w 1: M = ˜ w 1: M ∑ m ˜ w m will tend to assign higher mass to shorter sequences unless those shorter sequences are much less likely to be correct.

With careful initialization and learning-rate tuning, we could sometimes get RWS to avoid this problem

(

(

((

((

((

((

((

((

((

((

((

(((

(((

(⌉(˜(∐({(((√(((√(∐(⌉(√(⌈(˜(((⌈(˜({(˜(√([(√

(glyph[arrowvertexdbl](˜(](˜([(√(˜(̂(((⌉(˜(∐({(((√(((√(∐(⌉(√(⌈(˜(((⌈(˜({(˜(√([(√

(](√(˜(√(∐(√(](}({

of empty rationales. But this led to a new problem: the guide q φ ( z | x, y ) learned to closely mimic the prior p ( z | x ) until the very end of the rationale, and then simply paste in the correct answer whether or not it had anything to do with the rationale up to that point (cf. Turpin et al., 2023). Figure 5 in Appendix E shows a representative example in which the guide model ignores the answer it arrived at through incorrect reasoning and pastes in the correct answer.

Quantitatively, denoting by t the index of the token at which the 'final answer' section of the rationale begins, in one run we found that the average KL between q ( z 1: t | x, y ) and p ( z 1: t | x ) was about 0 . 61 nats, while the conditional KL between q ( z ( t +1): T | x, y, z 1: t ) and p ( z ( t +1): T | x, z 1: t ) was about 42 . 5 nats, confirming that the guide was not 'reasoning backwards', just copying the correct answer.

Finally, we considered a rejection-sampling 7 scheme in which we sample K proposal rationales z 1: K from p ( z | x ) , and average the gradients from those rationales that lead to correct answers. We will present the quantitative results in Section 4; our main finding is that, while this scheme can work, it requires reducing the minibatch size by a factor of K to keep the per-iteration cost constant compared to TRICE, which in turn leads to slower convergence and/or worse final results.

3 Related Work

Anumber of methods have proposed rationale generation for problem-solving tasks in neural sequence models, including both fully supervised and few-shot approaches (Wei et al., 2022; Nye et al., 2021; Kojima et al., 2022; Rajani et al., 2019; Shwartz et al., 2020; Wang et al., 2022b; Zhou et al., 2022; Creswell et al., 2022; Ye & Durrett, 2023). Particularly relevant to our approach is self-consistent chain-of-thought (Wang et al., 2022b), because this can be approximately viewed as marginalizing over rationales at test time. This technique has been successfully applied for a range of quantitative reasoning tasks (Lewkowycz et al., 2022). There is relatively much less work that does imputation or averaging over rationales at training time; perhaps the main instance is STaR (Zelikman et al., 2022), which we discuss in Section 3.1.

Dohan et al. (2022) present a position paper which advocates representing a composition of language model interactions via probabilistic programming. Our treatment of rationales as latent variables is inspired by that work. Lievin (2022) offers another example of interpreting LLMs with CoT as latent-variable models.

Variational inference (e.g., Kingma & Welling, 2013) and wake-sleep methods (e.g., Bornschein & Bengio, 2015) are workhorses of the latent-variable-modeling community, but as we discuss in Section 2.2 we found the bias of these methods to cause serious problems. MCMC-EM is a lesscommon strategy these days, although a version of it based on Gibbs sampling (Geman & Geman, 1984) it has been widely applied to training undirected graphical models (Tieleman, 2008). TRICE can also be cast as an instance of Markovian score climbing (Naesseth et al., 2020).

ReAct (Yao et al., 2023) demonstrated that injecting reasoning into an RL-style observe-and-act loop significantly increases performance. This approach was extended in Reflexion (Shinn et al., 2023), where an agent can conditionally reflect on an RL trajectory, augmenting the resulting examples which can be used as few-shot examples in subsequent rollouts. These approaches reported significant improvements on their respective evaluation tasks but still rely on the model being able to produce useful and actionable feedback through pure few-shot prompting, whereas our method actively tunes the model to produce thoughts amenable to the task.

Recent work on tool-use within language models also works via imputation, inferring where to insert calls to tools (Parisi et al., 2022; Schick et al., 2023). Their loss functions are similar in spirit to ours, filtering out trajectories which do not lead to valid answers. In this paper, we have treated rationales as latent variables; one could also treat tool-use as a latent variable.

3.1 Self-Taught Reasoner

The most closely related work is the self-taught reasoner (STaR; Zelikman et al., 2022). Besides the arguments in their derivations, there are three significant differences between TRICE and STaR. First, STaR uses greedy decoding, which reduces the diversity of the rationales it trains on. The authors made this choice to reduce the danger of the model getting the right answer despite having a bad rationale. While we do find that our procedure sometimes generates correct answers for the wrong reasons, this did not seem to stand in the way of the model improving on most tasks. One reason may be that our base models are more powerful than the 6B-parameter GPT-J model used in the STaR paper, so they are more likely to generate good rationales from the beginning.

A second difference is that TRICE resamples rationales every iteration, so it are less likely to overfit to any particular rationale. STaR has an inner loop that runs many training iterations on a single set of rationales, meaning it uses stale rationales to estimate the gradient of the marginal likelihood.

In our experiments, we observed that this leads to the model effectively memorizing a fixed set of rationales for the training set. Once this happens, the greedy decoding procedure will almost certainly reproduce exactly the same rationales at the beginning of the next outer loop. If these rationales all lead to the correct answer, and STaR has a rationale for each question, then this is a global optimum of the marginal likelihood on the training set! But empirically, STaR often does not find a good rationale for each question, and so it ignores some fraction of the training set (see Section 4).

This tendency to ignore the most difficult questions in the training set follows from STaR's derivation as an approximate policy-gradient algorithm trying to directly minimize the 0-1 loss E p [1 -c ( z, y )] = 1 -p θ ( y | x ) . The derivative of this marginal likelihood is p θ ( y | x ) ∇ θ log p θ ( y | x ) , that is, it is the derivative of the marginal log -likelihood (which TRICE tries to maximize) weighted by p θ ( y | x ) . This weighting causes difficult examples to contribute little to the gradient used to update the model, so the model may 'give up' on questions that it cannot yet solve. This is one argument for trying to maximize log-likelihoods instead of likelihoods.

A final, minor difference is that when STaR updates its rationales, it may replace a rationale from the model p ( z | x ) with a rationale from a surrogate q θ ( z | x, y ) . As the model memorizes a set of correct rationales for the training set, STaR becomes less likely to fall back on the surrogate, but this choice could affect early training dynamics.

4 Experiments

We evaluate TRICE on the GSM8K (Cobbe et al., 2021) dataset and the 27 BigBench-Hard (BBH) tasks (Suzgun et al., 2022b) using the medium-size PaLM 2-M (Anil et al., 2023) Transformer-based LLM (Vaswani et al., 2017). For the BBH experiments, we used the Flan instruction-tuned (Chung et al., 2022) version of PaLM 2; for GSM8K, we used the base PaLM 2 model, since GSM8K is included in the Flan training datasets. All experiments were run on TPU v4 and v5e chips (Jouppi et al., 2023). Examples of generated rationales can be found in Appendix E.

Rather than fine-tune the model weights, we use prompt tuning (Lester et al., 2021); we prepend a sequence of embedding vectors θ (a 'soft prompt') to the embeddings corresponding to the tokenized CoT prompt used to condition the model. Prompt tuning can achieve similar accuracy gains to full fine-tuning, but using a small fraction of the parameters. We initialize the soft prompt with the embedding sequence obtained from a series of three (for BBH) or five (for GSM8K) exemplar CoT prompts, each of the form ' Question: <QUESTION>\nAnswer: Let's think step by step.\n<RATIONALE> '. We consider two initialization schemes: one where we use the standard few-shot CoT prompts that are provided with BBH, and one where we try to bootstrap a few-shot CoT prompt by sampling random questions from the training set, generating random rationales from the base model, and picking three or five examples where the random rationales lead to correct answers. The first scheme can be seen as a way of fine-tuning a good initial few-shot prompt, but it does require a small amount of detailed CoT supervision, while the second scheme only requires label supervision.

On each BBH task, we split the examples into 60 % train and 40 % test sets. For all but three tasks, this is 150 training and 100 test examples. For GSM8K, we use the standard 7473 -example training set and 1319 -example test set. We evaluate CoT models' accuracy in two ways: first, using greedy (temperature-0) decoding, and second, using 'self-consistency' (Wang et al., 2022b). In self-consistency evaluation, we draw 40 samples and check whether the most common answer is correct; this is a plug-in estimator for the prediction arg max y p ( y | x ) that minimizes 0-1 loss under the model (although this is not how Wang et al. (2022b) originally motivated the procedure).

We compare against four baseline prompt-tuning methods: direct prompt tuning, CoT prompt tuning, rejection sampling, and STaR (Zelikman et al., 2022). All methods are evaluated against the same validation sets, and use the same training labels, few-shot prompts (except for direct tuning, where we only use question-answer pairs), and initialization strategies as appropriate. Details for each method and its corresponding experimental hyperparameters can be found in Appendix F.

Table 1 and Table 2 summarize the results; more detailed task-by-task BBH summaries are in Appendix D. Even with no human-generated exemplar rationales, TRICE is able to learn to generate rationales that lead to the correct answer. TRICE also outperforms a model trained directly on human-generated rationales on GSM8K (cf. Uesato et al., 2022), perhaps because the cross-entropy

loss used in supervised fine-tuning may place more weight on style than substance; it takes far more bits to encode how one expresses a chain of reasoning than it does to encode the reasons themselves.

Initializing the soft prompt with a human-generated 3-shot exemplar question-rationale-answer prompt slightly improves performance on BBH, as does evaluating with self-consistency. By the end of training, TRICE has managed to generate at least one valid rationale for almost all training examples, while STaR fails to generate valid rationales for almost 10% of training examples. Unlike in the experiments done on Commonsense QA (Talmor et al., 2019) by Zelikman et al. (2022), STaR does not outperform the direct-prompted prompt-tuned model on BBH. This may be because each BBH task includes relatively little training data (150 examples as opposed to CommonsenseQA's 9,741), and so in its inner loop STaR overfits to its relatively small set of bootstrapped rationales. TRICE, on the other hand, can overfit to the small set of questions but at least has a chance to generate a somewhat diverse set of rationales from those questions.

One piece of evidence for this overfitting-rationales hypothesis is that on the final step of its final inner loop, STaR (with bootstrapped initialization) achieves a training sequence-level ( not per-token) cross-entropy loss of less than 0.06 on all tasks, and of less than 0.01 on 19 out of 27 tasks. This implies that it has learned to exactly reproduce a single set of rationales with very high probability, which makes it very likely that it will generate those same rationales in the next iteration.

Figure 2 compares estimates for GSM8K of the average training marginal likelihood (i.e., how often a proposal is accepted) and the validation accuracy with greedy decoding as a function of number of

0

1000

2000

3000

4000

5000

0.4

0.6

0.8

Train Accuracy

0

1000

2000

3000

4000

5000

0.5

0.6

0.7

Test Accuracy

step

value

Method

RS

TRICE CV

TRICE no CV

training steps 8 for rejection sampling and for TRICE with and without the control-variate scheme. The control-variate scheme improves average convergence speed, particularly towards the end of training as the probability of generating correct answers on the training set increases. Both versions of TRICE converge to high training accuracy much faster than rejection sampling.

5 Discussion

We proposed TRICE, a method for tuning LLMs to be better at solving question-answering tasks using chain-of-thought (CoT) prompting. By framing the CoT-prompted LLM as a latent-variable model, we were able to derive a principled and effective fine-tuning method. When applied to GSM8K and BIG-Bench Hard (BBH) tasks, TRICE outperforms three strong baselines: direct prompt-tuning, STaR, and rejection sampling. While we derived TRICE in the context of CoT question-answering, its basic MCMC-EM strategy could be employed more broadly, for example to tool-use problems.

Limitations: We only evaluated TRICE with prompt-tuning on a medium-size LLM; it may be that it behaves differently on smaller models, larger models, or when using other fine-tuning strategies. TRICE is a gradient-based tuning algorithm, but many of the most capable LLMs are proprietary, and their owners often do not provide any public mechanism for gradient-based fine-tuning. This makes it hard to evaluate how well TRICE would work when used with, say, GPT-4 (OpenAI, 2023). Finally, our quantitative evaluations focused on whether the LLM could produce the right answer; we did not formally evaluate the quality of the reasoning in the rationales themselves (cf. Uesato et al., 2022).

Broader Impacts: This work aims to improve the capabilities of LLMs by making them better able to answer questions accurately and transparently. However, more-capable LLMs may be used in malicious or unsafe ways, fine-tuning on uncurated question-answering datasets may introduce biases into the models, and more widely used LLMs will contribute a larger carbon footprint.

Rationales may make it easier for motivated users to judge the trustworthiness of LLM outputs. But many users may not read and critique an LLM's rationales, taking the mere existence of a rationale as evidence of truth. If chain-of-thought rationales promote uncritical trust, they could lead to harm.

Acknowledgements: We appreciate Daniel Freeman and Enrique Piqueras' contributions to the infrastructure that we used in our experiments. We thank Kevin Murphy, Ben Lee, Brian Patton, and Jascha Sohl-Dickstein for helpful discussions.

References

Anil, R., Dai, A. M., Firat, O., Johnson, M., Lepikhin, D., Passos, A., Shakeri, S., Taropa, E., Bailey, P., Chen, Z., et al. Palm 2 technical report. arXiv preprint arXiv:2305.10403 , 2023.

Bishop, C. M. Pattern recognition and machine learning . Springer, 2006.

Bornschein, J. and Bengio, Y. Reweighted wake-sleep, 2015.

Burda, Y., Grosse, R., and Salakhutdinov, R. Importance weighted autoencoders. arXiv preprint arXiv:1509.00519 , 2015.

Chung, H. W., Hou, L., Longpre, S., Zoph, B., Tay, Y., Fedus, W., Li, E., Wang, X., Dehghani, M., Brahma, S., et al. Scaling instruction-finetuned language models. arXiv preprint arXiv:2210.11416 , 2022.

Cobbe, K., Kosaraju, V., Bavarian, M., Chen, M., Jun, H., Kaiser, L., Plappert, M., Tworek, J., Hilton, J., Nakano, R., Hesse, C., and Schulman, J. Training verifiers to solve math word problems. arXiv preprint arXiv:2110.14168 , 2021.

Cover, T. M. Elements of information theory . John Wiley & Sons, 1999.

Creswell, A., Shanahan, M., and Higgins, I. Selection-Inference: Exploiting large language models for interpretable logical reasoning. arXiv preprint arXiv:2205.09712 , May 2022.

Dohan, D., Xu, W., Lewkowycz, A., Austin, J., Bieber, D., Lopes, R. G., Wu, Y., Michalewski, H., Saurous, R. A., Sohl-dickstein, J., Murphy, K., and Sutton, C. Language model cascades, 2022.

Geman, S. and Geman, D. Stochastic relaxation, Gibbs distributions, and the Bayesian restoration of images. IEEE Transactions on pattern analysis and machine intelligence , 6:721-741, 1984.

Hastings, W. K. Monte Carlo sampling methods using Markov chains and their applications. Biometrika , 57(1):97-109, 04 1970. ISSN 0006-3444. doi: 10.1093/biomet/57.1.97. URL https://doi.org/10.1093/biomet/57.1.97 .

Hewitt, L. B., Le, T. A., and Tenenbaum, J. B. Learning to learn generative programs with memoised wake-sleep. In Uncertainty in Artificial Intelligence , 2020.

Hol, J. D., Schon, T. B., and Gustafsson, F. On resampling algorithms for particle filters. In 2006 IEEE Nonlinear Statistical Signal Processing Workshop , pp. 79-82, 2006. doi: 10.1109/NSSPW. 2006.4378824.

Jouppi, N., Kurian, G., Li, S., Ma, P., Nagarajan, R., Nai, L., Patil, N., Subramanian, S., Swing, A., Towles, B., et al. Tpu v4: An optically reconfigurable supercomputer for machine learning with hardware support for embeddings. In Proceedings of the 50th Annual International Symposium on Computer Architecture , pp. 1-14, 2023.

Kingma, D. P. and Ba, J. Adam: A method for stochastic optimization. In Bengio, Y. and LeCun, Y. (eds.), 3rd International Conference on Learning Representations, ICLR 2015, San Diego, CA, USA, May 7-9, 2015, Conference Track Proceedings , 2015. URL http://arxiv.org/abs/1412. 6980 .

Kingma, D. P. and Welling, M. Auto-encoding variational bayes. arXiv preprint arXiv:1312.6114 , 2013.

Kojima, T., Gu, S. S., Reid, M., Matsuo, Y., and Iwasawa, Y. Large language models are Zero-Shot reasoners. arXiv preprint arXiv:2205.11916 , May 2022.

Le, T. A., Kosiorek, A. R., Siddharth, N., Teh, Y . W., and Wood, F. Revisiting reweighted wake-sleep for models with stochastic control flow. In Uncertainty in Artificial Intelligence , 2019.

Lester, B., Al-Rfou, R., and Constant, N. The power of scale for parameter-efficient prompt tuning. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing , pp. 3045-3059, 2021.

Lewkowycz, A., Andreassen, A., Dohan, D., Dyer, E., Michalewski, H., Ramasesh, V., Slone, A., Anil, C., Schlag, I., Gutman-Solo, T., Wu, Y., Neyshabur, B., Gur-Ari, G., and Misra, V. Solving quantitative reasoning problems with language models, 2022.

Lievin, V. Deep Latent Variable Models for Natural Language Processing . PhD thesis, 2022.

Loshchilov, I. and Hutter, F. SGDR: Stochastic gradient descent with warm restarts. In International Conference on Learning Representations , 2017. URL https://openreview.net/forum?id= Skq89Scxx .

Murphy, K. P. Probabilistic Machine Learning: An introduction . MIT Press, 2022. URL probml.ai .

Murray, I. and Salakhutdinov, R. Notes on the kl-divergence between a markov chain and its equilibrium distribution. preprint , 2008.

Naesseth, C., Lindsten, F., and Blei, D. Markovian score climbing: Variational inference with kl (p|| q). Advances in Neural Information Processing Systems , 33:15499-15510, 2020.

Nielsen, S. F. The stochastic EM algorithm: Estimation and asymptotic results. Bernoulli , 6(3): 457-489, June 2000.

Nye, M., Andreassen, A. J., Gur-Ari, G., Michalewski, H., Austin, J., Bieber, D., Dohan, D., Lewkowycz, A., Bosma, M., Luan, D., Sutton, C., and Odena, A. Show your work: Scratchpads for intermediate computation with language models. arXiv preprint arXiv:2112.00114 , November 2021.

OpenAI. Gpt-4 technical report, 2023.

Owen, A. and Zhou, Y. Safe and effective importance sampling. Journal of the American Statistical Association , 95(449):135-143, 2000.

Parisi, A., Zhao, Y., and Fiedel, N. Talm: Tool augmented language models, 2022.

Rajani, N. F., McCann, B., Xiong, C., and Socher, R. Explain yourself! leveraging language models for commonsense reasoning. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics , pp. 4932-4942, Florence, Italy, July 2019. Association for Computational Linguistics. doi: 10.18653/v1/P19-1487. URL https://aclanthology.org/P19-1487 .

Roeder, G., Wu, Y., and Duvenaud, D. K. Sticking the landing: Simple, lower-variance gradient estimators for variational inference. In Guyon, I., Luxburg, U. V., Bengio, S., Wallach, H., Fergus, R., Vishwanathan, S., and Garnett, R. (eds.), Advances in Neural Information Processing Systems , volume 30. Curran Associates, Inc., 2017. URL https://proceedings.neurips.cc/paper_ files/paper/2017/file/e91068fff3d7fa1594dfdf3b4308433a-Paper.pdf .

Schick, T., Dwivedi-Yu, J., Dessì, R., Raileanu, R., Lomeli, M., Zettlemoyer, L., Cancedda, N., and Scialom, T. Toolformer: Language models can teach themselves to use tools, 2023.

Shinn, N., Labash, B., and Gopinath, A. Reflexion: an autonomous agent with dynamic memory and self-reflection, 2023.

Shwartz, V., West, P., Le Bras, R., Bhagavatula, C., and Choi, Y. Unsupervised commonsense question answering with self-talk. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP) , pp. 4615-4629, Online, November 2020. Association for Computational Linguistics. doi: 10.18653/v1/2020.emnlp-main.373. URL https://aclanthology.org/2020.emnlp-main.373 .

Suzgun, M., Scales, N., Schärli, N., Gehrmann, S., Tay, Y., Chung, H. W., Chowdhery, A., Le, Q. V., Chi, E. H., Zhou, D., and Wei, J. Challenging BIG-Bench tasks and whether Chain-of-Thought can solve them. "arXiv preprint arXiv:2210.09261" , October 2022a.

Suzgun, M., Scales, N., Schärli, N., Gehrmann, S., Tay, Y., Chung, H. W., Chowdhery, A., Le, Q. V., Chi, E. H., Zhou, D., et al. Challenging big-bench tasks and whether chain-of-thought can solve them. arXiv preprint arXiv:2210.09261 , 2022b.

Talmor, A., Herzig, J., Lourie, N., and Berant, J. CommonsenseQA: A question answering challenge targeting commonsense knowledge. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) , pp. 4149-4158, Minneapolis, Minnesota, June 2019. Association for Computational Linguistics. doi: 10.18653/v1/N19-1421. URL https://aclanthology.org/ N19-1421 .

Tieleman, T. Training restricted boltzmann machines using approximations to the likelihood gradient. In Proceedings of the 25th international conference on Machine learning , pp. 1064-1071, 2008.

Tierney, L. Markov chains for exploring posterior distributions. Annals of Statistics , 22(4):1701-1728, December 1994.

Tucker, G., Mnih, A., Maddison, C. J., Lawson, J., and Sohl-Dickstein, J. Rebar: Low-variance, unbiased gradient estimates for discrete latent variable models. Advances in Neural Information Processing Systems , 30, 2017.

Turpin, M., Michael, J., Perez, E., and Bowman, S. R. Language models don't always say what they think: Unfaithful explanations in chain-of-thought prompting. arXiv preprint arXiv:2305.04388 , 2023.

Uesato, J., Kushman, N., Kumar, R., Song, F., Siegel, N., Wang, L., Creswell, A., Irving, G., and Higgins, I. Solving math word problems with process-and outcome-based feedback. arXiv preprint arXiv:2211.14275 , 2022.

Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., and Polosukhin, I. Attention is all you need. Advances in neural information processing systems , 30, 2017.

Wang, X., Wei, J., Schuurmans, D., Le, Q., Chi, E., Narang, S., Chowdhery, A., and Zhou, D. Self-Consistency improves chain of thought reasoning in language models. arXiv preprint arXiv:2203.11171 , March 2022a.

Wang, X., Wei, J., Schuurmans, D., Le, Q., Chi, E., and Zhou, D. Self-consistency improves chain of thought reasoning in language models. arXiv preprint arXiv:2203.11171 , 2022b.

Wei, J., Wang, X., Schuurmans, D., Bosma, M., Chi, E., Le, Q., and Zhou, D. Chain of thought prompting elicits reasoning in large language models. "arXiv preprint arXiv:2201.11903" , January 2022.

Yao, S., Zhao, J., Yu, D., Du, N., Shafran, I., Narasimhan, K., and Cao, Y. React: Synergizing reasoning and acting in language models, 2023.

Ye, X. and Durrett, G. Explanation selection using unlabeled data for In-Context learning. "arXiv preprint arXiv:2302.04813" , February 2023.

Zelikman, E., Wu, Y., and Goodman, N. D. Star: Bootstrapping reasoning with reasoning. arXiv preprint arXiv:2203.14465 , 2022.

Zhou, D., Schärli, N., Hou, L., Wei, J., Scales, N., Wang, X., Schuurmans, D., Bousquet, O., Le, Q., and Chi, E. Least-to-Most prompting enables complex reasoning in large language models. "arXiv preprint arXiv:2205.10625" , May 2022.

Supplemental Material for 'Training Chain-of-Thought via Latent-Variable Inference'

A Generalizing TRICE to Nondeterministic Likelihood Models

To apply TRICE beyond question-answering problems, we might want to use a nondeterministic likelihood model. For example, our desired output y might be a summary of a text x , and z might be a scratchpad or outline. In situations like this, there might be many y 's that are appropriate for a given x and z . So from a modeling perspective, it could make sense to make p ( y | x, z ) have nonzero entropy. But there is also a computational reason to prefer such a model: as the number of reasonable values that y could take given x increases, the probability of sampling the precise y that was observed goes down at a rate that might be exponential in the size of the output space.

Fortunately, we can easily extend TRICE to accommodate nondeterministic likelihoods. The differences are:

As discussed in Section 2.1, the acceptance probability for an independence sampler where the proposals are generated from p ( z | x ) is α (˜ z | z ) = min { 1 , p ( y | ˜ z,x ) p ( y | z,x ) } . So instead of deterministically accepting correct proposed latents ˜ z , we update the memory probabilistically, always accepting proposals that make the observed y more likely, but sometimes also accepting proposals that make y a little less likely.

glyph[negationslash]

The control-variate weights β m are now a function of the acceptance probabilities α : β m = 1 M -1 ∑ m ′ = m α (˜ z m ′ | z i m ′ ) .

The value of the control variate in this setting may be less than it is in the deterministic-likelihood setting. Even if we learn a model that consistently produces good latents z (in the sense that they lead to valid outputs y ), this does not guarantee that it will consistently generate latents that are consistent with the particular y that was observed. For example, there might be multiple reasonable ways to outline a long text, some of which lead to different summary paragraphs. In this scenario, the acceptance probability may not converge to something close to 1, and the variance-reduction effect from the control variate will be modest.

B Derivation of the Control Variate Scaling Heuristic

Our analysis will focus on the variance of the k th element ˆ g k of our gradient estimator. To minimize clutter, we suppress subscript indices and define g ′ = ∇ θ k log p ( z ′ | x ) , ˜ g = ∇ θ k log p (˜ z | x ) , and g = ∇ θ k log p ( z | x ) , where z ′ is the updated rationale, ˜ z is the proposed rationale, and z is the previous rationale in memory. Note that g ′ = ˜ g if the proposal ˜ z is accepted, and g ′ = g if ˜ z is rejected. We assume that the previous rationale z is a sample from p ( z | x, y ) . We also define the shorthands g + = E [˜ g | c (˜ z, y ) = 1] , g -= E [˜ g | c (˜ z, y ) = 0] , v = Var(˜ g ) = E [˜ g 2 ] , v + = Var(˜ g | c (˜ z, y ) = 1) , v -= Var(˜ g | c (˜ z, y ) = 0) . Finally, we define the probability of accepting a proposal π = E [ c (˜ z, y )] .

Our gradient estimator is

The variance of ˆ g is

In Equation (8) we use the fact that E [˜ g ] = 0 and g + is nonrandom and therefore independent of ˜ g . Breaking out the cases where c (˜ z, y ) = 0 (so g ′ = g ) and c (˜ z, y ) = 1 (so g ′ = ˜ g ), the rightmost expectation is

We can simplify the term on the right. Since 0 = E [˜ g ] = πg + +(1 -π ) g -, (1 -π ) g + g -= -πg 2 + . Plugging this into Equation (10), we have

So the variance of ˆ g simplifies to

Taking the derivative with respect to β shows that this is minimized when

Plugging this back into Equation (12) gives the optimal variance v glyph[star] :

We can expand v by considering the case where c (˜ z, y ) = 1 (which happens with probability π and the case where c (˜ z, y ) = 0 (which happens with probability 1 -π ):

where in the second line we again use the fact that πg + = -(1 -π ) g -, and in the third-to-last line we approximate 1 π with the first-order Taylor approximation 1 π = 2 -π + O ((1 -π ) 2 ) . Thus, we can write

So the optimal variance v glyph[star] is

By contrast, plugging our heuristic value of β = π into Equation (12) gives the suboptimal variance v π :

where we use the approximation π k = (1 -(1 -π )) k = 1 -k (1 -π ) + O ((1 -π ) 2 ) to simplify the π 2 and π 3 terms. Thus, we conclude that v glyph[star] and v π are the same up to O ((1 -π ) 2 ) , and so as the probability π of getting the correct answer increases, the suboptimality of setting β = π goes down faster than the variance does.

C On Gradient Estimators Based Solely on Incorrect Rationales

We adopt the same shorthands as in Appendix B.

Our analysis centers on the identity

which relates the gradient we want to estimate g + (the expected gradient given that the rationale is correct) to g -(the expected gradient given that the rationale is incorrect).

C.1 Variance of incorrect-rationale gradient estimators

Equation (19) implies that

Deferring for the moment the difficulty in estimating π -1 (see Appendix C.2 below), we can consider the variance of an estimator based on the right hand side of Equation (20):

If π is small, then this becomes

so that unless the variance v -of incorrect rationales is very low, the variance of this estimator will be O ( π -2 ) , which is very high. By contrast, the variance of a gradient estimator based purely on correct rationales is simply v + , so unless the gradient variance for incorrect rationales is dramatically lower than that for correct rationales, then if π is small then incorrect rationales will lead to much noisier gradient estimates.

On the other hand, if 1 -π is small, then we have

which is likely a significant improvement on the variance v + of the correct-rationale estimator; in particular, it goes to zero as π approaches 1.

C.2 TRICE control variate as a debiased estimator based on incorrect rationales

Equation (20) implies that, in principle, given unbiased estimates for 1 -π and π -1 , we could compute gradient updates purely based on rationales that fail to obtain the correct answer. Unbiased estimates of 1 -π are easy to obtain; we need only compute 1 -c (˜ z, y ) . But unbiased estimates of π -1 are harder to come by.

Instead, we can compute a biased estimator that ignores the π -1 term and then correct for the bias:

So the expected value of the estimator -(1 -c (˜ z, y ))˜ g is too small by a factor of (1 -π ) g + . We can correct this bias by adding in an unbiased estimator of it that uses g (the gradient for a correct rationale from memory):

This is precisely the gradient estimator that TRICE uses when the sampled rationale ˜ g is incorrect and β = 1 . Smaller values of β interpolate between this estimator and an estimator based purely on correct rationales.

D BBH Per-Task Experimental Results

Table 3 summarizes our experimental results for each task in BBH.

E Example Rationales

Figure 3 illustrates some examples of rationales generated by the TRICE-tuned LLM on the BBH task Logical Deduction Three Objects.

Figure 4 illustrates some examples of rationales generated by the TRICE-tuned LLM on GSM8K. Although we did find examples where the LLM got the answer right for the wrong reasons, this was much less common on GSM8K than on BBH, since the numeric output space for GSM8K is much larger than that for the typical multiple-choice BBH task.

Figure 5 shows an example where the guide model q φ ( z | x, y ) in reweighted wake-sleep learns to closely mimic the prior model p θ ( z | x ) until the very end of the rationale, at which point it pastes in the correct answer.

F Method and Template Details

In this section, we present more details on the methods and templates that we used in the experiments.

To sample from p θ ( z | x ) , we prompt the LLM with the template ' Question: <QUESTION>\nAnswer: Let's think step by step.\n '. We cap the length of the generated rationales at 1.25 times the length of the longest of the exemplar rationales used to initialize the soft prompt. To initialize the memory (i.e., to sample from q ( z | x, y ) in line 2 of Algorithm 1), on BBH we sample from the base model with a 'guide' prompt of the form ' Question: <QUESTION>\nAnswer: The answer is <ANSWER>. Let's think step by step.\n '. We use the same guide prompt to generate rationalizations in STaR, but with temperature 0 (see below). On GSM8K, we instead initialize the memory with samples from p θ ( z | x ) , since we found that initializing the memory using a prompt that includes the answer led to

Example Rationales for Logical Deduction Three Objects BBH Task

An example where TRICE gets the answer right with a good rationale:

Question: On a shelf, there are three books: a brown book, a yellow book, and an orange book. The yellow book is the leftmost. The orange book is to the right of the brown book.

Options:

(A) The brown book is the rightmost

(B) The yellow book is the rightmost

(C) The orange book is the rightmost

TRICE answer: Brown book is to the right of yellow book. And orange book to the right of brown book. So. the answer is (C).

An example where TRICE gets the answer right with a bad rationale:

Question: A fruit stand sells three fruits: plums, apples, and loquats. The loquats are the cheapest. The plums are less expensive than the apples.

Options:

(A) The plums are the second-most expensive

(B) The apples are the second-most expensive

(C) The loquats are the second-most expensive

TRICE answer: Apples cost more than plums, but less than loquat. So. the answer is (A).

An example where TRICE gets the answer wrong:

Question: A fruit stand sells three fruits: mangoes, watermelons, and kiwis. The watermelons are less expensive than the kiwis. The kiwis are the second-most expensive.

Options:

(A) The mangoes are the most expensive

(B) The watermelons are the most expensive

(C) The kiwis are the most expensive

TRICE answer: The Mangoes are more expensive than the Watermelon. And are more expensive than kiwis. So. the answer is (C).

Example Rationales for GSM8K

An example where TRICE gets the answer right with a good rationale:

Question: Gabrielle sells eggs. On Monday she sells 5 crates of eggs. On Tuesday she sells 2 times as many crates of eggs as Monday. On Wednesday she sells 2 fewer crates than Tuesday. On Thursday she sells half as many crates of eggs as she sells on Tuesday. How many total crates of eggs does she sell for the 4 days?

An example where TRICE gets the answer right with a bad rationale:

Question: Samantha's last name has three fewer letters than Bobbie's last name. If Bobbie took two letters off her last name, she would have a last name twice the length of Jamie's. Jamie's full name is Jamie Grey. How many letters are in Samantha's last name?

TRICE answer: Jamie's full name consists of 5 letters. If Bobbie took 2 letters off her last name, she would have a last name twice the length of Jamie's, which is 10 letters. So, Bobbie's last name has 10 letters. If Bobbie's last name has 10 letters, and Samantha's last name has three fewer letters than Bobbie's, Samantha's last name has 10-3 = 7 letters. <answer> 7 </answer>

An example where TRICE gets the answer wrong:

Question: John drives for 3 hours at a speed of 60 mph and then turns around because he realizes he forgot something very important at home. He tries to get home in 4 hours but spends the first 2 hours in standstill traffic. He spends the next half-hour driving at a speed of 30mph, before being able to drive the remaining time of the 4 hours going at 80 mph. How far is he from home at the end of those

4

hours?

from

Example Rationales for GSM8K Generated by RWS Guide

Question: Josh decides to try flipping a house. He buys a house for $80,000 and then puts in $50,000 in repairs. This increased the value of the house by 150%. How much profit did he make?

slower convergence and worse results; it may be that including the answer in the prompt sometimes encourages the model to produce untrustworthy explanations (Turpin et al., 2023).

To evaluate the correctness c ( z, y ) of a rationale z given the answer y , in BBH we search the end of the rationale for final answers in the form ' the answer is <ANSWER>. '. In GSM8K, we initialize the soft prompt to encourage the model to wrap its answers in ' <answer> ' and ' </answer> ' tags, and then extract the answer from those tags. To encourage the bootstrapped few-shot examples in GSM8K to follow this template, we the following example to the CoT prompt: ' Question: What is 1 plus 1?\nAnswer: Let's think step by step.\n1 plus 1 is 2.\n<answer>\n2\n</answer>\n\n '.

Figure 6 and Figure 7 show the bootstrapped few-shot CoT examples that we used to initialize the soft prompt in the experiments.

TRICE. For all BBH tasks, we run TRICE for 500 steps with batch size M = 32 and do not use subsampling (i.e., compute L = 64 gradients per batch). We use the Adam optimizer (Kingma & Ba, 2015) with an initial learning rate 1 . 0 and a cosine decay schedule (Loshchilov & Hutter, 2017) that reduces the learning rate by 10x over the first 450 steps. For GSM8K, we run TRICE for 5000 steps with a constant learning rate of 1.0, batch size M = 128 , and compute L = 128 gradients per batch.

STaR. We use an adaptation of the STaR strategy proposed by Zelikman et al. (2022), where we do prompt-tuning rather than fine-tuning on all weights. The method alternates between updating its memory and retuning the model from scratch on the updated memory in an inner loop. We apply this procedure for 10 outer-loop steps. Following Zelikman et al. (2022), we start with 40 inner-loop optimization steps, increasing the number of inner-loop steps by 20 %each outer-loop iteration up to a maximum of 200 steps. If the training loss goes below 0.01 we break out of the inner loop. For STaR's inner-loop optimization, we use the same prompt-tuning initialization, Adam hyperparameters as above, but with cosine decay from 1.0 to 0.1 over the course of each inner loop. To update the

STaR memory, we first try generating a rationale from the prompt-tuned model by greedy decoding, then if that rationale is incorrect fall back on a rationalization generated by greedy decoding from the same guide model we use in TRICE to initialize the MCMC memory, and finally if neither procedure generates a valid rationale we omit the example from the memory.

Rejection Sampling. We reduce mini-batch size by 4 and draw 4 rationales for each example in the mini-batch. We use the same mini-batch size, train steps, and optimizer as in TRICE for all BBH and GSM8K experiments. In BBH, we use the initial learning rate 1.0 as in TRICE. In GSM8K, we use the learning rate 0 . 1 because it achieved better results than learning rate 0 . 3 , and the training procedure became unstable with learning rate 1 . 0 .

CoTPrompt Tuning. To do supervised CoT tuning, we prompt-tune the model to maximize the loglikelihoods of the training rationales given questions. The BBH datasets include very few exemplar rationales, so we cannot apply this strategy to BBH. On GSM8K, we use the same hyperparameters as in TRICE except that we early-stop the algorithm after only 1000 train steps, since the model overfits badly when we run longer.

Direct Prompt Tuning. In this method, the model tries to guess the answer directly without generating a rationale; prompt-tuning to maximize the log-likelihood of the answers in this setup is straightforward, since there is no latent rationale to integrate out. We initialize the soft prompt using 3 examples from the training set and truncate its length to 64. The optimization procedure is carried out over 150 steps with batch size 16 and the same Adam hyperparameters as above, except that the cosine decay period is set to 150 instead of 450. We found these adjustments to the hyperparameters from different training schemes were necessary to reduce overfitting.

Bootstrapped 3-shot CoT Prompt for Formal Fallacies BBH Task

Question: "It is not always easy to grasp who is consuming which products. The following argument pertains to this question: First of all, being a frequent consumer of KMS shampoo is necessary for being a regular consumer of Yardley London soap. Next, whoever is a regular user of Joico shampoo is not a frequent consumer of KMS shampoo. All this entails that no regular consumer of Yardley London soap is a regular user of Joico shampoo."

Is the argument, given the explicitly stated premises, deductively valid or invalid?

Options:

valid

invalid

Answer: Let's think step by

step.

Regular use of a product always entails being a frequent consumer of that product. Although a Joico shampoo user might still buy bottles of Yardley London soap sometimes, he/she can never be a regular product of both soaps. So, the answer is valid.

Question: "Here comes a perfectly valid argument: To start with, whoever is an expert of BSC Young Boys is not an ex-fan of Real Betis Balompié. Now, whoever is a friend of FC Dynamo Kyiv is not an expert of BSC Young Boys. Hence, no friend of FC Dynamo Kyiv is an ex-fan of Real Betis Balompié."

Is the argument, given the explicitly stated premises, deductively valid or invalid?

Options:

valid

invalid

Answer: Let's think step by step.

You can friend FC Dynamo Kyiv but not be an expert of BSC Young Boys. So, the answer is invalid.

Question: "It is not always easy to see who is related to whom - and in which ways. The following argument pertains to this question: Some classmate of Terri is a workmate of Dolores. Whoever is not a workmate of Dolores is an ancestor of Cheryl. So, necessarily, some ancestor of Cheryl is not a classmate of Terri."

Is the argument, given the explicitly stated premises, deductively valid or invalid?

Options:

valid

invalid

Answer: Let's think step by step.

Reasoning: Some classmate of Terri is not a workmate of Dolores. Whoever is not a workmate of Dolores is an ancestor of Cheryl. So, necessarily, some ancestor of Cheryl is not a classmate of Terri. Remember that Terri's classmate and Dolores's workmate can be in any case: One of the three can be any person. So, the answer is invalid.

Peer reviews:
{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThis paper introduces a principled and practical approach to boost the training of the \"chain-of-thought\" through the inference of latent variables. Instead of the typical variational inference, the authors opt for a MCMC-EM method to circumvent the issue of posterior collapse, a common occurrence in auto-regressive models with latent variables, which could be exacerbated when dealing with large language models. By treating rationales as latent variables, this methodology enables training without the need for detailed rationales, which can be expensive to produce.  Moreover, the authors propose a control-variate technique that reduces training variance while maintaining unbiasedness. The theoretical underpinnings of their approach are validated on the BIG-Bench Hard dataset.\n\nSTRENGTHS:\n1. Although the soft-prompt approach is widely used, this proposal introduces an innovative perspective on 'prompt-finetuning' utilizing a chain-of-thought.\n\n2. The assumptions and derivations presented are straightforward and intuitive with only minor confusion.\n\n3. The authors thoroughly explore the links between their work and previous studies, while also critically examining the limitations of their own findings.\n\n4. The authors validate their theories by applying them to the significant benchmark of BBH.\n\nWEAKNESSES:\nSee questions.\n\nQUESTIONS:\n1. For accept rate in Metroplis-Hastings, why the transition kernel $p(\\tilde{z},y|x)$ is not conditional on previous state $z$?\n\n2. For sampling from intractable posterior $p(z|x,y)$, what if you directly sampling from this distribution using finite-step MCMC as $p(z|x,y)\\propto p(z|x)p(y|z,x)$? You do not need to add more experiments. Could you explain the difference?\n\n3. For control variate, in appendix you mentioned it may not be that useful in the stochastic setting. For figure 1, I want to know that suppose you train long enough, will the training estimate becomes the same for two settings (with or without control variate) based on your claim in Eq. 3? Meanwhile, what's the notation meaning for expectation over MCMC?\n\n4. How many tokens you use for latent variable $z$?\n\n5. While I commend the authors for validating their approach on an important benchmark, an aspect I deeply appreciate, I believe that testing on a more diverse dataset would bolster the paper's credibility and appeal. This is particularly true when making a comparison with [1]. \n\n6. Do you have failure case analysis and do you need human evaluation?\n\nI would be more than willing to raise my review scores if the authors could provide further clarification and deeper insights about the paper. \n\n[1] STaR: Self-Taught Reasoner Bootstrapping Reasoning With Reasoning\n\nLIMITATIONS:\nThe authors has discussed this paper's limitations.", "TITLE": "Official Review", "RECOMMENDATION": 6, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-07-06"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThis paper explores considering Chain-of-Thoughts (CoT) as a latent variable and introduces TRICE: an MCMC-EM algorithm for optimizing CoT-latent-latent variable models using a Metropolis-Hastings algorithm (rejection sampling) coupled with a control variate. \n\nThe authors tested the model by fine-tuning a proprietary LLM on 27 BIG-bench hard tasks and report improvements when compared to direct prompt tuning and STaR. The authors tested the effectiveness of the control variate but did not test the method against more conventional optimisation methods.\n\nSTRENGTHS:\nOverall, This paper discusses a well-defined issue and explores innovative solutions to the optimization problem, it was a refreshing and educative read, thank you!\n\nMain strengths:\n1. Optimizing LLMs as latent variable models has great potential and the authors present the problem well\n2. The authors introduce an innovative gradient estimator (MCMC-EM + control variate) which is computationally efficient (single sample per data point) and seems to work very well\n3.  The authors demonstrate progress on a subset of the MMLU dataset\n4.  Theoretical and experimental limitations are thoroughly discussed\n\nWEAKNESSES:\nOverall, the paper lacks structure and more extensive comparison with the existing literature on Monte Carlo methods. I believe not addressing these points would greatly reduce the impact of this paper. Nevertheless, I would happily accept this paper if these limitations are resolved!\n   \n1. The paper overall lacks structure. Although I appreciated the lengthy discussions, I think the main storyline could be made more clear by separating the main ideas from the discussions. \n   \n2. The optimization method is only presented using full text and Algorithm 1. This paper would convey its idea more clearly using a set of two additional equations: A) expression of the *true* gradients and B) Monte Carlo estimate (which translates into Algorithm 1).\n   \n3. Classic gradient estimation methods are not covered sufficiently and some of the statements in section 2.2 *Why not variational inference?* are misleading. \n\t1. Posterior collapse (discussed in Lucas et al., 2019) is an issue inherent to the optimization of the proposal distribution $q(z | x, y)$ and $q$ is in this paper never optimized.  \n\t2. The author discusses the limitations of the ELBO, but the ELBO only arises when using a single-sample estimate of the log-likelihood. When working with discrete latent variables, it is more common to use the Importance Weighted Bound (IWB). I.e., use a K-samples importance-weighted estimate of the likelihood (e.g., $\\log p(y | x) \\approx \\log \\frac{1}{K} \\sum_{j=1}^K \\frac{p(y, z^{(j)} | x)}{q(z^{(j)}|x,y)})$ -- as done in [\"Revisiting Reweighted Wake-Sleep for Models with Stochastic Control Flow\", Let et al., 2019](https://arxiv.org/abs/1805.10469)) which variance scales as $\\sqrt{1/K}$. See [\"Monte Carlo Gradient Estimation in Machine Learning\", Mohamed et al., 2020] for more background on optimization methods.\n\n6. The experimental comparison with RWS is not included in the paper.\n\nQUESTIONS:\n1. How exactly did you compute the gradients in the RWS experiment?\n\nLIMITATIONS:\n1. I stumbled upon this PhD thesis: [Deep Latent Variable Models for Natural Language Processing, Lievin 2022](http://vlievin.github.io/deep-lvms-for-nlp.pdf), which discusses similar ideas. You might not have been the first ones to consider that \"CoT methods are latent-variable probabilistic models\"", "TITLE": "Official Review", "RECOMMENDATION": 6, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-07-06"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThis work introduces a new method for training models for chain-of-thought prompting, aimed at maximizing the marginal probability of generating a correct answer using Markov-chain Monte Carlo, expectation maximization, and a novel control variate technique, along with prompt tuning. Much of the work is spent deriving and analyzing the method (e.g. compared to related methods like self-taught reasoner STaR), with a final section dedicated to testing the method and demonstrating very significant performance gains over vanilla prompt tuning (no CoT) and STaR.\n\nSTRENGTHS:\n- Principled, novel method along with extensive derivation. Particularly, this well motivates the need for taking a marginalization framing rather than the greedy approach often used before\n- It is generally very useful to see more theoretical justification provided in this area. Past works (e.g. STaR) provide many novel ideas, but it is useful to take a more comprehensive (and marginalization-based) approach to the problem\n- extensive theoretical/technical rationale for method over other options (STaR, variational inference)\n- very strong experimental results, demonstrating significant gains over STaR, another recent method for training for CoT prompting\n\nWEAKNESSES:\n- Fairly limited analysis of experimental results (mostly aggregate results on Big Bench tasks in the main paper, without too much specific analysis)\n- It would also be useful/interesting to see what the generated rationales look like: how do they differ from e.g. STaR, and how often are they correct in a human-interpretable way rather than just leading to a correct answer? Adding some information about this in the main paper would be useful\n- Fairly limited discussion of limitations\n\nQUESTIONS:\nNone\n\nLIMITATIONS:\nLimitations section is quite limited. It would be useful to see e.g. a discussion of the effects of rationales on user trust (will having rationales make users trust models more even if the rationales are wrong?)", "TITLE": "Official Review", "RECOMMENDATION": 7, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 4, "DATE": "2023-07-07"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThis paper proposes treating rationales as latent-variables and considers the marginal distribution over answers, averaging over possible rationales. To do so, a MCMC procedure is proposed, in which rationales are proposed via an independence sampler. The approach is compared to STaR (Zelikman et al., 2022) as a baseline on 27 BigBench-HARD tasks. Rather than fine-tune all the model weights, prompt tuning is used a parameter-efficient alternative. The proposed approach is found to outperform STaR on the subset of tasks considered.\n\nSTRENGTHS:\n* The derivations the authors present are detailed and comprehensive. The design choices are explained well and justified in context.\n\n* Compared to alternate methods, the approach advocated in this paper seems more principled.\n\n* The authors discuss a potential alternate approach (variational Bayes) and justify why it is not appropriate.\n\nWEAKNESSES:\n* As the authors acknowledge, TRICE is only tested on small datasets. The behavior of the comparison model is significantly different than the expected behavior; the authors speculate this is due to overfitting of the comparison model, but do not compare TRICE’s performance on Commonsense QA or reduce the number of inner loop steps to prevent overfitting.\n\n* While the overall approach is novel, it’s not clear that the improvements and alterations proposed present significant innovations on existing methods. Furthermore, I have some concerns about the sensitivity of the approach to hyper-parameters, such as the # of MCMC steps, initialization scheme, etc.\n\n* Some implementation details are unclear. The methods as-is would not be reproducible, and it seems that the authors do not plan to release their code, raising concerns about replicability.\n\nQUESTIONS:\n* What is the specific $c(z,y)$ used in the experiments? It never seems to be defined— an example is given on line 71, but it’s unclear whether that’s the specific correctness function used in the experiments.\n\n* Line 80 says that “For example, the guide might prompt an LLM specifically to give an rationale for the answer”— was this the case for all experiments?\n\n* Line 296 says that \"an adaptation of the STaR strategy\" is tested-- what aspects specifically were adapted?\n\nLIMITATIONS:\nThere is a nominal discussion of limitations but I think this could be significantly expanded. For example, MCMC can be sensitive to hyperparameters and mixing is hard to diagnose.", "TITLE": "Official Review", "RECOMMENDATION": 5, "REVIEWER_CONFIDENCE": 5, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-07-07"}

comments: SUMMARY:
The paper proposes a prompt-tuning strategy that tries to maximize the marginal log-likelihood of generating a correct answer using CoT prompting.

STRENGTHS:
The paper presents a prompt-tuning strategy that aims to optimize the marginal log-likelihood of producing accurate answers through the utilization of CoT prompting. And the paper uses  simple Markov chain Monte Carlo (MCMC) expectation-maximization (EM) algorithm, memoized wake-sleep, and persistent contrastive divergence to address the challenge of sampling from the posterior. The results look like promising over other baselines.

WEAKNESSES:
The author did not provide specific information about the model details. If the model size is close to 100 billion, it would be beneficial for the paper to include a baseline comparison with text-davinci-003 (Zero-shot or few shot learning). Otherwise, I feel it unnecessary to conduct prompt tuning on a large-scale model if its performance is still inferior to that of zero/few-shot learning using the same scale model but from GPT family. 
If the author's intention is to compare with open-source models, it is essential to include Alpaca-CoT (https://github.com/PhoebusSi/alpaca-CoT), regardless of the specific model or fine-tuning technique they employ.

QUESTIONS:
See weakness part.

LIMITATIONS:
See weakness part.
TITLE: Official Review
SOUNDNESS_CORRECTNESS: 3
DATE: 2023-07-10