<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Paper Review | YuyaoGe's Website</title><link>https://geyuyao.com/category/paper-review/</link><atom:link href="https://geyuyao.com/category/paper-review/index.xml" rel="self" type="application/rss+xml"/><description>Paper Review</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Thu, 24 Oct 2024 00:00:00 +0000</lastBuildDate><image><url>https://geyuyao.com/media/icon_hucac340dfc176d8b4c8a8aa7a23204f12_18561_512x512_fill_lanczos_center_3.png</url><title>Paper Review</title><link>https://geyuyao.com/category/paper-review/</link></image><item><title>EMNLP 2024 Paper Review | Fewer is More: CoT Exemplars Should Be Few but Good</title><link>https://geyuyao.com/post/few-is-more-en/</link><pubDate>Thu, 24 Oct 2024 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/few-is-more-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/few-is-more/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> Fewer is More: Boosting LLM Reasoning with Reinforced Context Pruning&lt;/p>
&lt;p>&lt;strong>Institute:&lt;/strong> Hong Kong University of Science and Technology, Microsoft Research&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Xijie Huang Li, Lyna Zhang, Kwang-Ting Cheng, Fan Yang, Mao Yang&lt;/p>
&lt;p>&lt;strong>Arxiv Link:&lt;/strong> &lt;a href="https://arxiv.org/abs/2312.08901" target="_blank" rel="noopener">https://arxiv.org/abs/2312.08901&lt;/a>&lt;/p>
&lt;p>&lt;strong>Date:&lt;/strong> 2024.2.15&lt;/p>
&lt;h1 id="1-abstract">1. Abstract&lt;/h1>
&lt;p>Even with CoT prompting, LLMs still fall short on mathematical reasoning problems. The authors propose CoT-Influx, a method that optimizes both the exemplars and the content of chain-of-thought prompts to improve the reasoning ability of LLMs. Its core idea is to use pruning to maximize the amount of useful information fed into the model.&lt;/p>
&lt;h1 id="2-motivation">2. Motivation&lt;/h1>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>The potential of chain-of-thought (CoT) exemplars is under-exploited&lt;/strong>:&lt;br>
Prior work has shown that supplying step-by-step chain-of-thought exemplars helps models perform complex reasoning. However, a limited context window &lt;strong>caps the number of CoT exemplars that can be fed in&lt;/strong>, so the full potential of CoT goes unrealized.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Limitations of existing solutions&lt;/strong>:&lt;br>
Extending the context window does make room for more CoT exemplars, &lt;strong>but it drives up inference cost and complexity&lt;/strong>. Existing compression- and retrieval-based techniques, meanwhile, perform poorly on mathematical reasoning tasks, and in particular fail to pick out the CoT exemplars and tokens that matter most for a specific task.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>These gaps motivate &lt;strong>CoT-Influx&lt;/strong>, which improves the quality of the input text through a pruning strategy without increasing computational cost.&lt;/p>
&lt;h1 id="3-observations">3. Observations&lt;/h1>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>More CoT exemplars improve LLM reasoning performance&lt;/strong>:
Adding CoT exemplars lifts how LLMs perform on mathematical reasoning tasks, but the context window caps how many can actually be supplied.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>The choice of CoT exemplars is critical&lt;/strong>:
Not every CoT exemplar helps reasoning; carelessly adding incorrect, redundant, or misleading exemplars can even degrade performance.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>CoT exemplars contain redundant tokens&lt;/strong>:
CoT exemplars often carry redundant tokens. Pruning them frees space for more useful content and thereby improves reasoning.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h1 id="4-method-cot-influx">4. Method: CoT-Influx&lt;/h1>
&lt;h2 id="the-short-version-skipping-the-details">The short version, skipping the details&lt;/h2>
&lt;p>CoT-Influx treats the LLM as a black box. Its key module is a coarse-to-fine pruner that produces high-quality, compact CoT exemplars in two steps:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Shot Pruner&lt;/strong>: select from a large pool of CoT exemplars the k exemplars most helpful for the target problem.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Token Pruner&lt;/strong>: prune the retained CoT exemplars further, stripping out unimportant tokens to yield a condensed version.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>The condensed CoT exemplars are then prepended to the question, and that&amp;rsquo;s it.&lt;/p>
&lt;center> &lt;img style="border-radius: 0.3125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);" src="https://geyuyao.com/post/few-is-more/1729793114717.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;h2 id="the-detailed-version">The detailed version&lt;/h2>
&lt;h3 id="1-problem-definition">1. &lt;strong>Problem definition&lt;/strong>&lt;/h3>
&lt;p>Given a set of chain-of-thought exemplars
$\mathcal{D} = \{x_{\text{cot}}^i\}_{i=1}^{n}$, where each exemplar
$x_{\text{cot}}^i$ consists of a question, reasoning steps, and an answer, and whose token count exceeds the LLM&amp;rsquo;s context window length
$T$, we would like to optimize
$\mathcal{D}$ through a two-stage pruning process to produce an effective input whose total token count
$t(x_{\text{input}})$ satisfies:&lt;/p>
$$
t(x_{\text{input}}) \leq T
$$
&lt;p>while still allowing the LLM to generate the correct reasoning result from that input.&lt;/p>
&lt;h3 id="2-the-two-stage-pruning-process">2. &lt;strong>The two-stage pruning process&lt;/strong>&lt;/h3>
&lt;p>CoT-Influx&amp;rsquo;s two-stage pruning process uses policy networks to select the useful chain-of-thought exemplars and, within them, the relevant tokens:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Stage one: Shot Pruner&lt;/strong>&lt;br>
This stage uses a multi-layer perceptron (MLP) with two hidden layers to select the
$k'$ most useful exemplars from a batch of chain-of-thought exemplars. The MLP takes as input the text embedding of each exemplar, denoted
$H_{\text{shot}} \in \mathbb{R}^{k \times N \times D_{\text{BERT}}}$, where
$k$ is the batch size,
$N=512$ is the number of tokens per exemplar, and
$D_{\text{BERT}}$ is the dimensionality of the BERT embedding. The MLP then outputs a probability distribution:&lt;/li>
&lt;/ul>
$$
\pi_{\theta_1}(a_{\text{shot}} | s_{\text{shot}}) = \sigma(\text{MLP}(H_{\text{shot}}))
$$
&lt;p>Here
$\sigma$ is the sigmoid activation, and the action
$a_{\text{shot}}$ indicates whether the CoT exemplar is kept. The selected exemplar set is:&lt;/p>
$$
\mathcal{D'} = \{x_{\text{cot}}^j \in \mathcal{D} : a_{\text{shot}}^j = 1\}
$$
&lt;ul>
&lt;li>&lt;strong>Stage two: Token Pruner&lt;/strong>&lt;br>
For the retained exemplar set
$\mathcal{D'}$, a second two-hidden-layer MLP prunes the tokens within each exemplar. It likewise takes as input the embeddings of the retained exemplars
$H_{\text{token}} \in \mathbb{R}^{k' \times N \times D_{\text{BERT}}}$ and outputs a probability distribution that decides whether each token is kept:&lt;/li>
&lt;/ul>
$$
\pi_{\theta_2}(a_{\text{token}} | s_{\text{token}}) = \sigma(\text{MLP}(H_{\text{token}}))
$$
&lt;p>The pruned token set is:&lt;/p>
$$
\hat{x}_{\text{cot}}^j = \{ \text{token} \in x_{\text{cot}}^j : a_{\text{token}} = 1 \}
$$
&lt;h3 id="3-optimization-objective-a-multi-objective-reward-function">3. &lt;strong>Optimization objective: a multi-objective reward function&lt;/strong>&lt;/h3>
&lt;p>CoT-Influx optimizes a &lt;strong>multi-objective reward function&lt;/strong> that keeps reasoning accurate while cutting away as many redundant exemplars and tokens as possible. The reward combines the LLM&amp;rsquo;s reasoning loss, the accuracy of the reasoning, and the number of input tokens:&lt;/p>
$$
R(x_{\text{input}}) = \left( \frac{1}{1 + L_{\text{LLM}}(x_{\text{input}})} + R_{\text{Acc}} \right) \times \left( \frac{t(x_{\text{input}})}{T} \right)^w
$$
&lt;p>where:&lt;/p>
&lt;ul>
&lt;li>
$L_{\text{LLM}}(x_{\text{input}})$ is the LLM&amp;rsquo;s reasoning loss;&lt;/li>
&lt;li>
$R_{\text{Acc}}$ is the reasoning accuracy (1 if correct, 0 if wrong);&lt;/li>
&lt;li>
$t(x_{\text{input}})$ is the number of input tokens;&lt;/li>
&lt;li>
$T$ is the maximum token length of the context window;&lt;/li>
&lt;li>
$w$ is a hyperparameter that tunes the influence of the token count.&lt;/li>
&lt;/ul>
&lt;p>This reward steers the pruner toward maximum reasoning accuracy while squeezing the total token count down far enough that the input fits inside the context window.&lt;/p>
&lt;h3 id="4-reinforcement-learning-optimization">4. &lt;strong>Reinforcement learning optimization&lt;/strong>&lt;/h3>
&lt;p>To optimize the pruning policy networks, CoT-Influx uses &lt;strong>REINFORCE&lt;/strong>, adjusting the parameters of the two-stage pruner by maximizing the reward function.&lt;/p>
$$
\nabla_\theta J(\theta) = R(x_{\text{input}}) \cdot \left( \nabla_\theta \log \pi_{\theta_1}(a_{\text{shot}} | s_{\text{shot}}) + \nabla_\theta \log \pi_{\theta_2}(a_{\text{token}} | s_{\text{token}}) \right)
$$
&lt;h1 id="5-results">5. Results&lt;/h1>
&lt;p>The figure below shows how CoT-Influx performs on the GSM8K dataset.&lt;/p>
&lt;center> &lt;img style="border-radius: 0.3125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);" src="https://geyuyao.com/post/few-is-more/1729791928636.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;p>Notably, as the figure below shows, LLaMA2-70B paired with CoT-Influx surpasses larger LLMs without any fine-tuning at all. For instance, LLaMA2-70B improves on GPT-3.5 by 2.5%.&lt;/p>
&lt;center> &lt;img style="border-radius: 0.3125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);" src="https://geyuyao.com/post/few-is-more/1729791914198.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;h1 id="6-findings">6. Findings&lt;/h1>
&lt;ol>
&lt;li>More capable LLMs prefer harder CoT exemplars, whereas smaller LLMs go for simpler ones.&lt;/li>
&lt;li>Numbers and formatting tokens are essential for mathematical reasoning. Function words such as with, the, and then, along with background context irrelevant to the reasoning — theater, for example — can be pruned away without hurting reasoning.&lt;/li>
&lt;/ol>
&lt;h1 id="7-commentary">7. Commentary&lt;/h1>
&lt;ol>
&lt;li>
&lt;p>Although the idea is a natural one, the paper is still fairly inspiring, particularly in its architectural design and optimization.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The paper tells its story extremely well, laying out the background and motivation in a way that keeps you engaged — the Pilot Study section is a good example. It makes something simple sound profound and yet remains easy to follow.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>There is a lot to learn from its experiments, such as the ablations and the many small studies; the logic is rigorous throughout.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Its practicality is open to debate. For one thing, a reinforcement learning approach carries real cost. For another, I read this as an end-to-end design, so switching datasets would mean retraining. And perhaps what the trained network ends up deleting is exactly words like with, the, and then — if it really is that rigid, a vocabulary list would do just as well. That last point is, of course, only speculation.&lt;/p>
&lt;/li>
&lt;/ol></description></item><item><title>Paper Review | Jailbreaking LLMs by Exploiting Decoding Strategies</title><link>https://geyuyao.com/post/catastrophic-jailbreak-llms-en/</link><pubDate>Tue, 09 Apr 2024 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/catastrophic-jailbreak-llms-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/catastrophic-jailbreak-llms/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> Catastrophic Jailbreak of Open-source LLMs via Exploiting Generation&lt;/p>
&lt;p>&lt;strong>Institute:&lt;/strong> Princeton University&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Yangsibo Huang, Samyak Gupta, Mengzhou Xia, Kai Li, Danqi Chen&lt;/p>
&lt;p>&lt;strong>Arxiv Link:&lt;/strong> &lt;a href="https://arxiv.org/abs/2310.06987" target="_blank" rel="noopener">https://arxiv.org/abs/2310.06987&lt;/a>&lt;/p>
&lt;p>&lt;strong>Date:&lt;/strong> 2023.10.10&lt;/p>
&lt;h1 id="abstract">Abstract&lt;/h1>
&lt;p>The authors propose a method called &lt;em>generation exploitation&lt;/em>, which attacks an LLM by manipulating its system prompt and decoding hyperparameters. The attack raises the attack success rate (ASR) from 0% to over 95%. Along the way they also propose using a fine-tuned BERT-BASE-CASED model to evaluate the toxicity (harmfulness) of a model&amp;rsquo;s responses. In light of this catastrophic failure of alignment, they put forward an alignment approach named &lt;em>generation-aware alignment&lt;/em>.&lt;/p>
&lt;h1 id="motivation">Motivation&lt;/h1>
&lt;p>The authors observed that the field typically evaluates the alignment of open-source LLMs under the default decoding method alone, such as greedy decoding. Once a malicious user changes the decoding hyperparameters, alignment may fail.&lt;/p>
&lt;p>For instance, prior alignment evaluations on LLAMA2 used the hyperparameters $p = 0.9$ and $\tau = 0.1$, always with a system prompt.&lt;/p>
&lt;ul>
&lt;li>Section 4.1 of the LLAMA2 paper states: &amp;ldquo;For decoding, we set temperature to 0.1 and use nucleus sampling with top-p set to 0.9&amp;rdquo;;&lt;/li>
&lt;li>Appendix A.3.7 of the LLAMA2 paper notes: &amp;ldquo;when collecting generations, we append a system prompt prior to the evaluation prompt.&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;p>Reasonable as this practice may be in principle, it can lead to serious consequences once users adopt a broader range of decoding strategies.&lt;/p>
&lt;h1 id="do-broader-decoding-strategies-lead-to-jailbreaks">Do Broader Decoding Strategies Lead to Jailbreaks?&lt;/h1>
&lt;h2 id="experimental-setup">Experimental Setup&lt;/h2>
&lt;p>To investigate this, the authors break the question into two sub-questions and study each separately.&lt;/p>
&lt;ol>
&lt;li>Does the presence or absence of a system prompt affect jailbreaking?
&lt;ol>
&lt;li>The authors split the experiments into two groups according to whether the default system prompt is used, and compare them to gauge the effect of the system prompt on jailbreaking.&lt;/li>
&lt;/ol>
&lt;/li>
&lt;li>Do decoding hyperparameters affect jailbreaking?
&lt;ol>
&lt;li>Temperature sampling, with $\tau$ varied from 0.05 to 1 in steps of 0.05, giving 20 configurations in total.&lt;/li>
&lt;li>Top-K sampling restricts the candidate pool to the K most probable tokens, and the next token is sampled from that pool alone. The authors vary K over {1, 2, 5, 10, 20, 50, 100, 200, 500}, giving 9 configurations.&lt;/li>
&lt;li>Top-p sampling takes the smallest set of tokens whose cumulative probability exceeds p. Varying p from 0.05 to 1 in steps of 0.05 gives 20 configurations.&lt;/li>
&lt;/ol>
&lt;/li>
&lt;/ol>
&lt;p>For ASR evaluation, the authors use two methods.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>String matching&lt;/strong>: determine alignment by matching a small set of refusal phrases as substrings, such as &amp;ldquo;sorry&amp;rdquo; or &amp;ldquo;I cannot create&amp;rdquo;; if none of these strings is present, the attack is classified as successful.&lt;/li>
&lt;li>&lt;strong>Evaluation with a trained classifier&lt;/strong>: string matching is quite limited, since LLM outputs vary enormously in form. The authors therefore use a fine-tuned BERT-BASE-CASED model to assess the toxicity (harmfulness) of the model&amp;rsquo;s response. The classifier sorts an input string into two classes: correctly aligned and misaligned.&lt;/li>
&lt;/ol>
&lt;p>For data, the authors use AdvBench and their own MaliciousInstruct.&lt;/p>
&lt;h2 id="results">Results&lt;/h2>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/catastrophic-jailbreak-llms/0.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;ol>
&lt;li>&lt;strong>Removing the system prompt increases the attack success rate&lt;/strong>: as the figure above shows, the simple act of removing the system prompt markedly increases the attack success rate (ASR), typically by more than 10%. We observe that the presence of a system prompt plays a crucial role in keeping outputs aligned, especially for models that have not undergone safety tuning. For those models, removing the system prompt can raise ASR by well over 50%. Yet even for a model with explicit safety alignment — the LLAMA2 chat model — ASR still rises once the system prompt is removed.&lt;/li>
&lt;li>&lt;strong>Diverse decoding strategies increase the attack success rate&lt;/strong>: as the figure above shows, performance can indeed be improved by exploring a variety of decoding strategies. In fact, every model except LLAMA2-CHAT exceeds 90% ASR. This stark contrast in performance highlights a catastrophic failure of alignment in the evaluated models.&lt;/li>
&lt;li>&lt;strong>The limits of evaluating alignment with a fixed decoding strategy&lt;/strong>: notably, a fixed decoding configuration on the LLAMA-CHAT models generally yields an ASR below 30%, whereas varying the configuration can push ASR above 80%. These findings underscore that assessing model alignment with a fixed decoding strategy clearly understates the real risk.&lt;/li>
&lt;/ol>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/catastrophic-jailbreak-llms/1.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;p>The figure above reports the decoding strategy to which each model is most vulnerable, showing that different models are vulnerable to different decoding strategies.&lt;/p>
&lt;p>By human judgment, half of the misaligned outputs are harmful.&lt;/p>
&lt;h1 id="pushing-the-attack-further">Pushing the Attack Further&lt;/h1>
&lt;p>The authors use two simple strategies to raise ASR on the safety-aligned LLAMA2-CHAT models to 95%.&lt;/p>
&lt;h2 id="multiple-samples">Multiple Samples&lt;/h2>
&lt;p>Given the nondeterministic nature of sampling-based decoding, increasing the number of sampling runs is an intuitive way to strengthen the attack.&lt;/p>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/catastrophic-jailbreak-llms/1712633120711.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;p>As the figure above shows, drawing multiple samples for each decoding configuration substantially raises the ASR of the LLAMA2-CHAT models to &amp;gt; 95% — specifically, 5 samples for LLAMA2-7B-CHAT and 4 samples for LLAMA2-13B-CHAT reach the 95% level.&lt;/p>
&lt;h2 id="penalty--and-constraint-based-decoding">Penalty- and Constraint-based Decoding&lt;/h2>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/catastrophic-jailbreak-llms/1712633475305.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;p>Another effective strategy is to introduce constraints into the decoding process. Adding a length penalty at decoding time, for example, lifts the attack success rate from 83% to 92%. Adding two further constraints — banning certain &amp;ldquo;bad words&amp;rdquo; (such as &amp;ldquo;sorry&amp;rdquo;, &amp;ldquo;unethical&amp;rdquo;, &amp;ldquo;illegal&amp;rdquo;) and forcing certain words to appear (such as &amp;ldquo;sure&amp;rdquo;, &amp;ldquo;ok&amp;rdquo;) — pushes the attack success rate to 100%.&lt;/p>
&lt;h2 id="comparison-with-gcg">Comparison with GCG&lt;/h2>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/catastrophic-jailbreak-llms/1712633864711.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;p>The authors&amp;rsquo; generation exploitation attack consistently outperforms the state-of-the-art attack across two models, two benchmarks, and two metrics of attack success. Notably, their method is also 30x faster than GCG: launching their attack with a single prompt on LLAMA2-7B-CHAT with one NVIDIA A100 GPU takes about 3 minutes, whereas GCG needs roughly 1.5 hours for the same task (500 steps, batch size 512).&lt;/p>
&lt;h1 id="a-generation-aware-alignment-method">A Generation-aware Alignment Method&lt;/h1>
&lt;p>This section introduces &lt;em>generation-aware alignment&lt;/em>, a method designed to make a model more resistant to generation exploitation attacks — attacks that can cause severe alignment failures. The method works as follows:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Overview&lt;/strong>: under generation-aware alignment, the system proactively collects model outputs produced by a variety of decoding strategies and uses them in the alignment process. A decoding strategy here refers to how the model generates a text sequence from the input prompt.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>The procedure in detail&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>For a language model $f_\theta$ and a given prompt $\mathbf{p}$, the model generates an output sequence $\mathbf{r}$ via a sampling method $h$. Here $h$ is a decoding strategy that maps the language model&amp;rsquo;s probability distribution, conditioned on the prompt $p$, to a token sequence over the vocabulary $\mathcal{V}$.&lt;/li>
&lt;li>For each prompt $\mathbf{p}$, the system collects $n$ responses from different decoding strategies, forming the response set $\mathcal{R}^{\mathbf{p}}$.&lt;/li>
&lt;li>All responses are then split into two groups: the aligned response set $\mathcal{R}&lt;em>{a}^{\mathbf{p}}$ and the misaligned response set $\mathcal{R}&lt;/em>{m}^{\mathbf{p}}$.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Optimization objective&lt;/strong>: generation-aware alignment minimizes the following objective, which comes from the &amp;ldquo;chain of hindsight&amp;rdquo; method:
$$
\mathcal{L} = \frac{1}{|\mathcal{P}|} \sum_{\mathbf{p} \sim \mathcal{P}} \frac{1}{|\mathcal{R}&lt;em>{m}^{\mathbf{p}}| \times |\mathcal{R}&lt;/em>{a}^{\mathbf{p}}|} \sum_{(\mathbf{r}&lt;em>m, \mathbf{r}&lt;em>a) \sim \mathcal{R}&lt;/em>{m}^\mathbf{p} \times \mathcal{R}&lt;/em>{a}^\mathbf{p}} - \log \mathbb{P}(\mathbf{r}_a \mid \mathbf{p}, \mathbf{s}_a) - \log \mathbb{P}(\mathbf{r}_m \mid \mathbf{p}, \mathbf{s}_m)
$$
where $\mathbf{s}_a$ and $\mathbf{s}_m$ denote &amp;ldquo;an aligned answer&amp;rdquo; and &amp;ldquo;a misaligned answer&amp;rdquo; respectively.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>In plain terms, the procedure can be summarized as follows:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Collect answers&lt;/strong>: imagine asking the model a question and, instead of a single answer, getting many answers generated in different ways (the decoding strategies).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Classify the answers&lt;/strong>: next, we sort these answers into two groups, one of correct answers and one of incorrect answers.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Train the model&lt;/strong>: finally, we use this information to train the model, so that it learns to better distinguish which kinds of answers are correct and which are not.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h2 id="results-1">Results&lt;/h2>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/catastrophic-jailbreak-llms/1712633826438.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;p>As the figure above shows, generation-aware alignment lowers the original model&amp;rsquo;s ASR from 95% to 69%. By contrast, aligning on samples drawn with a fixed decoding configuration leaves a higher final ASR of 88%.&lt;/p>
&lt;p>Notably, among the three decoding strategies exploited by the attacker, sampling with diverse decoding configurations gives the largest gain in the model&amp;rsquo;s robustness to temperature attacks.&lt;/p>
&lt;h1 id="open-source-vs-closed-source">Open-source vs. Closed-source&lt;/h1>
&lt;p>All the experiments above were run on open-source models. Here the authors turn to a closed-source one, gpt-3.5-turbo.&lt;/p>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/catastrophic-jailbreak-llms/1712634394552.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;p>&lt;strong>Proprietary models are harder to attack&lt;/strong>. We observe a markedly lower ASR (7%) when attacking the proprietary model (see the figure above), compared with an ASR that usually exceeds 95% on open-source models.&lt;/p>
&lt;p>Two key factors explain the gap.&lt;/p>
&lt;ol>
&lt;li>Proprietary models generally deploy content filters that detect and handle potentially harmful prompts and outputs. We observed, for instance, that 9 of the tested prompts had unusually long request times due to the content filter and were eventually terminated by a timeout error.&lt;/li>
&lt;li>Proprietary models are typically owned by organizations with the resources to conduct extensive red-teaming, which makes those models more resistant to attack.&lt;/li>
&lt;/ol>
&lt;h1 id="conclusion">Conclusion&lt;/h1>
&lt;p>The authors introduce a new dataset, MaliciousInstruct; a way to evaluate the toxicity of model responses; an attack that manipulates decoding hyperparameters, called generation exploitation; and an alignment strategy, generation-aware alignment.&lt;/p>
&lt;p>Generation exploitation requires none of the sophisticated machinery involved in optimizing adversarial prompts; it focuses instead on manipulating different generation strategies. Notably, using 30x less computation than the best existing attack, it misaligns 11 models at rates as high as 95%.&lt;/p></description></item><item><title>Paper Review | TTA: A New Approach to Confidence Estimation for LLMs</title><link>https://geyuyao.com/post/think-twice-before-assure-en/</link><pubDate>Mon, 25 Mar 2024 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/think-twice-before-assure-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/think-twice-before-assure/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> Think Twice Before Assure: Confidence Estimation for Large Language Models through Reflection on Multiple Answers&lt;/p>
&lt;p>&lt;strong>Institute:&lt;/strong> National University of Singapore, University of Science and Technology of China, Meta AI&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Moxin Li, Wenjie Wang, Fuli Feng, Fengbin Zhu, Qifan Wang, Tat-Seng Chua&lt;/p>
&lt;p>&lt;strong>Arxiv Link:&lt;/strong> &lt;a href="https://arxiv.org/abs/2403.09972" target="_blank" rel="noopener">https://arxiv.org/abs/2403.09972&lt;/a>&lt;/p>
&lt;p>&lt;strong>Date:&lt;/strong> 2024.3.15&lt;/p>
&lt;h1 id="abstract">Abstract&lt;/h1>
&lt;p>Assessing the credibility of the output is a critical task for large language models (LLMs), especially black-box ones. Because LLMs are overconfident in the incorrect answers they generate, confidence estimation for LLMs is often inaccurate. Existing approaches to the overconfidence problem share a clear limitation: they consider the confidence of only a single answer generated by the LLM. The authors address this by proposing a new method that assesses the credibility of multiple candidate answers together, thereby mitigating overconfidence in incorrect answers.&lt;/p>
&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;p>The core of confidence estimation is calibration — ensuring that the confidence level matches the actual accuracy of the answer.&lt;/p>
&lt;p>The key to calibrating a black-box LLM is solving the overconfidence problem. LLMs are inherently biased toward trusting the answers they themselves generate, which makes it hard for a model to judge honestly whether its own answer is correct; it tends to assign those answers very high confidence scores.&lt;/p>
&lt;p>Two research paradigms exist today:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>The first (self-consistency) attributes overconfidence in part to the contextual bias between the question, or prompt, and the answer. Researchers therefore try prompt ensembling, constructing a variety of prompt templates and rephrasings of the question.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The second (verbalized methods) focuses on the LLM&amp;rsquo;s self-assessment, with techniques such as instructing the LLM to judge the truthfulness of an answer or applying Chain-of-Thought (CoT) reasoning.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>The limitation of this line of work is that these methods typically consider only a single target answer generated by the LLM. Since the model is overconfident in its own answers, they may still be biased toward incorrect ones.&lt;/p>
&lt;p>The paper gets around this with a new multi-answer assessment paradigm in which the LLM weighs several candidate answers at once, which improves confidence calibration.&lt;/p>
&lt;h1 id="problem-definition">Problem Definition&lt;/h1>
&lt;p>Given an input consisting of a question $q$ and a prompt $p$ — the latter comprising an instruction and optional in-context examples — the LLM generates an answer $a$. Confidence estimation then aims to recover the LLM&amp;rsquo;s confidence in $a$, expressed as a score $c \in R$. Writing the confidence estimation strategy as $CE(·)$, the process is:
$$
a = LLM(p(q)), \
c = CE(LLM(·), p(q), a).
$$&lt;/p>
&lt;h1 id="prior-approaches">Prior Approaches&lt;/h1>
&lt;p>The question thus becomes how to design the confidence estimation function $CE(·)$.&lt;/p>
&lt;p>The obvious approach is to estimate the confidence score from the LLM&amp;rsquo;s output probabilities, written as $c = Pr(LLM(·), p(q), a)$. The paper assumes a black-box setting, though, where the model&amp;rsquo;s internal states are not visible, which rules this out.&lt;/p>
&lt;center> &lt;img style="border-radius: 0.3125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);" src="https://geyuyao.com/post/think-twice-before-assure/1711439658243.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;p>Two approaches currently exist for the black-box setting:&lt;/p>
&lt;ul>
&lt;li>self-consistency, shown as subfigure 1 above&lt;/li>
&lt;li>verbalized methods, shown as subfigure 2 above&lt;/li>
&lt;/ul>
&lt;p>Self-consistency essentially asks the same question several times with different phrasings and looks at the proportion of correct answers. Formally:
$$
\begin{aligned}&amp;amp;c=\frac{\sum_{i=1}^D \mathbb1(a_i=a)}D,\&amp;amp;\mathrm{where~}a_i=LLM(p(q)).\end{aligned}
$$
where $D&amp;gt;1$.&lt;/p>
&lt;p>Verbalized methods simply ask the LLM to state several candidate answers along with their corresponding probabilities.
$$
[{a_1,c_1},&amp;hellip;{a_K,c_K}]=LLM(p^b(q)).
$$&lt;/p>
&lt;p>Both, however, consider only a single target answer generated by the LLM, and since the model is overconfident in its own answers, both may still be biased toward incorrect ones.&lt;/p>
&lt;h1 id="the-proposed-method">The Proposed Method&lt;/h1>
&lt;p>The authors argue that if the LLM thoroughly compares the credibility of more candidate answers, a high confidence in $a$ may be tempered when the LLM has a strong sense that another answer is correct, which lowers the risk of overconfidence.&lt;/p>
&lt;p>They therefore propose TTA, a multi-answer assessment paradigm, in two steps.&lt;/p>
&lt;h2 id="step-1-reflect-and-justify">Step 1: Reflect and justify&lt;/h2>
&lt;p>The LLM first reflects on the credibility of each answer $a^q_i$ and is asked to find evidence $e_i$ justifying $a^q_i$ as a correct answer to $q$.
$$
e_i = LLM(p^e(q, a^q_i)), i \in {1, &amp;hellip;, N}
$$
The rationale for this step is that $p^e$ guides the LLM to derive a justification from $q$ and $a^q_i$, avoiding the bias the LLM carries in generating $a$ from $p(q)$.&lt;/p>
&lt;h2 id="step-2-joint-confidence-estimation">Step 2: Joint confidence estimation&lt;/h2>
&lt;center> &lt;img style="border-radius: 0.3125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);" src="https://geyuyao.com/post/think-twice-before-assure/1711439658243.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;p>Once evidence $e_i$ has been gathered for every $a^q_i$, a Top-$K$ verbalized method integrates the $e_i$ and yields the probability of answer $a$.
$$
c = Pr(LLM(\cdot), p^v(q, [e_1, &amp;hellip;, e_N]), a)
$$
The Top-$K$ verbalized method is chosen here because it produces $K$ candidate answers together with their probabilities in a single response.&lt;/p>
&lt;p>Here $K$ is set to the number of answers $N$.&lt;/p>
&lt;p>The whole process can be formalized as:
$$
c = Pr(LLM(\cdot), p^v(q, [e_1, &amp;hellip;, e_N]), a), \
\notag
\text{where } e_i = LLM(p^e(q, a^q_i)), i \in {1, &amp;hellip;, N}.
$$
The pipeline is shown as subfigure 3 above.&lt;/p>
&lt;h1 id="experiments">Experiments&lt;/h1>
&lt;h2 id="datasets--models">Datasets &amp;amp; Models&lt;/h2>
&lt;p>The paper runs experiments on three tasks across six datasets.&lt;/p>
&lt;p>Sentiment analysis (SA) uses IMDB and Flipkart; natural language inference (NLI) uses SNLI and HANS; commonsense question answering (CQA) uses CommonsenseQA and PIQA.&lt;/p>
&lt;p>The models are OpenAI&amp;rsquo;s GPT-3.5 and GPT-4 and ZhipuAI&amp;rsquo;s GLM-4.&lt;/p>
&lt;h2 id="baseline">Baseline&lt;/h2>
&lt;p>Self-cons, CoT-cons, Top-K Verb, Hybrid, Self-detect, CAPE, P(True).&lt;/p>
&lt;h2 id="evaluation">Evaluation&lt;/h2>
&lt;p>AUROC and PRAUC, both ranging from 0 to 1.&lt;/p>
&lt;h2 id="result">Result&lt;/h2>
&lt;center> &lt;img style="border-radius: 0.3125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);" src="https://geyuyao.com/post/think-twice-before-assure/1711440605017.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">Results of the compared methods on GPT-3.5&lt;/div>&lt;/center>
&lt;ol>
&lt;li>Answer accuracy is better separated by the confidence scores, yielding better calibration.&lt;/li>
&lt;li>TTA has strong application potential in selective prediction scenarios.&lt;/li>
&lt;li>LLMs&amp;rsquo; parameter sensitivity varies across different target answers.&lt;/li>
&lt;li>TTA achieves better calibration performance than the other methods.&lt;/li>
&lt;/ol></description></item><item><title>Paper Review | A Survey of LLM Agents for Games</title><link>https://geyuyao.com/post/game-playing-agents-survey-en/</link><pubDate>Thu, 21 Mar 2024 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/game-playing-agents-survey-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/game-playing-agents-survey/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> A Survey on Game Playing Agents and Large Models: Methods, Applications, and Challenges&lt;/p>
&lt;p>&lt;strong>Institute:&lt;/strong> Beijing Academy of Artificial Intelligence (BAAI); Institute of Software, Chinese Academy of Sciences; University of Chinese Academy of Sciences; Dartmouth College; Beijing University of Posts and Telecommunications; Peking University&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Xinrun Xu, Yuxin Wang, Chaoyi Xu, Ziluo Ding, Jiechuan Jiang, Zhiming Ding, Börje F. Karlsson&lt;/p>
&lt;p>&lt;strong>Arxiv Link:&lt;/strong> &lt;a href="https://arxiv.org/abs/2403.10249" target="_blank" rel="noopener">https://arxiv.org/abs/2403.10249&lt;/a>&lt;/p>
&lt;p>&lt;strong>Date:&lt;/strong> 2024.3.15&lt;/p>
&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;center> &lt;img style="border-radius: 0.3125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);" src="https://geyuyao.com/post/game-playing-agents-survey/1711099570041.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;p>Large models (LMs), covering both language models and multimodal models, have made substantial progress in many important areas. That progress has prompted researchers to explore using LMs as agents that carry out complex tasks. Compared with conventional models, LM-based agents (LMAs) generalize considerably better in many settings.&lt;/p>
&lt;p>The capabilities demonstrated by LM-based agents have generated strong interest in applying them to games. Games offer agents a virtual environment whose challenges demand complex reasoning and cognitive ability, making them an ideal benchmark for evaluating agents. Relative to real-world experiments, collecting data in a game environment offers unmatched advantages in cost, controllability, safety, and diversity, while still preserving a meaningful level of difficulty.&lt;/p>
&lt;p>Before asking how to make large models play games, it is worth first considering how humans play them.&lt;/p>
&lt;p>The human brain, as a complex information-processing system, first converts sensory input into perceptual representations, then uses those representations to build knowledge about the world and make decisions, and finally carries them out through action. This sequence can be abstracted into an iterative agent loop: &lt;strong>perception&lt;/strong>, &lt;strong>inference&lt;/strong>, and &lt;strong>action&lt;/strong>.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Perception&lt;/strong>: converting the raw information observed during gameplay into an actionable understanding of the game that supports subsequent interaction. Early work turned text into semantic information; more recent work attempts to bring visual information into the picture as well.&lt;/li>
&lt;li>&lt;strong>Inference&lt;/strong>: this stage involves many of an agent&amp;rsquo;s key capabilities, including memory, learning, reasoning, reflection, and decision making.
&lt;ul>
&lt;li>&lt;strong>Memory&lt;/strong>: storing and retrieving learned knowledge.&lt;/li>
&lt;li>&lt;strong>Learning&lt;/strong>: adjusting policies through experience and through skills acquired in multi-agent systems.&lt;/li>
&lt;li>&lt;strong>Reasoning&lt;/strong>: the process of solving problems by processing and aggregating information. In complex games, decision making requires multi-hop reasoning and long-horizon planning, task decomposition, and collaborative decisions to cope with dynamic game environments.&lt;/li>
&lt;li>&lt;strong>Reflection&lt;/strong>: the process of self-improvement, in which the agent evaluates and adjusts its strategy based on feedback.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;strong>Action&lt;/strong>: covering interaction with the game environment, that is, the agent&amp;rsquo;s response to the game state and to environmental feedback.
&lt;ul>
&lt;li>&lt;strong>Code generation&lt;/strong>: many agent behaviors are executed by generating code, using techniques such as iterative prompting, role-specific prompting, and code generation. &lt;em>GPT-4 in fact does this all the time. For example, if we ask GPT to analyze a table for us, it will write a Python snippet to read, analyze, and visualize the table, and then report the result back to us as text.&lt;/em>&lt;/li>
&lt;li>&lt;strong>Dialogue interaction&lt;/strong>: dialogue covers not only agent-to-agent communication but also human-agent interaction. These interactions are realized through collaboration frameworks and dialogue control mechanisms that enable dynamic and effective communication, the goal being to flexibly adapt conversational behavior to the needs and context of the interaction.&lt;/li>
&lt;li>&lt;strong>Behavioral consistency&lt;/strong>: behavioral consistency means that the agent acts in a predictable, stable, and coherent pattern across different situations. Structured approaches such as DAGs, feedback mechanisms, and reinforcement learning can be used to achieve this.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>Note that two notions Chinese renders with the same word are distinct in English: &lt;em>inference&lt;/em> and &lt;em>reasoning&lt;/em>. Inference emphasizes extending existing information logically and extracting conclusions from it, whereas reasoning covers a broader range of thinking and logical deduction.&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>The &amp;ldquo;world model&amp;rdquo; mentioned above can be understood as the knowledge about the world that the human brain builds from perceptual representations. Here the world model is the brain&amp;rsquo;s internal representation of the external environment — an understanding of objects, events, scenes, and the relations among them — which helps an individual make sense of their surroundings, predict future events, and, on that basis, decide and act.&lt;/p>
&lt;/blockquote>
&lt;h1 id="perception">Perception&lt;/h1>
&lt;p>Perceiving the raw scene of a game and extracting information from it is crucial to every step that follows. The main function of perception is to convert the multimodal space — visual, semantic, and auditory — into input for the agent.&lt;/p>
&lt;p>Modern digital games integrate multimodal perceptual channels to give human players a richer, more immersive experience, letting them sink more deeply into the game world. Unfortunately, however, there is not much existing work on incorporating &lt;strong>audio data&lt;/strong> into the training of large models or into the optimization of game agents.&lt;/p>
&lt;h2 id="semantic-perception">Semantic Perception&lt;/h2>
&lt;p>Perception on the semantic side refers mainly to the textual elements and textual descriptions in a game, ranging from natural-language instructions to dialogue. It means that the player understands the various elements of the game environment and the events taking place — and makes decisions and acts — by reading and interpreting text.&lt;/p>
&lt;p>Semantic perception can be divided into four categories:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Simple text input&lt;/strong>: the user&amp;rsquo;s simple ideas or descriptions, basic game state variables, and dialogue between characters.&lt;/li>
&lt;li>&lt;strong>Structured or role-based input&lt;/strong>: a character&amp;rsquo;s attributes, backstory, related information, skills, and so on.&lt;/li>
&lt;li>&lt;strong>Environmental and context-specific input&lt;/strong>: detailed game descriptions and contextual information, as well as natural-language instructions for tasks.&lt;/li>
&lt;li>&lt;strong>Multimodal input&lt;/strong>: integrating visual, auditory, and textual data for decision making, and combining dialogue, game state, and scripts to enable richer interaction.&lt;/li>
&lt;/ul>
&lt;h2 id="visual-perception">Visual Perception&lt;/h2>
&lt;p>We mentioned above that multimodal information such as vision can be converted into text. Converting other modalities into text, however, may discard a great deal of important information, easily leaving the agent unable to understand the situation it faces or to navigate the game. LMAs therefore need more comprehensive perceptual data.&lt;/p>
&lt;p>Multimodal large language models (MLLMs) have become one solution to this problem. With an MLLM, an agent can obtain a richer perception of its surroundings, which in turn supports more sophisticated cognitive processes and decision making in environments resembling the real world.&lt;/p>
&lt;p>For this visual space, three distinct perception approaches exist today:&lt;/p>
&lt;ol>
&lt;li>Obtaining game-related information through dedicated APIs and feeding that information to the agent.&lt;/li>
&lt;li>Pre-training the model on image and action data.&lt;/li>
&lt;li>Feeding in pure image information directly.&lt;/li>
&lt;/ol>
&lt;h1 id="inference">Inference&lt;/h1>
&lt;p>In the opening stage of a game, the agent needs to absorb basic commonsense and game-specific background knowledge, either through pre-training or through real-time perception. During gameplay, the agent synthesizes past game events, manages knowledge storage and retrieval, and performs core cognitive functions such as learning, reasoning, decision making, and reflection.&lt;/p>
&lt;h2 id="memory">Memory&lt;/h2>
&lt;p>To correctly represent learned knowledge or past events and to use that information during inference, an agent must operate on these &amp;ldquo;memories&amp;rdquo; effectively. How to design a high-quality memory mechanism that lets an agent &lt;strong>retrieve&lt;/strong> and &lt;strong>store&lt;/strong> memories efficiently while &lt;strong>fully exploiting&lt;/strong> the underlying large language model and &lt;strong>respecting its constraints&lt;/strong> remains an open problem.&lt;/p>
&lt;h3 id="commonsense">Commonsense&lt;/h3>
&lt;p>Commonsense knowledge is knowledge that people typically acquire early in life and that often goes unstated in a given situation; it is essential for reasoning and for avoiding misunderstandings.&lt;/p>
&lt;p>Large language models, pre-trained on diverse internet text, already demonstrate advanced language understanding and reasoning, and can bring this implicit knowledge to bear on new challenges. That knowledge, however, may not always align perfectly with a specific application context such as a particular game scenario. Current research therefore aims to strengthen a language model&amp;rsquo;s commonsense understanding in the following ways:&lt;/p>
&lt;ol>
&lt;li>Embedding structured knowledge through &lt;strong>instruction fine-tuning&lt;/strong>.&lt;/li>
&lt;li>Using an &lt;strong>SOP&lt;/strong> to integrate commonsense into a specific role and task. For instance, if a model is used to play the role of a doctor, the SOP might contain medical commonsense, guidelines for communicating with patients, and standard procedures for diagnosis and treatment. This allows the model to act more effectively and adaptively in simulated or real situations, since it draws on the commonsense in the SOP to guide its decisions and behavior.&lt;/li>
&lt;li>Using &lt;strong>RAG&lt;/strong> (retrieval-augmented generation).&lt;/li>
&lt;/ol>
&lt;h3 id="game-background-knowledge">Game Background Knowledge&lt;/h3>
&lt;p>For large models, game background knowledge means an understanding of the various aspects of the game environment.&lt;/p>
&lt;p>Current techniques incorporate basic game rules, basic procedures, reasoning ability, and one-shot demonstrations into the prompt. For example:&lt;/p>
&lt;ol>
&lt;li>Feeding a detailed character profile to the large model through the prompt.&lt;/li>
&lt;li>Using knowledge graphs to describe relations among entities.&lt;/li>
&lt;li>Using detailed scenarios drawn from simulated environments and role-playing game (RPG) logs, which markedly improves the language model&amp;rsquo;s understanding of game dynamics.&lt;/li>
&lt;li>Building an external knowledge base from the Minecraft Wiki and from documentation of item crafting/smelting recipes, creating an exhaustive source of knowledge about the Minecraft world for the agent to consult.&lt;/li>
&lt;/ol>
&lt;h3 id="retrieval">Retrieval&lt;/h3>
&lt;p>Memory retrieval in LMAs means strengthening reasoning and action by recalling learned information.&lt;/p>
&lt;p>Memory retrieval methods for LMAs fall into three categories: structured memory systems, dynamic adaptive retrieval processes, and advanced memory retrieval techniques.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Structured memory systems&lt;/strong>: these techniques aim to organize and index information efficiently for fast retrieval. Skill libraries, shared message pools, hierarchical structures, and structured communication all exist so that an agent can quickly access previously acquired skills and knowledge, enabling effective memory management. A &amp;ldquo;summarize and forget&amp;rdquo; memory mechanism prioritizes critical memory items by summarizing important information and discarding the rest, thereby lowering computational cost.&lt;/li>
&lt;li>&lt;strong>Dynamic adaptive retrieval processes&lt;/strong>: this approach retrieves memories by combining relevance, recency, and importance, with strategic collection emphasizing the relevance and freshness of historical game information. The process also involves continually adjusting plans in light of new circumstances, ensuring that the agent&amp;rsquo;s behavior adapts as the game changes. Put simply, the approach updates and adjusts the agent&amp;rsquo;s memory in real time so that better decisions can be made.&lt;/li>
&lt;li>&lt;strong>Advanced memory retrieval techniques&lt;/strong>: these include (1) using long short-term memory (LSTM) to retain memories of past events, (2) generating more concise state descriptions to help the agent quickly grasp the current game situation, and (3) compressing historical text sequences to save space and improve efficiency. In short, these techniques help agents manage and use their memories more precisely and effectively.&lt;/li>
&lt;/ol>
&lt;h2 id="learning">Learning&lt;/h2>
&lt;p>Learning in the context of large models (LMs) involves interpreting and integrating information from a variety of sources, including training data, user interaction, and environmental feedback.&lt;/p>
&lt;p>The learning process can be explicit — for example, fine-tuning on a specific dataset or task-focused training — or implicit, as when pre-existing knowledge is used to adapt to a new scenario.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Iterative and feedback-based learning&lt;/strong>: combines iterative prompting, role prompting, feedback mechanisms, and behavior cloning to strengthen capability through continuous feedback and adaptation.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Reinforcement learning and offline learning&lt;/strong>: includes reinforcement learning with environmental feedback, offline learning, and reinforcement learning driven by language instructions. Whereas iterative feedback-based learning focuses on optimizing model behavior through continuous real-time feedback, this approach focuses on maximizing long-term reward or achieving a specific goal through interaction with the environment, whether live or based on historical data.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Experience-based learning with memory&lt;/strong>: focuses on drawing on past experience, memory retrieval, and experience pools to guide current and future actions.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Collaborative and adaptive learning&lt;/strong>: emphasizes learning through multi-agent cooperation, adaptive strategies, and interactive learning processes.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h2 id="reasoning">Reasoning&lt;/h2>
&lt;p>Reasoning involves abstracting the foundational knowledge acquired during the learning stage into higher forms of understanding, via deductive, inductive, or abductive inference.&lt;/p>
&lt;h2 id="decision-making">Decision Making&lt;/h2>
&lt;p>In the vast worlds of games, particularly in open-world and immersive environments, players and AI agents face complex decision and action spaces.&lt;/p>
&lt;p>These spaces contain an enormous number of possible actions, interactions, and decisions, with a wide range of characters, item uses, and skill combinations. Multi-agent planning can add yet another layer of complexity, requiring coordination and collaboration among multiple agents under incomplete information.&lt;/p>
&lt;h3 id="multi-hop-reasoning">Multi-hop Reasoning&lt;/h3>
&lt;p>Multi-hop reasoning refers to the cognitive process of considering multiple layers of information and dependencies before making a decision.&lt;/p>
&lt;p>In a strategy game, for example, the agent must assess the current situation, anticipate the opponent&amp;rsquo;s moves, evaluate the potential outcomes of various actions, and only then settle on the most advantageous course.&lt;/p>
&lt;h3 id="long-horizon-planning">Long-horizon Planning&lt;/h3>
&lt;p>Long-horizon planning refers to the strategic process by which an agent sets a goal and determines the actions that will achieve it over an extended period.&lt;/p>
&lt;p>Some researchers have proposed using chain-of-thought (CoT) planning to imitate human reasoning, generating the intermediate steps that lead to a final decision, where each step builds on the previous one until the goal is reached.&lt;/p>
&lt;h2 id="reflection">Reflection&lt;/h2>
&lt;p>Reflection refers to the ability of LM-based agents (LMAs) to assess, evaluate, and possibly adjust their own processes, decisions, or outputs as a task unfolds.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Feedback-based self-improvement&lt;/strong>: the process of self-verification, analysis, and iterative enhancement using external feedback such as environmental responses or code execution results.&lt;/li>
&lt;li>&lt;strong>Iteratively refining plans and actions&lt;/strong>: methods that continually refine plans or actions based on feedback and new information, the better to achieve or adapt to a goal.&lt;/li>
&lt;li>&lt;strong>Collaboration and multi-agent interaction&lt;/strong>: emphasizes collaboratively re-evaluating and adjusting decisions within a multi-agent system.&lt;/li>
&lt;li>&lt;strong>Debate and theory-of-mind-based reflection&lt;/strong>: uses a debate or exchange format as a model of the reflection process.&lt;/li>
&lt;/ul>
&lt;h1 id="action">Action&lt;/h1>
&lt;p>The action space in which LMAs operate within games can be classified into three distinct types.&lt;/p>
&lt;ol>
&lt;li>Text-based interaction&lt;/li>
&lt;li>Interaction through APIs&lt;/li>
&lt;li>Direct control via IO operations, such as keyboard and mouse.&lt;/li>
&lt;/ol>
&lt;h2 id="behavior">Behavior&lt;/h2>
&lt;p>LMAs perform specific operations through generative programming techniques. Iterative prompting combined with environmental feedback, execution errors, and self-verification continually refines the generated program, ensuring its validity and relevance to the task at hand.&lt;/p>
&lt;h2 id="dialogue">Dialogue&lt;/h2>
&lt;p>LMAs interact with humans or with other agents by taking into account the current environment and past experience.&lt;/p>
&lt;p>Examples include agent-agent interaction and human-agent interaction.&lt;/p>
&lt;p>Past research has shown that LMAs exhibit human-like social behavior in collaboration, such as teamwork, leadership, persuasion, deception, and confrontation.&lt;/p>
&lt;h2 id="consistency">Consistency&lt;/h2>
&lt;p>Action consistency means that an agent&amp;rsquo;s actions must remain coherent and aligned with its goals.&lt;/p>
&lt;p>To maintain such consistency, the agent takes past experience and the current situation into account, exploits feedback mechanisms, and revises its actions and plans when necessary.&lt;/p>
&lt;p>Concrete strategies include:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Look-ahead checking mechanisms&lt;/strong>: assessing whether an action is feasible.&lt;/li>
&lt;li>&lt;strong>Reinforcement learning (RL)&lt;/strong>: training a policy that selects the most appropriate action.&lt;/li>
&lt;li>&lt;strong>Self-consistency (SC)&lt;/strong>: generating multiple action predictions and selecting the most frequent one for consistent decision making, as in the PokéLLMon case.&lt;/li>
&lt;/ul>
&lt;p>Structural approaches include:&lt;/p>
&lt;ul>
&lt;li>Using a directed acyclic graph to control the progression of actions.&lt;/li>
&lt;li>Leveraging a skill library.&lt;/li>
&lt;li>Defining structured actions with clear semantics.&lt;/li>
&lt;li>Assigning specific roles to agents and following a structured workflow.&lt;/li>
&lt;li>Neuro-symbolic methods.&lt;/li>
&lt;/ul>
&lt;h1 id="challenges">Challenges&lt;/h1>
&lt;h2 id="hallucination">Hallucination&lt;/h2>
&lt;p>An LM can produce output that does not match the source material or the facts, a phenomenon usually called hallucination and one that is very hard to eliminate.&lt;/p>
&lt;p>Introducing critic agents, SOPs, and role-specific prompts can reduce logical hallucinations.&lt;/p>
&lt;p>Researchers have also tried in-context reinforcement learning (ICRL), retrieval-augmented generation (RAG), multi-agent debate, and other methods to address hallucination.&lt;/p>
&lt;h2 id="error-correction">Error Correction&lt;/h2>
&lt;p>Here, much research adopts iterative prompting mechanisms, feedback mechanisms, or chat chains among agents to identify and correct errors.&lt;/p>
&lt;p>Methods such as using critic agents for selection and feedback, and iterative prompting with environmental feedback, are employed for error correction.&lt;/p>
&lt;h2 id="generalization">Generalization&lt;/h2>
&lt;p>Generalization refers to an agent&amp;rsquo;s ability to apply the knowledge, skills, and capabilities acquired in past environments to new, previously unseen environments so that it can still achieve goals and carry out tasks.&lt;/p>
&lt;p>Proposed solutions include context-aware chain-of-thought (CoT) reasoning, GITM (Ghost in the Minecraft), which exploits long-horizon planning and external knowledge in Minecraft, and information extraction and collaborative planning in multi-agent settings.&lt;/p>
&lt;h2 id="interpretability">Interpretability&lt;/h2>
&lt;p>Some studies use CoT processes, modular decision processes, and clear conversational programming paradigms to make agent behavior more interpretable.&lt;/p>
&lt;h1 id="future-directions">Future Directions&lt;/h1>
&lt;h2 id="multimodal-perception">Multimodal Perception&lt;/h2>
&lt;p>Strengthening multimodal capability, including visual and auditory perception, may allow agents to handle more complex tasks.&lt;/p>
&lt;p>It is worth noting that sound effects in games are essential for perceiving context, understanding tasks, and receiving feedback, yet very little literature explores how &lt;strong>auditory information&lt;/strong> can be used to improve the performance of game agents.&lt;/p>
&lt;h2 id="authenticity-of-the-game-experience">Authenticity of the Game Experience&lt;/h2>
&lt;p>People prefer human-written content to dialogue and ideas generated by large language models. This suggests that future research needs to tie LLM-generated content more closely to the game&amp;rsquo;s narrative and state.&lt;/p>
&lt;h2 id="external-tools">External Tools&lt;/h2>
&lt;p>LM-based agents have yet to master the use of external tools to improve their own performance in games.&lt;/p>
&lt;h2 id="real-time-performance">Real-time Performance&lt;/h2>
&lt;p>Given the inference process and computational demands inherent to large models, mastering real-time, high-speed games poses a formidable challenge.&lt;/p></description></item><item><title>Paper Review | An LLM Survey from Tomas Mikolov, Author of Word2Vec</title><link>https://geyuyao.com/post/large-language-models-survey-en/</link><pubDate>Sat, 16 Mar 2024 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/large-language-models-survey-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/large-language-models-survey/">中文&lt;/a>
&lt;/div>
&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;center> &lt;img style="border-radius: 0.2125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);width: 100%;" src="https://geyuyao.com/post/large-language-models-survey/1710679207909.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;p>Large language models (LLMs) refer mainly to Transformer-based neural language models that contain tens to hundreds of billions of parameters and are pre-trained on massive text corpora — models such as PaLM, LLaMA, and GPT-4. Compared with PLMs, LLMs are not only larger in scale but also stronger in language understanding and generation, and more importantly, they exhibit emergent abilities that are absent in smaller language models. As the figure above shows, these emergent abilities include (1) in-context learning, where LLMs learn a new task at inference time from a handful of examples presented in the prompt; (2) instruction following, where after instruction tuning LLMs can follow instructions for new types of tasks without any explicit examples; and (3) multi-step reasoning, where LLMs solve complex tasks by decomposing them into intermediate reasoning steps, as in chain-of-thought prompting. LLMs can also be augmented with external knowledge and tools so that they interact effectively with users and their environment, and they can keep improving themselves through feedback data collected from human interaction (for example, via reinforcement learning from human feedback, RLHF).&lt;/p>
&lt;h1 id="large-language-models">Large Language Models&lt;/h1>
&lt;center> &lt;img style="border-radius: 0.2125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);width: 80%;" src="https://geyuyao.com/post/large-language-models-survey/1710686762203.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;h2 id="early-pre-trained-neural-networks">Early Pre-trained Neural Networks&lt;/h2>
&lt;p>In 1999, Bengio et al. developed the earliest neural language models (NLMs), which were competitive with n-gram models. Since then, NLMs based on recurrent neural networks (RNNs) and their variants — such as long short-term memory (LSTM) and the gated recurrent unit (GRU) — have been widely used in many natural language applications, including machine translation, text generation, and text classification. The invention of the Transformer architecture later marked another milestone in the development of neural language models. Transformers offer parallelism that RNNs lack, which makes it possible to pre-train very large language models efficiently on GPUs. These pre-trained language models (PLMs) can then be fine-tuned for many downstream tasks.&lt;/p>
&lt;p>We group the early popular Transformer-based PLMs into three main categories according to their neural architecture — encoder-only, decoder-only, and encoder-decoder — and introduce each below.&lt;/p>
&lt;h3 id="encoder-only-plms">&lt;em>Encoder-only PLMs:&lt;/em>&lt;/h3>
&lt;p>As the name suggests, encoder-only models contain only an encoder network. They were originally developed for language understanding tasks such as text classification, where the model must predict a category label for the input text. The representative model is BERT, along with its variants such as RoBERTa, ALBERT, DeBERTa, XLM, XLNet, and UNILM.&lt;/p>
&lt;center> &lt;img style="border-radius: 0.2125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);width: 100%;" src="https://geyuyao.com/post/large-language-models-survey/1710680176745.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">Overall pre-training and fine-tuning pipeline of BERT&lt;/div>&lt;/center>
&lt;p>BERT (Bidirectional Encoder Representations from Transformers) is one of the most widely used encoder-only models. It consists of three modules: (1) an embedding module that converts the input text into a sequence of embedding vectors, (2) a stack of Transformer encoders that turns those embedding vectors into contextual representation vectors, and (3) a fully connected layer that maps the representation vectors (at the final layer) into one-hot vectors. BERT is pre-trained with two objectives: masked language modeling (MLM) and next sentence prediction. A pre-trained BERT model can be fine-tuned by adding a classifier layer for many language understanding tasks, ranging from text classification and question answering to language inference. The overall pre-training and fine-tuning pipeline of BERT is shown in the figure above.&lt;/p>
&lt;h3 id="decoder-only-plms">&lt;em>Decoder-only PLMs&lt;/em>&lt;/h3>
&lt;p>Among decoder-only PLMs, the most representative are GPT-1 and GPT-2, developed by OpenAI, which paved the way for GPT-3.5 and GPT-4.&lt;/p>
&lt;center> &lt;img style="border-radius: 0.2125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);width: 100%;" src="https://geyuyao.com/post/large-language-models-survey/1710680578957.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">Overview of the GPT pre-training and fine-tuning steps&lt;/div>&lt;/center>
&lt;p>GPT-1 was the first to demonstrate that training a decoder-only generative pre-training (GPT) model in a self-supervised fashion on an unlabeled text corpus, and then applying discriminative fine-tuning on each specific downstream task, yields good performance across a wide range of natural language tasks.&lt;/p>
&lt;p>GPT-2 showed that when trained on WebText — a large dataset composed of millions of web pages — a language model can learn to perform specific natural language tasks without any explicit supervision.&lt;/p>
&lt;blockquote>
&lt;p>Self-supervised learning: a subset of unsupervised learning. In self-supervised learning, the model uses an unlabeled dataset itself as training data. For instance, during GPT training the model predicts the next token, and this prediction task requires no externally annotated data, because the next token comes directly from the input data itself.&lt;/p>
&lt;/blockquote>
&lt;h3 id="encoder-decoder-plms">&lt;em>Encoder-Decoder PLMs&lt;/em>&lt;/h3>
&lt;p>Prior research has shown that nearly every natural language processing task can be cast as a sequence-to-sequence generation task. An encoder-decoder language model is therefore a unified model by design, since it can perform all natural language understanding and generation tasks. The most representative models in this category are T5, mT5, MASS, and BART.&lt;/p>
&lt;h2 id="llm-families">LLM Families&lt;/h2>
&lt;center> &lt;img style="border-radius: 0.2125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);width: 100%;" src="https://geyuyao.com/post/large-language-models-survey/1710682371551.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;p>Large language models (LLMs) refer mainly to Transformer-based PLMs with billions to hundreds of billions of parameters. Compared with the PLMs above, LLMs are not only larger in size but also stronger in language understanding and generation, and they exhibit emergent abilities that smaller models lack. Next, we review three LLM families: GPT, LLaMA, and PaLM.&lt;/p>
&lt;h3 id="the-gpt-family">&lt;em>The GPT Family&lt;/em>&lt;/h3>
&lt;p>Generative Pre-Training (GPT) is a family of decoder-only models developed by OpenAI. The family includes GPT-1, GPT-2, GPT-3, InstructGPT, ChatGPT, GPT-4, CODEX, and WebGPT. While the earlier GPT models, such as GPT-1 and GPT-2, are open source, the more recent ones, such as GPT-3 and GPT-4, are closed source and accessible only through an API.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>GPT-3&lt;/strong>: a pre-trained autoregressive language model with 175 billion parameters. GPT-3 is widely regarded as the first LLM, because it is not only far larger than previous PLMs but also the first to display emergent abilities not observed in smaller PLMs. GPT-3 demonstrated the emergent ability of in-context learning, meaning that it can be applied to any downstream task without any gradient update or fine-tuning.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>CODEX&lt;/strong>: a general-purpose programming model that can parse natural language and generate code in response. CODEX is a descendant of GPT-3, fine-tuned for programming applications on a code corpus collected from GitHub.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>WebGPT&lt;/strong>: another descendant of GPT-3, fine-tuned to answer open-ended questions using a text-based web browser, helping users search and browse the web.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>InstructGPT&lt;/strong>: proposed to make LLMs follow human instructions, InstructGPT is fine-tuned with human feedback (RLHF) so that it stays aligned with user intent across a wide range of tasks.&lt;/p>
&lt;blockquote>
&lt;center> &lt;img style="border-radius: 0.2125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);width: 100%;" src="https://geyuyao.com/post/large-language-models-survey/图片.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">Overview of RLHF&lt;/div>&lt;/center>
&lt;p>RLHF: starting from a set of prompts written by labelers together with prompts submitted through the OpenAI API, a dataset of labeler demonstrations of the desired model behavior is collected. GPT-3 is then fine-tuned on this dataset. Next, a dataset of human-ranked model outputs is collected, and the model is further fine-tuned with reinforcement learning. This approach is called reinforcement learning from human feedback (RLHF).&lt;/p>
&lt;/blockquote>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>ChatGPT (GPT-3.5)&lt;/strong>: the most significant milestone in LLM development is ChatGPT, released on November 30, 2022. ChatGPT is a chatbot that lets users steer a conversation to accomplish a variety of tasks, such as answering questions, seeking information, and summarizing text. ChatGPT is powered by GPT-3.5 and is a sibling model to InstructGPT.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;center> &lt;img style="border-radius: 0.2125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);width: 100%;" src="https://geyuyao.com/post/large-language-models-survey/1710681340133.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">Performance of GPT-4 on academic and professional exams compared with GPT-3.5&lt;/div>&lt;/center>
&lt;ul>
&lt;li>&lt;strong>GPT-4&lt;/strong>: the newest and most powerful LLM in the GPT series. Released in March 2023, GPT-4 is a multimodal LLM that accepts both images and text as input and produces text output. Although it still falls short of humans in some of the most challenging real-world scenarios, GPT-4 achieves human-level performance on a variety of professional and academic benchmarks, including passing a simulated bar exam with a score around the top 10% of test takers, as shown in the figure above. Like earlier GPT models, GPT-4 is first pre-trained to predict the next token on a large text corpus, and then fine-tuned with RLHF to align its behavior with what humans expect.&lt;/li>
&lt;/ul>
&lt;h3 id="the-llama-family">&lt;em>The LLaMA Family&lt;/em>&lt;/h3>
&lt;p>LLaMA is a series of large language models released by Meta. Unlike the GPT models, LLaMA models are open source.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>LLaMA-1&lt;/strong>: the first batch of LLaMA models was released in February 2023, with parameter counts ranging from 7B to 65B. These models were pre-trained on trillions of tokens collected from publicly available datasets. LLaMA adopts the Transformer architecture of GPT-3 with a few minor architectural modifications.&lt;/li>
&lt;li>&lt;strong>LLaMA-2&lt;/strong>: in July 2023, Meta, in collaboration with Microsoft, released the LLaMA-2 family, which includes base language models as well as chat models fine-tuned for dialogue, known as LLaMA-2 Chat.&lt;/li>
&lt;/ul>
&lt;h3 id="the-palm-family">&lt;em>The PaLM Family&lt;/em>&lt;/h3>
&lt;p>The PaLM (Pathways Language Model) family was developed by Google.&lt;/p>
&lt;ul>
&lt;li>The first PaLM model was announced in April 2022. It was pre-trained on 6,144 TPUv4 chips using the Pathways system, contains 540 billion parameters, and was open-sourced in March 2023.&lt;/li>
&lt;li>PaLM-2 is trained with a mixture of objectives, unlike its predecessor PaLM. Through extensive evaluation on English, multilingual, and reasoning tasks, PaLM-2 substantially improves downstream task performance across model sizes while demonstrating faster and more efficient inference than PaLM.&lt;/li>
&lt;/ul>
&lt;h3 id="others">&lt;em>Others&lt;/em>&lt;/h3>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Mistral-7B&lt;/strong>: a 7B-parameter language model engineered for superior performance and efficiency. Mistral-7B outperforms LLaMA-2-13B on all evaluation benchmarks and surpasses LLaMA-34B on reasoning, mathematics, and code generation. The model uses &lt;strong>grouped-query attention&lt;/strong> for faster inference, combined with &lt;strong>sliding window attention&lt;/strong> to handle sequences of arbitrary length effectively while lowering inference cost.&lt;/p>
&lt;center> &lt;img style="border-radius: 0.2125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);width: 100%;" src="https://geyuyao.com/post/large-language-models-survey/1710682078104.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">The BLOOM architecture&lt;/div>&lt;/center>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>BLOOM&lt;/strong>: Scao et al. proposed BLOOM, an open-access language model with 176B parameters, designed and built collaboratively by hundreds of researchers. BLOOM is a decoder-only Transformer language model trained on the ROOTS corpus, which spans hundreds of sources (59 in total) covering 46 natural languages and 13 programming languages. Its architecture is shown in the figure above.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>GLM&lt;/strong>: a large bilingual (English and Chinese) pre-trained language model with 130 billion parameters. It aims to open-source a 100B-scale model at least on par with GPT-3 (davinci).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Gemini&lt;/strong>: the Gemini team introduced a new family of multimodal models supporting a 32k context length. The Gemini family comes in three versions: Ultra for highly complex tasks, Pro for enhanced performance and deployability at scale, and Nano for on-device applications.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h1 id="how-to-build-an-llm">How to Build an LLM&lt;/h1>
&lt;h2 id="architecture-choices">Architecture Choices&lt;/h2>
&lt;p>As described above, the most widely used LLM architectures today are encoder-only, decoder-only, and encoder-decoder.&lt;/p>
&lt;p>Here we first revisit the Transformer architecture. It was originally proposed in &lt;em>Attention Is All You Need&lt;/em> and designed from the outset to exploit GPUs for efficient parallel computation. At its core is the attention mechanism, which, compared with recurrence and convolution, (1) uses GPUs more effectively and (2) captures long-range contextual information. The attention function can be described as mapping a query and a set of key-value pairs to an output, where the query, keys, values, and output are all vectors. The output is a weighted sum of the values, where the weight assigned to each value is computed by a compatibility function of the query with the corresponding key.&lt;/p>
&lt;h3 id="encoder-only">&lt;em>Encoder-Only&lt;/em>&lt;/h3>
&lt;p>In an encoder-only architecture, the attention layer has access to all the words in the initial sentence at every stage. Pre-training for these models usually involves &lt;strong>corrupting a given sentence in some way (for example, masking) and asking the model to reconstruct it&lt;/strong>. &lt;strong>Encoder-only architectures are well suited to tasks that require understanding of the complete sequence, such as sentence classification, named entity recognition, and extractive question answering.&lt;/strong>&lt;/p>
&lt;h3 id="decoder-only">&lt;em>Decoder-Only&lt;/em>&lt;/h3>
&lt;p>In a decoder-only architecture, at every stage any given token attends only to the tokens preceding it. These models are sometimes called autoregressive models. Their pre-training is usually formulated as predicting the next token in the sequence (next token prediction). Decoder-only architectures suit tasks that involve text generation. The GPT models are the outstanding example of this model class.&lt;/p>
&lt;h3 id="encoder-decoder">&lt;em>Encoder-Decoder&lt;/em>&lt;/h3>
&lt;p>Encoder-decoder architectures use both an encoder and a decoder, and are sometimes called sequence-to-sequence models. At each stage, the encoder&amp;rsquo;s attention layer can access all the words in the initial sentence, whereas the decoder&amp;rsquo;s attention layer can only access the tokens preceding a given token in the input. Encoder-decoder models suit tasks that generate a new sentence from a given input, such as summarization, translation, or generative question answering.&lt;/p>
&lt;h2 id="data-cleaning">Data Cleaning&lt;/h2>
&lt;p>Data quality is critical to the performance of the language model trained on it. Data cleaning techniques such as filtering and deduplication have been shown to have a significant impact on model performance.&lt;/p>
&lt;h3 id="data-filtering">Data Filtering&lt;/h3>
&lt;p>Data filtering aims to improve the quality of the training data and thus the effectiveness of the trained LLM. Common data filtering techniques include:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Denoising&lt;/strong>: for example, removing false information.&lt;/li>
&lt;li>&lt;strong>Handling outliers&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Class imbalance&lt;/strong>: balancing the distribution of classes in the dataset.&lt;/li>
&lt;li>&lt;strong>Text preprocessing&lt;/strong>: removing stop words, punctuation, and the like.&lt;/li>
&lt;li>&lt;strong>Handling ambiguity&lt;/strong>: dealing with vague or contradictory data.&lt;/li>
&lt;/ol>
&lt;h3 id="deduplication">Deduplication&lt;/h3>
&lt;p>Deduplication means removing duplicate instances or repeated occurrences of the same data. Duplicate data points can introduce bias during model training and reduce diversity. Some studies show that deduplication improves the model&amp;rsquo;s ability to generalize to new, unseen data.&lt;/p>
&lt;h2 id="tokenization">Tokenization&lt;/h2>
&lt;p>Tokenization is the process of converting a text sequence into smaller pieces, namely tokens.&lt;/p>
&lt;h2 id="model-pre-training">Model Pre-training&lt;/h2>
&lt;p>Pre-training is the first step in the training pipeline of a large language model. During pre-training, an LLM is typically trained in a self-supervised manner on a large amount of (usually) unlabeled text. The two most common pre-training methods are next token prediction and masked language modeling (MLM).&lt;/p>
&lt;ul>
&lt;li>Next token prediction: predict the next token in a sentence token by token from left to right (or right to left), establishing dependencies between tokens. Suitable for text generation tasks such as machine translation and text generation.&lt;/li>
&lt;li>Masked language modeling: in MLM, the model learns the relationships between tokens by predicting randomly masked words in a sentence, which trains it to understand the contextual meaning of words. MLM is better suited to understanding tasks such as text classification and named entity recognition.&lt;/li>
&lt;/ul>
&lt;h2 id="fine-tuning-and-instruction-tuning">Fine-tuning and Instruction Tuning&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>Fine-tuning usually serves two purposes: (1) adapting the base model to different tasks, and (2) injecting new knowledge.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Beyond fine-tuning, we also want an LLM to understand and follow natural language instructions from humans. That is where instruction tuning comes in.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="alignment">Alignment&lt;/h2>
&lt;p>AI alignment is the process of steering an AI system toward human goals, preferences, and principles. Sometimes, in the course of token prediction, large language models exhibit dangerous behavior. For example, they may generate undesirable, harmful, misleading, or biased content.&lt;/p>
&lt;p>At this stage, two popular approaches are &lt;strong>RLHF&lt;/strong> (reinforcement learning from human feedback) and &lt;strong>RLAIF&lt;/strong> (reinforcement learning from AI feedback).&lt;/p>
&lt;ul>
&lt;li>&lt;strong>RLHF&lt;/strong>: RLHF uses a reward model to learn alignment from human feedback. The tuned reward model is able to evaluate different outputs and score the outputs of the model being trained according to the alignment preferences given by humans.&lt;/li>
&lt;li>&lt;strong>RLAIF&lt;/strong>: RLAIF, on the other hand, connects a pre-trained, well-aligned model directly to the LLM being trained and helps it learn from this larger, better-aligned model. This resembles a generalized form of knowledge distillation.&lt;/li>
&lt;/ul>
&lt;h2 id="decoding-strategies">Decoding Strategies&lt;/h2>
&lt;p>Decoding refers to the process of generating text with a pre-trained large language model. Given an input prompt, the tokenizer converts each token in the input text into its corresponding numerical representation. The language model then takes these numerical token representations as input and predicts the next most likely token. Finally, the model produces logits, which are turned into probabilities by a softmax function. A variety of decoding strategies have been proposed; among the most popular are greedy search, beam search, top-K, and top-P.&lt;/p>
&lt;h3 id="greedy-search">Greedy Search&lt;/h3>
&lt;p>Greedy search picks the most likely token as the next token in the sequence at each step, discarding all other potential options. As with many greedy algorithms, this approach may sacrifice the consistency and coherence of the text. It only considers the most likely token at each step, without regard for the quality of the generated sequence as a whole.&lt;/p>
&lt;h3 id="beam-search">Beam Search&lt;/h3>
&lt;p>Unlike greedy search, which only considers the single most likely next token, beam search considers the N most likely tokens, where N is the number of beams. The process repeats until a predefined maximum sequence length is reached or an end-of-sequence token appears. At that point, the token sequence (also called a beam) with the highest overall score is selected as the output. For example, with a beam size of 2 and a maximum length of 5, beam search must recursively generate and evaluate $2^5 = 32$ possible sequences. It therefore requires considerably more computation than greedy search.&lt;/p>
&lt;h3 id="top-k">Top-k&lt;/h3>
&lt;p>Top-k sampling uses the probability distribution produced by the language model to randomly select a token from among the k most likely options.&lt;/p>
&lt;p>Suppose we have six tokens (A, B, C, D, E, F) and set k=2, with P(A)=30%, P(B)=20%, and P(C)=P(D)=P(E)=P(F)=12.5%. Under top-k sampling, tokens C, D, E, and F are ignored, and the model outputs A with probability 60% and B with probability 40%. This approach ensures that we prioritize the most likely tokens while still introducing a degree of randomness.&lt;/p>
&lt;p>In this method, randomness is usually introduced through the notion of temperature. The temperature T is a parameter from 0 to 1 that affects the probabilities produced by the softmax function, as the following formula shows:
$$
softmax(x_i)=\frac{e^{x_i/T}}{\sum_je^{x_j/T}}
$$
As the formula indicates, a low temperature makes the probability distribution sharper, which means higher-probability tokens become even more prominent, so the generated text is more deterministic and less creative; a high temperature flattens the distribution, giving low-probability tokens more of a chance and thereby increasing the diversity and creativity of the text.&lt;/p>
&lt;h3 id="top-p">Top-p&lt;/h3>
&lt;p>Top-p sampling, also known as nucleus sampling, takes a slightly different approach from top-k sampling. Instead of selecting the top k most likely tokens, nucleus sampling chooses a threshold p such that the probabilities of the selected tokens sum to more than p. In other words, under top-p sampling the model examines the most likely tokens in descending order and adds them to a list one by one until their cumulative probability exceeds the threshold p.&lt;/p>
&lt;h1 id="using-llms">Using LLMs&lt;/h1>
&lt;h2 id="limitations-of-llms">Limitations of LLMs&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>No state or memory&lt;/strong>: on their own, they cannot even remember what was sent to them in a previous prompt.&lt;/li>
&lt;li>&lt;strong>Answers are random or probabilistic&lt;/strong>: send the same input to an LLM several times and you will very likely get different replies.&lt;/li>
&lt;li>&lt;strong>Outdated information&lt;/strong>&lt;/li>
&lt;li>&lt;strong>High training cost&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Hallucination&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>Here we discuss only hallucination.&lt;/p>
&lt;p>Hallucination in LLMs has been described as &amp;ldquo;generated content that is nonsensical or unfaithful to the provided source,&amp;rdquo; and it falls into two categories:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Intrinsic hallucinations&lt;/strong>: the hallucination directly conflicts with the source material, being factually inaccurate or logically inconsistent.&lt;/li>
&lt;li>&lt;strong>Extrinsic hallucinations&lt;/strong>: content that cannot be verified against the source, containing speculative or unverifiable elements.&lt;/li>
&lt;/ol>
&lt;p>The impact of hallucination depends heavily on the context and the task. In creative endeavors such as writing poetry, for instance, hallucination may be considered acceptable or even beneficial.&lt;/p>
&lt;p>Recent work on LLM hallucination, such as instruction tuning and reinforcement learning from human feedback (RLHF), attempts to steer LLMs toward more fact-grounded output, but their inherently probabilistic nature, and the limitations that come with it, remains.&lt;/p>
&lt;h2 id="prompt-engineering">Prompt Engineering&lt;/h2>
&lt;p>When working with an LLM, the prompt is the text input provided by the user to guide the model&amp;rsquo;s output. A prompt typically includes an instruction, a question, input data, and examples.&lt;/p>
&lt;p>Typical prompting methods include:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Chain of Thought (CoT)&lt;/strong>: the famous CoT, which asks the LLM to think step by step so that it produces a better output. It comes in two main forms:
&lt;ol>
&lt;li>&lt;strong>Zero-shot CoT&lt;/strong>: append &amp;ldquo;Let&amp;rsquo;s think step by step&amp;rdquo; after the question.&lt;/li>
&lt;li>&lt;strong>Manual CoT&lt;/strong>: requires humans to supply step-by-step reasoning examples as templates.&lt;/li>
&lt;li>Of the two, Manual CoT is the more effective, but constructing chains of thought by hand is difficult and error-prone. Auto CoT does not suffer from this problem; see &lt;a href="https://geyuyao.com/post/auto-cot/" target="_blank" rel="noopener">Auto CoT — Generating Chain-of-Thought Automatically via Clustering&lt;/a> for details.&lt;/li>
&lt;/ol>
&lt;/li>
&lt;li>&lt;strong>Tree of Thought (ToT)&lt;/strong>: building on the idea of CoT, ToT can be unfolded into multiple &amp;ldquo;trees of thought,&amp;rdquo; where each branch represents a different reasoning path, that is, a different CoT.&lt;/li>
&lt;li>&lt;strong>Self-Consistency&lt;/strong>: given a prompt, the LLM generates not one answer but several. These candidate answers are then evaluated to determine how consistent they are with one another. Finally, the answer that is most consistent across all of them is chosen as the final output.&lt;/li>
&lt;li>&lt;strong>Reflection&lt;/strong>: prompts the LLM to evaluate and possibly revise its output by reasoning about the correctness and coherence of its own answer.&lt;/li>
&lt;li>&lt;strong>Expert Prompting&lt;/strong>: prompts the LLM to take on the role of an expert and answer accordingly, providing high-quality, well-informed answers.&lt;/li>
&lt;/ol>
&lt;h2 id="rag">RAG&lt;/h2>
&lt;center> &lt;img style="border-radius: 0.2125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);width: 70%;" src="https://geyuyao.com/post/large-language-models-survey/1710686853330.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;p>As the figure above shows, RAG extracts the query from the prompt and uses it to retrieve relevant information from an external knowledge source (such as a search engine or a knowledge graph). The retrieved information is then added to the prompt and fed to the LLM, which produces the final answer.&lt;/p>
&lt;h2 id="llm-agents">LLM Agents&lt;/h2>
&lt;center> &lt;img style="border-radius: 0.2125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);width: 70%;" src="https://geyuyao.com/post/large-language-models-survey/1710686912432.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;p>The notion of AI agents has a long history. An AI agent is typically an autonomous entity that perceives its environment through sensors, makes judgments based on the current state, and acts.&lt;/p>
&lt;p>In the context of large models, an agent is a system built on an LLM that can carry out specific tasks autonomously. Such agents are designed to interact with users or their environment and to make decisions based on the input and the intended goal of the interaction. The core characteristics of an agent are:&lt;/p>
&lt;ol>
&lt;li>The ability to access and use tools.&lt;/li>
&lt;li>The ability to make decisions autonomously.&lt;/li>
&lt;/ol>
&lt;p>Representative work in this area includes ReAct and LATS; interested readers may consult my earlier post &lt;a href="https://geyuyao.com/post/react/" target="_blank" rel="noopener">ReAct — An LLM Reasoning Paradigm Combining Reasoning and Acting&lt;/a>.&lt;/p>
&lt;h1 id="datasets">Datasets&lt;/h1>
&lt;center> &lt;img style="border-radius: 0.2125em; box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);width: 100%;" src="https://geyuyao.com/post/large-language-models-survey/101.png"> &lt;br> &lt;div style="color:orange; border-bottom: 1px solid #d9d9d9; display: inline-block; color: #999; padding: 1px;">&lt;/div>&lt;/center>
&lt;h1 id="challenges">Challenges&lt;/h1>
&lt;h2 id="smaller-and-more-efficient-models">Smaller and More Efficient Models&lt;/h2>
&lt;p>A current research trend is to propose small language models (SLMs) as a more economical alternative to LLMs, particularly for tasks that do not require such large models.&lt;/p>
&lt;h2 id="new-architectural-paradigms-beyond-attention">New Architectural Paradigms Beyond Attention&lt;/h2>
&lt;p>One important class of models proposed after the attention-based models is state space models (SSMs). Although the concept of state space models has a long history in machine learning, in the context of language models SSM usually refers to the more recent structured state space model architecture, S4 for short. Some recent models in this category include Mamba, Hyena, and Striped Hyena.&lt;/p>
&lt;p>On another front, several attention-compatible architectural mechanisms have been gaining ground recently, such as mixture of experts (MoE). Notably, MoEs can serve as a component of any architecture, whether or not it is attention-based.&lt;/p>
&lt;h2 id="multimodality">Multimodality&lt;/h2>
&lt;p>Several well-known multimodal LLMs already exist, including LLaVA (a vision-language model), LLaVA-Plus (an extension of LLaVA), GPT-4, Qwen-VL, and Next-GPT.&lt;/p>
&lt;h2 id="techniques-for-using-and-augmenting-llms">Techniques for Using and Augmenting LLMs&lt;/h2>
&lt;p>Prompting and RAG, for example.&lt;/p>
&lt;h2 id="llm-safety">LLM Safety&lt;/h2>
&lt;p>Privacy and bias, for example.&lt;/p></description></item><item><title>Paper Review | Auto-CoT — Generating Chain-of-Thought via Clustering</title><link>https://geyuyao.com/post/auto-cot-en/</link><pubDate>Sat, 02 Mar 2024 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/auto-cot-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/auto-cot/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> Automatic Chain of Thought Prompting in Large Language Models&lt;/p>
&lt;p>&lt;strong>Institute:&lt;/strong> Shanghai Jiao Tong University, Amazon Web Services&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Zhuosheng Zhang, Aston Zhang, Mu Li, Alex Smola&lt;/p>
&lt;p>&lt;strong>Arxiv Link:&lt;/strong> &lt;a href="https://arxiv.org/abs/2210.03493" target="_blank" rel="noopener">https://arxiv.org/abs/2210.03493&lt;/a>&lt;/p>
&lt;p>&lt;strong>Date:&lt;/strong> 2022.10.7&lt;/p>
&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;p>Before this work, chain-of-thought prompting existed in two paradigms. The first is Zero-shot CoT, which simply appends &amp;ldquo;Let&amp;rsquo;s think step by step&amp;rdquo; to the end of the question. The second is Manual CoT (Few-shot CoT), where each exemplar consists of a question paired with a reasoning chain. How well the second approach works depends entirely on how good the hand-written chains are — and writing them takes human effort. The authors propose Auto-CoT, which generates few-shot CoT exemplars automatically and spares us that manual labor.&lt;/p>
&lt;h1 id="motivation">Motivation&lt;/h1>
&lt;p>Manual CoT (Few-shot CoT) outperforms Zero-shot CoT but consumes far more human effort, so the authors set out to design Auto-CoT.&lt;/p>
&lt;h1 id="findings">Findings&lt;/h1>
&lt;p>Unlike papers that present their method up front, this one first runs a series of exploratory experiments and only then arrives at its proposal.&lt;/p>
&lt;p>The authors begin by comparing Retrieval-Q-CoT against Random-Q-CoT on three datasets: MultiArith, GSM8K, and AQuA. On MultiArith, Retrieval-Q-CoT turns out to be &lt;em>worse&lt;/em> than Random-Q-CoT, which is clearly counterintuitive. Suspecting that the culprit was the poor quality of the Zero-shot-generated chains, they repeated the experiment on GSM8K and AQuA, two datasets whose CoT annotations are human-written. As expected, Retrieval-Q-CoT outperformed Random-Q-CoT on both. The conclusion: chains produced by Zero-shot are simply not as good as human-written ones.&lt;/p>
&lt;blockquote>
&lt;p>Retrieval-Q-CoT: encode the question with Sentence-BERT, then take the top-k most similar questions as demonstrations, $q_i^{demo}(i=1,..,k)$. For these k questions, generate chains with Zero-shot — $c_i^{demo}$ — then concatenate $q_i^{demo},c_i^\text{demo}(i=1,&amp;hellip;,k),q^{test}$ as the input to the LLM.&lt;/p>
&lt;p>Random-Q-CoT: same as Retrieval-Q-CoT, except the k questions are chosen at random.&lt;/p>
&lt;/blockquote>
&lt;p>To further verify that flawed chains are what degrade reasoning, the authors deliberately injected incorrect chains into 128 out of 600 examples. Retrieval-Q-CoT was indeed misled, confirming how much correct chains matter in CoT prompting.&lt;/p>
&lt;p>Going further, the authors clustered all questions into k groups by similarity with k-means, then generated chains with Zero-shot and ran inference. To find out whether certain clusters concentrate the questions on which Zero-Shot-CoT tends to fail, they computed the error rate of each cluster.&lt;/p>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/auto-cot/1709469511695.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;p>As the figure shows, cluster 2 has a strikingly high error rate, which indicates that Zero-shot cannot produce good chains for a certain class of questions — likely the reason Retrieval-Q-CoT underperforms.&lt;/p>
&lt;h1 id="auto-cot">Auto-CoT&lt;/h1>
&lt;p>Building on these findings, the authors propose Auto-CoT, which consists of two main stages:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Clustering&lt;/strong>: partition the questions of a given dataset into several clusters.&lt;/li>
&lt;li>&lt;strong>Sampling&lt;/strong>: select one representative question from each cluster and generate its reasoning chain with Zero-Shot-CoT under a simple heuristic.&lt;/li>
&lt;/ol>
&lt;p>The overall pipeline is shown below:&lt;/p>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/auto-cot/1709469718524.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;p>In more detail:&lt;/p>
&lt;ol>
&lt;li>In the clustering stage, all questions are embedded with Sentence-BERT and partitioned into k classes by k-means. Within each cluster, questions are sorted by their distance to the cluster center, producing an ascending list $\mathbf{q}^{(i)}=[q_1^{(i)},q_2^{(i)},\ldots]$.&lt;/li>
&lt;li>In the sampling stage, each cluster is traversed in that ascending order. A chain is generated for the current question with Zero-shot; if the chain runs to no more than 60 tokens and five steps, that question and its chain become the exemplar for every question in the cluster and are prepended to them at inference time.&lt;/li>
&lt;/ol>
&lt;h1 id="experiments">Experiments&lt;/h1>
&lt;p>The experiments cover three categories of reasoning tasks across ten benchmark datasets, all with GPT-3:&lt;/p>
&lt;ol>
&lt;li>Arithmetic reasoning (MultiArith, GSM8K, AddSub, AQUA-RAT, SingleEq, SVAMP)&lt;/li>
&lt;li>Commonsense reasoning (CSQA, StrategyQA)&lt;/li>
&lt;li>Symbolic reasoning (Last Letter Concatenation, Coin Flip)&lt;/li>
&lt;/ol>
&lt;p>The baselines are Zero-Shot, Zero-Shot-CoT, Few-Shot, and Manual-CoT.&lt;/p>
&lt;p>As the table below shows, Auto-CoT consistently matches or exceeds the performance of CoT methods that require manually designed demonstrations.&lt;/p>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/auto-cot/1709470146077.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;h1 id="conclusion">Conclusion&lt;/h1>
&lt;p>Viewed from 2024, the method in this paper looks fairly simple next to work such as ReAct. It is worth remembering, however, that it appeared quite early, when everyone was still feeling their way forward — which makes a method like this all the more valuable. In fact, traces of Auto-CoT are still visible in the latest approaches.&lt;/p></description></item><item><title>Paper Review | Does a Longer Chain of Thought Make an LLM Smarter?</title><link>https://geyuyao.com/post/reasoning-step-length-en/</link><pubDate>Mon, 26 Feb 2024 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/reasoning-step-length-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/reasoning-step-length/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> The Impact of Reasoning Step Length on Large Language Models&lt;/p>
&lt;p>&lt;strong>Institute:&lt;/strong> Northwestern University, University of Liverpool, New Jersey Institute of Technology, Rutgers University&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Mingyu Jin, Qinkai Yu, Dong Shu, Haiyan Zhao, Wenyue Hua, Yanda Meng, Yongfeng Zhang, Mengnan Du&lt;/p>
&lt;p>&lt;strong>Arxiv Link:&lt;/strong> &lt;a href="https://arxiv.org/abs/2401.04925" target="_blank" rel="noopener">https://arxiv.org/abs/2401.04925&lt;/a>&lt;/p>
&lt;p>&lt;strong>Date:&lt;/strong> 2024.1.20&lt;/p>
&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;p>Chain of thought (CoT) has already proven, in practice, to substantially improve the reasoning ability of large language models. Yet no work so far has explained the relationship between the length of a chain of thought and reasoning ability. This paper takes that question as its core, runs a systematic set of experiments on CoT, and arrives at a number of interesting and counterintuitive conclusions.&lt;/p>
&lt;h1 id="conclusions">Conclusions&lt;/h1>
&lt;p>Let us skip the preamble and go straight to the conclusions.&lt;/p>
&lt;ol>
&lt;li>For Few-shot CoT, the accuracy of the model&amp;rsquo;s answers is linearly related to the number of reasoning steps: the longer the chain, the more accurate the answer. Conversely, shortening the CoT significantly reduces accuracy, even when the shortened chain preserves the same key information as the long one.&lt;/li>
&lt;li>Even when a CoT chain contains incorrect reasoning, keeping the necessary reasoning length still yields good results. In other words, a longer chain improves accuracy even if an intermediate step is wrong.&lt;/li>
&lt;li>Simple tasks need fewer steps; complex tasks need more.&lt;/li>
&lt;li>Even in the Zero-shot CoT setting, adding &amp;ldquo;you must think more steps&amp;rdquo; on top of &amp;ldquo;Let&amp;rsquo;s think step by step&amp;rdquo; improves the model&amp;rsquo;s performance.&lt;/li>
&lt;/ol>
&lt;h1 id="experimental-setup">Experimental Setup&lt;/h1>
&lt;h2 id="zero-shot-cot">Zero-shot CoT&lt;/h2>
&lt;p>The Zero-shot CoT setting in this paper defaults to &amp;ldquo;Let&amp;rsquo;s think step by step&amp;rdquo;. The authors then compare it against &amp;ldquo;Let&amp;rsquo;s think step by step, you must think more steps&amp;rdquo; to see how the extra instruction affects the LLM.&lt;/p>
&lt;h2 id="few-shot-cot">Few-shot CoT&lt;/h2>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/reasoning-step-length/1709036168663.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;p>As shown above, the Few-shot CoT in this paper is organized into the following steps:&lt;/p>
&lt;ol>
&lt;li>Think About The Word: the authors first ask the LLM to think about the meaning of the words in the question (work out what each word means before answering). For example, given the question &amp;ldquo;Could someone in Tokyo take a taxi to the Metropolitan Museum of Art?&amp;rdquo;, as illustrated below, the authors have the LLM first consider what &amp;ldquo;Tokyo&amp;rdquo;, &amp;ldquo;taking a taxi&amp;rdquo;, and &amp;ldquo;Metropolitan Museum of Art&amp;rdquo; mean — &amp;ldquo;Think about Tokyo&amp;hellip; Think about taking a taxi&amp;hellip; Think about Metropolitan Museum of Art&amp;hellip;&amp;rdquo;.&lt;/li>
&lt;/ol>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/reasoning-step-length/1709038629109.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;ol start="2">
&lt;li>
&lt;p>Read the question again: have the LLM read the question once more (review the problem statement again).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Repeat State: have the LLM produce a summary of the question, simplifying what it needs to remember and reducing the influence of the other words in the CoT (extract the key information from the question).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Self-Verification: add a self-verification step in which the model judges, from some basic information, whether the answer is reasonable (think for yourself about whether your answer is right).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Make Equation: for mathematical problems, have the LLM formalize the problem as an equation.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h1 id="experiments-and-findings">Experiments and Findings&lt;/h1>
&lt;h2 id="the-relationship-between-step-count-and-accuracy">The relationship between step count and accuracy&lt;/h2>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/reasoning-step-length/1709038719656.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;p>As shown above, in each subplot the x-axis is the length of the CoT chain (the number of reasoning steps) and the y-axis is the LLM&amp;rsquo;s accuracy. Clearly, &lt;strong>the longer the CoT chain, the higher the accuracy&lt;/strong>. This finding holds across all datasets and tasks.&lt;/p>
&lt;h2 id="what-happens-when-one-link-in-the-cot-is-wrong">What happens when one link in the CoT is wrong?&lt;/h2>
&lt;p>For CoT researchers, the most important question is how to get every step of the chain right so as to arrive at the correct answer. In this section, the authors ask: if one link in the CoT is reasoned incorrectly, how does that affect the LLM&amp;rsquo;s final result?&lt;/p>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/reasoning-step-length/1709038869996.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;p>In the figure below, the x-axis denotes eight categories of tasks/datasets, and the two colored bars represent fully correct chains and chains containing an incorrect answer. The authors find that:&lt;/p>
&lt;ol>
&lt;li>For mathematical problems, an error in one link has very little impact. The authors argue that the LLM learns the computational pattern rather than the result of the computation itself, and is therefore unaffected. An example is shown in the figure below, where the faulty prompt on the right computes &lt;code>10+8&lt;/code> as the incorrect value &lt;code>48&lt;/code>.&lt;/li>
&lt;li>For logical problems, even a small error breaks the chain of thought and has a large impact.&lt;/li>
&lt;/ol>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/reasoning-step-length/1709039099537.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;h2 id="what-happens-when-the-reasoning-steps-are-compressed">What happens when the reasoning steps are compressed?&lt;/h2>
&lt;p>Compressing the reasoning steps here means phrasing each step more briefly. The results show that compression drives performance close to that of Zero-shot, further demonstrating the strong link between reasoning steps and LLM accuracy.&lt;/p>
&lt;h2 id="the-effect-of-model-size-on-the-results">The effect of model size on the results&lt;/h2>
&lt;p>As the figure below makes obvious, the more parameters, the more accurate the model.&lt;/p>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/reasoning-step-length/1709039362935.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;h2 id="do-different-cot-generation-methods-differ-much">Do different CoT generation methods differ much?&lt;/h2>
&lt;p>Since this paper focuses on the impact of reasoning steps, it first has to confirm that the questions used inside the CoT are not what drives the LLM&amp;rsquo;s performance.&lt;/p>
&lt;p>To that end, with the LLM fixed to GPT-3.5-turbo-1106, the authors selected two datasets (MultiArith and GSM8K) and two CoT methods (Auto CoT and Few-shot CoT) for this study.&lt;/p>
&lt;p>As shown below, an initial inspection indicates that these modifications have a negligible effect on performance. This preliminary finding suggests that it is the length of the reasoning chain, rather than the nature of the questions themselves, that primarily governs the reasoning ability of LLMs.&lt;/p>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/reasoning-step-length/1709039615751.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">&lt;/div>
&lt;/center>
&lt;h1 id="comments">Comments&lt;/h1>
&lt;p>Although this paper is not technically difficult, its evaluation of CoT is thorough, its angle is novel, and it arrives at a good number of interesting conclusions.&lt;/p></description></item><item><title>Paper Review | Emergent Abilities of LLMs Are a Mirage</title><link>https://geyuyao.com/post/emergent-abilities-mirage-en/</link><pubDate>Sat, 16 Dec 2023 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/emergent-abilities-mirage-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/emergent-abilities-mirage/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> Are Emergent Abilities of Large Language Models a Mirage?&lt;/p>
&lt;p>&lt;strong>Institution:&lt;/strong> Computer Science, Stanford University&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Rylan Schaeffer, Brando Miranda, Sanmi Koyejo&lt;/p>
&lt;p>&lt;strong>Arxiv Link:&lt;/strong> &lt;a href="https://arxiv.org/abs/2304.15004" target="_blank" rel="noopener">https://arxiv.org/abs/2304.15004&lt;/a>&lt;/p>
&lt;p>&lt;strong>Comments:&lt;/strong> NeurIPS 2023&lt;/p>
&lt;p>&lt;strong>Date:&lt;/strong> 2023.04.28&lt;/p>
&lt;h1 id="preface">Preface&lt;/h1>
&lt;p>This paper was posted on arXiv on April 28, 2023. Two versions later, it won a Best Paper award in the main track at NeurIPS 2023 (2 out of 3584).&lt;/p>
&lt;h1 id="emergent-abilities">Emergent Abilities&lt;/h1>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/emergent-abilities-mirage/0.jpg">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">Figure 1&lt;/div>
&lt;/center>
&lt;p>The paper notes that a great deal of work claims LLMs display abilities that are absent at smaller scales but present at larger ones — what people commonly call emergent abilities, or emergence.&lt;/p>
&lt;blockquote>
&lt;p>An &amp;ldquo;emergent ability&amp;rdquo; is a capability or behavior that a model displays only once it becomes large enough, one that smaller models did not have — a metric that suddenly shoots up, for instance.&lt;/p>
&lt;/blockquote>
&lt;p>As the figure above shows, for model families such as LaMDA and GPT-3, accuracy jumps abruptly once the parameter count crosses a certain critical point. That is emergence.&lt;/p>
&lt;p>Emergent abilities have two defining features:&lt;/p>
&lt;ul>
&lt;li>Sharpness: an abrupt rise as the parameter count increases linearly&lt;/li>
&lt;li>Unpredictability: they appear suddenly at some uncertain critical parameter count&lt;/li>
&lt;/ul>
&lt;h1 id="does-emergence-really-exist">Does Emergence Really Exist?&lt;/h1>
&lt;p>To give away the conclusion: this paper shows that LLMs exhibit no genuine &amp;ldquo;emergence&amp;rdquo;; their capabilities grow smoothly as parameters increase.&lt;/p>
&lt;p>Emergence is not a product of growth in a model&amp;rsquo;s parameter count. It is an illusion created by the metric the researcher happened to choose.&lt;/p>
&lt;p>The authors&amp;rsquo; starting point is that the metrics previously used to measure model capability are discrete rather than linear, and that this is what produces apparent emergence. So what happens if we swap in a linear or continuous metric instead — does a model&amp;rsquo;s capability turn out to be smooth, continuous, and predictable?&lt;/p>
&lt;h1 id="explaining-emergent-abilities">Explaining Emergent Abilities&lt;/h1>
&lt;center>
&lt;img style="border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);"
src="https://geyuyao.com/post/emergent-abilities-mirage/1.png">
&lt;br>
&lt;div style="color:orange; border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 1px;">Figure 2&lt;/div>
&lt;/center >
&lt;p>The authors open with a question of their own: how can a smooth, continuous, predictable change in model performance be made to look abrupt and unpredictable? Their answer is that a researcher&amp;rsquo;s choice of a nonlinear or discontinuous metric can distort how the model&amp;rsquo;s performance appears, making it seem to change abruptly and unpredictably.&lt;/p>
&lt;p>Experience tells us that a neural network&amp;rsquo;s capability scales in a fixed proportion with the amount of training data, the parameter count, and the compute expended. Taking that as given, assume the following holds &lt;strong>(Figure 2.A)&lt;/strong>:
$$
\mathcal{L}_{CE}(N)=\left(\frac Nc\right)^\alpha
$$
where $L_CE$ denotes cross entropy, $N$ denotes the parameter count, and $c&amp;gt;0$ and $\alpha&amp;lt;0$ are constants.
In practice, cross entropy is defined as:
$$
\mathcal{L}_{CE}(N)\overset{\mathrm{def}}{\operatorname*{=}}-\sum_{v\in V}p(v)\log\hat{p}_N(v)
$$
This formula measures the discrepancy between the model&amp;rsquo;s predicted distribution
$\hat{p}_N$ over the whole vocabulary
$V$ and the true distribution
$p$. For each possible token $v$, the true distribution $p(v)$ gives the true probability that token $v$ occurs, while $\hat{p}_N(v)$ is the probability the model assigns to token $v$.&lt;/p>
&lt;p>Since
$p(v) = 0$ for all
$v \neq v^*$ and
$p(v^*) = 1$, only the term with
$v = v^*$ survives the sum, and the formula simplifies to:&lt;/p>
&lt;p>$$
\mathcal{L}_{CE}(N)=-\log\hat{p}_N(v^*)
$$&lt;/p>
&lt;p>The probability that each token is predicted correctly is &lt;strong>(Figure 2.B)&lt;/strong>:
$$
\begin{align*}
p(\text{single token correct})&amp; =\exp\left(-\mathcal{L}_{CE}(N)\right)\\ &amp; =\exp\left(-(N/c)^\alpha\right)
\end{align*}
$$
Now suppose the researcher chooses a metric that requires $L$ tokens to all be correct. The task might be, for example, $L$-digit integer addition, scoring $1$ if all $L$ output digits match the target digits exactly, with no insertions, deletions, or substitutions, and $0$ otherwise. If each token&amp;rsquo;s correctness is independent, the probability of scoring $1$ is:
$$
\begin{align*}
\operatorname{Accuracy}(N) &amp;\approx p_N\left(\text{single token correct}\right)^\text{num. of tokens} \\
&amp;= \exp\left(-(N/c)^\alpha\right)^L
\end{align*}
$$
&lt;/p>
&lt;blockquote>
$$\text{Exact String Match}\stackrel{\text{def}}{=}\begin{cases}1&amp;\text{if output string exactly matches target string}\\0&amp;\text{otherwise}\end{cases}$$
&lt;/blockquote>
&lt;p>This choice of metric makes performance scale nonlinearly with the length of the token sequence. Plotting performance on a linear-log axis &lt;strong>(Figure 2.C)&lt;/strong> reveals abrupt, unpredictable jumps on longer sequences — a very close match to the emergent abilities other researchers have claimed.&lt;/p>
&lt;p>And what happens if we use a linear metric such as Token Edit Distance?
$$
\begin{aligned}
\text{Token Edit Distance}(N) &amp;\approx L(1-p_N(\text{single token correct})) \\
&amp;= L\left(1-\exp\left(-(N/c)^\alpha\right)\right)
\end{aligned}
$$
When model capability is measured with the linear metric Token Edit Distance, it becomes smooth, continuous, and predictable &lt;strong>(Figure 2.E)&lt;/strong>.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;Token Edit Distance&amp;rdquo; is a way of measuring the difference between two sequences. It counts the minimum number of edit operations — insertions, deletions, and substitutions of a single token — needed to turn one sequence into the other. In this context, a &amp;ldquo;token&amp;rdquo; usually means a word, a character, or another linguistic unit.&lt;/p>
&lt;p>For example, if we have two sequences, sequence A being &amp;ldquo;cat&amp;rdquo; and sequence B being &amp;ldquo;bat&amp;rdquo;, the token edit distance from A to B is 1, since we need only substitute &amp;ldquo;b&amp;rdquo; for &amp;ldquo;c&amp;rdquo;.&lt;/p>
&lt;/blockquote>
&lt;p>If the discrete metric Multiple Choice Grade is used, emergence is observed &lt;strong>(Figure 2.D)&lt;/strong>, but if the continuous metric Brier Score is used, emergence disappears &lt;strong>(Figure 2.F)&lt;/strong>.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>Multiple Choice Grade:&lt;/strong>&lt;/p>
$$\\ \text{Multiple Choice Grade}\stackrel{\text{def}}{=}\begin{cases}1&amp;\text{if highest probability mass on correct option}\\0&amp;\text{otherwise}\end{cases}$$
&lt;p>&lt;strong>Brier Score:&lt;/strong>
$$ BS = \frac{1}{N} \sum_{i=1}^{N} (f_i - o_i)^2$$
where:&lt;/p>
&lt;ul>
&lt;li>$N$ is the number of predictions.&lt;/li>
&lt;li>$f_i$ is the predicted probability of occurrence for the $i$-th prediction (the probability output by the model).&lt;/li>
&lt;li>$o_i$ is the observed value of the actual outcome for the $i$-th case (usually 1 if the event occurred and 0 if it did not).&lt;/li>
&lt;/ul>
&lt;p>As an example, suppose you are predicting whether football matches will end in a draw. For three matches, your model predicts draw probabilities of 0.3, 0.6, and 0.2. The actual outcomes are that the first match was a draw (1) while the second and third were not (0).&lt;/p>
&lt;p>The Brier Score is then computed as follows:&lt;/p>
&lt;ul>
&lt;li>For the first match, the prediction error is $ (0.3 - 1)^2 = 0.49 $.&lt;/li>
&lt;li>For the second match, the prediction error is $ (0.6 - 0)^2 = 0.36 $.&lt;/li>
&lt;li>For the third match, the prediction error is $ (0.2 - 0)^2 = 0.04 $.
The Brier Score is the average of these errors, so in this example it is $ \frac{0.49 + 0.36 + 0.04}{3} = 0.2967 $.&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;p>In summary, the illusion of emergence has two causes.&lt;/p>
&lt;ol>
&lt;li>The metrics adopted by earlier work are discrete rather than continuous or linear, and that is what gives rise to the appearance of emergence.&lt;/li>
&lt;li>Earlier work experimented only over a narrow range of parameter counts. Model sizes are typically 6B, 7B, 13B, 33B, 70B and so on, which cover only a handful of points in the range. Had sizes such as 6B, 6.1B, 6.2B, 6.3B &amp;hellip; 70.1B, 70.2B been available, people would have seen that discrete metrics relate to parameter count exponentially rather than by a sudden jump.&lt;/li>
&lt;/ol>
&lt;hr>
&lt;p>This work fully deserves its Best Paper award at NeurIPS 2023. Its starting point is simple, yet its insights are far-reaching, creative, and genuinely illuminating. Before it appeared, emergence had become a widely accepted &amp;ldquo;magical phenomenon&amp;rdquo; in the field, and a good deal of research had been devoted to it, probing experiments included. Against that backdrop, the paper works from the details up to show that &amp;ldquo;emergence&amp;rdquo; does not actually exist — an eye-opening result for many researchers, this author among them.&lt;/p></description></item><item><title>Paper Review | Multimodal Representations of Graph Structure for LLMs</title><link>https://geyuyao.com/post/which-modality-text-motif-image-en/</link><pubDate>Tue, 21 Nov 2023 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/which-modality-text-motif-image-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/which-modality-text-motif-image/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> Which Modality should I use &amp;ndash; Text, Motif, or Image? : Understanding Graphs with Large Language Models&lt;/p>
&lt;p>&lt;strong>Institution:&lt;/strong> Minnesota NLP, University of Minnesota&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Debarati Das, Ishaan Gupta, Jaideep Srivastava, Dongyeop Kang&lt;/p>
&lt;p>&lt;strong>Arxiv Link:&lt;/strong> &lt;a href="https://arxiv.org/abs/2311.09862" target="_blank" rel="noopener">https://arxiv.org/abs/2311.09862&lt;/a>&lt;/p>
&lt;p>&lt;strong>Code Link:&lt;/strong> None&lt;/p>
&lt;p>&lt;strong>Date:&lt;/strong> 2023.11.16&lt;/p>
&lt;p>&lt;strong>Abstract:&lt;/strong> Large language models (LLMs) are revolutionizing various fields by leveraging large text corpora for context-aware intelligence. Due to the context size, however, encoding an entire graph with LLMs is fundamentally limited. This paper explores &lt;strong>how to better integrate graph data with LLMs and presents a novel approach using various encoding modalities (e.g., text, image, and motif) and approximation of global connectivity of a graph using different prompting methods to enhance LLMs&amp;rsquo; effectiveness in handling complex graph structures.&lt;/strong> The study also introduces GraphTMI, a new benchmark for evaluating LLMs in graph structure analysis, focusing on factors such as homophily, motif presence, and graph difficulty. Key findings reveal that image modality, supported by advanced vision-language models like GPT-4V, is more effective than text in managing token limits while retaining critical information. The research also examines the influence of different factors on each encoding modality&amp;rsquo;s performance. This study highlights the current limitations and charts future directions for LLMs in graph understanding and reasoning tasks.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/0.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;h1 id="introduction">&lt;strong>Introduction:&lt;/strong>&lt;/h1>
&lt;p>This paper explores the impact of encoding global and local graph structure in &lt;strong>different modalities&lt;/strong>, with a particular focus on &lt;strong>node classification&lt;/strong>.&lt;/p>
&lt;p>Specifically, it compares three modalities: &lt;strong>text&lt;/strong>, &lt;strong>motif&lt;/strong>, and &lt;strong>image&lt;/strong>.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/1.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>Why the paper introduces the motif modality:&lt;/p>
&lt;blockquote>
&lt;p>However, it becomes &lt;strong>too verbose&lt;/strong> for large graphs, potentially &lt;strong>exceeding the input context limits&lt;/strong> of large language models like GPT-4. To circumvent this, &lt;strong>we suggest Motif modality encoding, which captures essential patterns within the node&amp;rsquo;s vicinity, offering a balanced local and global perspective.&lt;/strong>&lt;/p>
&lt;/blockquote>
&lt;h1 id="methodology">Methodology&lt;/h1>
&lt;h2 id="text-encoder-modality">Text Encoder Modality&lt;/h2>
&lt;p>Encoding graphs as text can be separated into two key parts:&lt;/p>
&lt;ol>
&lt;li>the mapping of nodes to their corresponding labels in the graph
&lt;ul>
&lt;li>{node ID: node label}&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>the encoding of edges between the nodes&lt;/li>
&lt;/ol>
&lt;p>We consider several factors that can influence the performance of text-modality encoding:&lt;/p>
&lt;ul>
&lt;li>Edge Encoding Function&lt;/li>
&lt;li>Graph Structure&lt;/li>
&lt;li>Sampling Strategy&lt;/li>
&lt;/ul>
&lt;h3 id="edge-encoding-function">Edge Encoding Function&lt;/h3>
&lt;ul>
&lt;li>Edgelist&lt;/li>
&lt;li>Edgetext&lt;/li>
&lt;li>Adjacency List&lt;/li>
&lt;li>GML&lt;/li>
&lt;li>GraphML&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Edgelist:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">Node to Label Mapping : Node 69025: Label 34| Node 17585: Label 10|...
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Edge list: [(69025, 96211), (69025, 17585), (17585, 104598), (17585, 18844), (17585, 96211), (96211, 34515)]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Edgetext:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">Node to Label Mapping : Node 85328: Label 16| Node 158122: Label ?|...
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Edge connections (source node - target node): Node 85328 is connected to Node 158122. Node 158122 is connected to Node 167226.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Adjacency List:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">Node to Label Mapping : Node 2339: Label 3| Node 2340: Label ?|...
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Adjacency list: 1558: [2339, 2340], 2339: [1558, 2340], 2340: [2339,1558]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>GML:&lt;/strong>&lt;/p>
&lt;p>A GML file consists of an unordered sequence of node and edge elements enclosed within [].&lt;/p>
&lt;p>The node label information is embedded in the structure, &lt;strong>so no separate node-label mapping is needed&lt;/strong>.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">GraphML:graph [
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> node [
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> id 2339
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> label 3
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> node [
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> id 2340
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> label ?
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> node [
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> id 1558
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> label 3
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> edge [
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> source 2339
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> target 1558
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> edge [
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> source 2339
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> target 2340
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>GraphML:&lt;/strong>&lt;/p>
&lt;p>A GraphML file consists of an XML file containing a graph element, within which is an unordered sequence of node and edge elements.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">GraphML:&amp;lt;graphml xmlns=http://graphml.graphdrawing.org/xmlns
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">xsi:schemaLocation=http://graphml.graphdrawing.org/xmlns
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &amp;lt;graph edgedefault=undirected&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &amp;lt;node id=2339 label=3 /&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &amp;lt;node id=2340 label=? /&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &amp;lt;node id=1558 label=3 /&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &amp;lt;edge source=2339 target=1558 /&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &amp;lt;edge source=2339 target=2340 /&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &amp;lt;/graph&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&amp;lt;/graphml&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="graph-structure">Graph Structure&lt;/h3>
&lt;p>We selected real-world citation datasets with differing network properties to explore the significance of graph structure on node classification.&lt;/p>
&lt;ul>
&lt;li>CORA&lt;/li>
&lt;li>Citeseer&lt;/li>
&lt;li>Pubmed&lt;/li>
&lt;/ul>
&lt;h3 id="sampling-strategy">Sampling Strategy&lt;/h3>
&lt;ul>
&lt;li>Ego graph&lt;/li>
&lt;li>Forest Fire sampling&lt;/li>
&lt;/ul>
&lt;h3 id="example">Example&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">Task: Node Label Prediction (Predict the label of the node marked with a ?) given the adjacency list information as a dictionary of type &amp;#34;node: neighborhood&amp;#34; and node-label mapping in the text enclosed in triple backticks. Response should be in the format &amp;#34;Label of Node = &amp;lt;predicted label&amp;gt;&amp;#34;.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">If the predicted label cannot be determined, return &amp;#34;Label of Node = -1&amp;#34;.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">```AdjList: {1: [2,3], 2: [3,4], 3: [1,2]}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Node-Label Mapping: {1: A, 2: B, 3: ?} ```
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="motif-modality">Motif Modality&lt;/h2>
&lt;p>Encoding graphs as motifs can be separated into two key parts:&lt;/p>
&lt;ol>
&lt;li>the encoding of nodes to their corresponding labels in the graph&lt;/li>
&lt;li>the motifs present around the ? (unlabeled) node.&lt;/li>
&lt;/ol>
&lt;h3 id="motif-information">Motif information&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Type of Motif&lt;/th>
&lt;th>Motif Encoding&lt;/th>
&lt;th>Description of Motif&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Node-Label Mapping&lt;/strong>&lt;/td>
&lt;td>Node to Label Mapping : Node 1889: Label 4 | &amp;hellip; Node 1893: Label 2|&amp;hellip;&lt;/td>
&lt;td>Only the node-label mapping is provided (&lt;strong>this gives no connectivity information to LLM&lt;/strong>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>No. of Star Motifs&lt;/strong>&lt;/td>
&lt;td>Node to Label Mapping : Node 1889: Label 4 | &amp;hellip; Node 1893: Label 2|&amp;hellip; Graph motif information: Number of star motifs: 0|&lt;/td>
&lt;td>Star motifs signify centralized networks with influential central nodes, where a central node is connected to others that aren&amp;rsquo;t interlinked. We pass the count of the star motifs present in the graph.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>No. of Triangle Motifs&lt;/strong>&lt;/td>
&lt;td>Node to Label Mapping : Node 1889: Label 4 | &amp;hellip; Node 1893: Label 2|&amp;hellip; Graph motif information: Number of triangle motifs: 6|&lt;/td>
&lt;td>Triangle motifs (triads connecting three nodes) are foundational in social networks, indicating transitive relationships, community structures, and strong social ties. We pass the count of the triads present in the graph.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>No. of Triangle Motifs Attached&lt;/strong>&lt;/td>
&lt;td>Node to Label Mapping : Node 1889: Label 4 | &amp;hellip; Node 1893: Label 2|&amp;hellip; Graph motif information: Triangle motifs attached to ? node: |1893,2034,1531|, |1893,1531,429|&lt;/td>
&lt;td>We pass the triangle motifs attached to the ? label, which gives an idea of the influential triads connected to the ? node.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>No. of Star Motifs Attached&lt;/strong>&lt;/td>
&lt;td>Node to Label Mapping : Node 1889: Label 4 | &amp;hellip; Node 1893: Label 2|&amp;hellip; Graph motif information: Star motifs connected to ? node: | |&lt;/td>
&lt;td>We pass the star motifs attached to the ? label, which gives an idea of the influential nodes connected to the ? node.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>No. of Star and Triangle Motifs&lt;/strong>&lt;/td>
&lt;td>Node to Label Mapping : Node 1889: Label 4 | &amp;hellip; Node 1893: Label 2|&amp;hellip; Graph motif information: Number of star motifs: 0| Number of triangle motifs: 6|&lt;/td>
&lt;td>We pass the count of the triads and star motifs present in the graph, to give the LLM an idea of the graph structure.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Star and Triangle Motifs attached&lt;/strong>&lt;/td>
&lt;td>Node to Label Mapping : Node 1889: Label 4 | &amp;hellip; Node 1893: Label 2|&amp;hellip; Graph motif information: Triangle motifs attached to ? node: |1893,2034,1531|, |1893,1531,429| Star motifs connected to ? node: | |&lt;/td>
&lt;td>We pass the star motifs and triads attached to the ? label, which gives an idea of the influential nodes and triads connected to the ? node.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>No of cliques ? Node is part of&lt;/strong>&lt;/td>
&lt;td>Node to Label Mapping : Node 1889: Label 4 | &amp;hellip; Node 1893: Label 2|&amp;hellip; Graph motif information: Number of cliques in graph: 0| Node is a part of these cliques: | |&lt;/td>
&lt;td>We pass the number of cliques in the network, which gives an idea of its clustered nature. We also pass the cliques the ? label is a part of, which gives an idea of the immediate community of the unlabelled node.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>No of cliques ? Node is attached to&lt;/strong>&lt;/td>
&lt;td>Node to Label Mapping : Node 1889: Label 4 | &amp;hellip; Node 1893: Label 2|&amp;hellip; Graph motif information: ? Node is attached to these cliques: | |&lt;/td>
&lt;td>We pass the cliques the ? label is attached to, which gives an idea of the neighboring influential community of the unlabelled node.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="example-1">Example&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">Task: Node Label Prediction (Predict the label of the node marked with a ?) given the node-label mapping and graph
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">motif information in the text enclosed in triple backticks. Response should be in the format &amp;#34;Label of Node = &amp;lt;predicted
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">label&amp;gt;&amp;#34;.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">If the predicted label cannot be determined, return &amp;#34;Label of Node = -1&amp;#34;.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">```Node-Label Mapping: {1: A, 2: A, 3: ?}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Graph-motif information: No of triangles: 1| Triangles
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">attached to ? Node : [1,2,3]| ```
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="image-modality">Image Modality&lt;/h2>
&lt;p>We first render our sampled graphs with NetworkX and color each node according to its label.&lt;/p>
&lt;p>We always color the &lt;strong>unlabeled node red and mark it with a &amp;lsquo;?&amp;rsquo; label&lt;/strong>.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/2.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;h3 id="image-representation">Image representation&lt;/h3>
&lt;p>We examine how &lt;strong>different changes to the image representation can improve an image&amp;rsquo;s human readability&lt;/strong>. We then use these image encodings to evaluate node classification performance.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:center">
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/2.jpg" alt="Original NetworkX Graph" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/th>
&lt;th style="text-align:center">
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/3.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/th>
&lt;th style="text-align:center">
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/4.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:center">Original NetworkX Graph&lt;/td>
&lt;td style="text-align:center">Node Size Increase&lt;br />Enlarging the nodes&lt;/td>
&lt;td style="text-align:center">Contrasting Text Color&lt;br />This subfigure contrasts the text labels against the node colors to improve the &amp;ldquo;human readability&amp;rdquo; of the labels.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:center">
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/5.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/th>
&lt;th style="text-align:center">
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/6.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/th>
&lt;th style="text-align:center">
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/7.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:center">Distinctive Node Colors&lt;br />Choosing a distinct color for nodes of each label makes the individual nodes easier to tell apart.&lt;/td>
&lt;td style="text-align:center">Node Size increase based on 1-Hop distance&lt;br />Enlarging the neighboring nodes&lt;/td>
&lt;td style="text-align:center">Aggregate all changes&lt;br />Applying all of the enhancements above&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h1 id="result">Result&lt;/h1>
&lt;h2 id="results-across-all-modalities">Results Across All Modalities&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>Cora&lt;/th>
&lt;th>Citeseer&lt;/th>
&lt;th>Pubmed&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>GNN Baselines&lt;/strong>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>GCN&lt;/td>
&lt;td>0.7584 ±0.121&lt;/td>
&lt;td>0.6102 ±0.087&lt;/td>
&lt;td>0.7546 ±0.076&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>GAT&lt;/td>
&lt;td>0.7989 ±0.092&lt;/td>
&lt;td>0.6583 ±0.074&lt;/td>
&lt;td>0.7490 ±0.060&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>GraphSage&lt;/td>
&lt;td>0.7719 ±0.124&lt;/td>
&lt;td>0.6017 ±0.103&lt;/td>
&lt;td>0.7193 ±0.076&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>LLMs + Encoding Modality&lt;/strong>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Text🥇&lt;/td>
&lt;td>&lt;strong>0.81&lt;/strong> ±0.04 [0.07 ±0.03]&lt;/td>
&lt;td>&lt;strong>0.75&lt;/strong> ±0.05 [0.07 ±0.01]&lt;/td>
&lt;td>&lt;strong>0.83&lt;/strong> ±0.01 [0.08 ±0.01]*&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Motif&lt;/td>
&lt;td>0.73 ±0.06 [0.06 ±0.01]&lt;/td>
&lt;td>0.59 ±0.01 [0.32 ±0.02]&lt;/td>
&lt;td>0.77 ±0.06 [0.13 ±0.04]&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Image🥈&lt;/td>
&lt;td>0.77 ±0.05 [0.04 ±0.02]*&lt;/td>
&lt;td>0.71 ±0.09 [0.06 ±0.01]*&lt;/td>
&lt;td>0.79 ±0.03 [0.19 ±0.01]&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>⭐From this table, we find that &lt;strong>the text modality is comparable with graph baselines in all three datasets&lt;/strong>, while &lt;strong>the image modality comes a close second&lt;/strong>. This shows the potential of LLMs to serve as a good foundation model for graphs.&lt;/p>
&lt;p>⭐We also observe that &lt;strong>the image modality has the lowest denial rate on the smaller CORA and Citeseer datasets, while the larger Pubmed dataset shows a higher denial rate&lt;/strong>. &lt;strong>This may be because the subgraphs sampled there are bigger, which clutters the image modality and leads the LLM to deny a classification.&lt;/strong>&lt;/p>
&lt;h3 id="qualitative-analysis-of-denial-of-classification-in-the-image-modality">Qualitative analysis of denial of classification in the Image Modality&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:center">
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/8.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/th>
&lt;th style="text-align:center">
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/9.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/th>
&lt;th style="text-align:center">
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/10.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:center">a.(Ground = 0) Without additional context or rules for how labels are assigned, it is not possible to accurately predict the label of the red node.&lt;br />All the other nodes are colored according to their label, whereas the ? node is colored red, which confuses the LLM.&lt;/td>
&lt;td style="text-align:center">b.(Ground = 4) The label cannot be determined with certainty due to the lack of a discernible pattern or rule that associates a node&amp;rsquo;s color or its connections with its label.&lt;br />Heterophily is present in the graph: 3-?-4&lt;/td>
&lt;td style="text-align:center">c.(Ground = 2) The label cannot be determined with certainty due to the lack of a clear pattern in the graph and no previous examples of red nodes to infer from.&lt;br />Few-shot examples are needed&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>We observe that a) &lt;strong>the LLM requires context about how labels are assigned to each node&lt;/strong>. We left this information implicit in our image modality encoder, where every node is colored per its label. The red color is reserved for the ? node, which is unlabeled. This information is not explicit to the LLM. With image (b), there is &lt;strong>no clear pattern associating the node&amp;rsquo;s color with its label, a confusion induced by the great amount of heterophily in the graph.&lt;/strong> Image (c) brings up the need for few-shot learning, that is, for showing the LLM other graph examples.&lt;/p>
&lt;h3 id="insights-from-graphtmi">Insights from GraphTMI&lt;/h3>
&lt;p>&lt;strong>Easy problems (high homophily, simple graph structure) have higher accuracy with the image modality encoding&lt;/strong>. Graphs categorized as &lt;strong>medium or hard&lt;/strong>, because they are heterophilous or structurally complex, achieve &lt;strong>higher accuracy with the text modality&lt;/strong>, though the image modality is not far behind.&lt;/p>
&lt;h2 id="text-modality-results">Text Modality Results&lt;/h2>
&lt;h3 id="edge-encoding-function-1">Edge Encoding Function&lt;/h3>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/11.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>The figure shows that the 🌟&lt;strong>adjacency list&lt;/strong>, combined with node-label mapping, is the most informative edge encoding function: it strikes the best balance between &lt;strong>high accuracy&lt;/strong> and a &lt;strong>low token limit fraction&lt;/strong>.&lt;/p>
&lt;blockquote>
&lt;ul>
&lt;li>accuracy rate(↑)&lt;/li>
&lt;li>mismatch rate (↓)&lt;/li>
&lt;li>denial rate (↓)&lt;/li>
&lt;li>token limit fraction (↓)&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;h3 id="impact-of-graph-structure-and-graph-sampling">Impact of graph structure and graph sampling:&lt;/h3>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/12.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>&lt;strong>Green is the accuracy rate, blue is the mismatch rate, red is the denial rate, and pink is the token limit fraction.&lt;/strong> The desired trends for each metric are given in brackets - (↑) accuracy rate, (↓) mismatch rate, (↓) denial rate, and (↓) token limit fraction. The x-axis distinguishes between ego graph sampling (ego) and forest fire sampling (ff) through different bar textures.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>The impact on accuracy is small; what is mainly affected is the token limit fraction.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Both sampling strategies perform best on CORA, probably because it is smaller, denser, and more clustered.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="motif-modality-results">Motif Modality Results&lt;/h2>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/13.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>We observe that the mean accuracy rate rises when the &amp;ldquo;triangle and star attached to ? node&amp;rdquo; motif is added, while the other metrics for the same setting stay low.&lt;/p>
&lt;ul>
&lt;li>This part contains almost no analysis; it merely mentions in passing that &amp;ldquo;triangle and star attached to ? node&amp;rdquo; works best.&lt;/li>
&lt;/ul>
&lt;h2 id="image-modality-results">Image Modality Results&lt;/h2>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/which-modality-text-motif-image/14.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>We observe that the &amp;ldquo;rendering change&amp;rdquo; offers the highest bump in accuracy, which only goes down when &amp;ldquo;node size is changed on hop&amp;rdquo;. This is probably because the LLM is confused by the different node sizes and what they mean. It could be resolved by clarifying the text prompt or by using different shapes to represent nodes at different hop distances. Based on Figure 11, when &amp;ldquo;all the changes are applied&amp;rdquo;, the denial rate is at its minimum and the accuracy rate at its maximum (0.7).&lt;/p>
&lt;ol>
&lt;li>Rendering changes do improve accuracy.&lt;/li>
&lt;li>When &amp;ldquo;all the changes are applied&amp;rdquo;, the denial rate is at its minimum and the accuracy rate at its maximum (0.7).&lt;/li>
&lt;/ol>
&lt;h1 id="conclusion">Conclusion&lt;/h1>
&lt;ul>
&lt;li>Representing graphs in the image and motif modalities as LLM input is something we had not seen before.&lt;/li>
&lt;li>Limited by compute and the token limit, the maximum hop count was set to 3.&lt;/li>
&lt;/ul></description></item><item><title>Paper Review | Graph-Guided Reasoning for Multi-Hop Question Answering in Large Language Models</title><link>https://geyuyao.com/post/graph-guided-reasoning-en/</link><pubDate>Mon, 20 Nov 2023 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/graph-guided-reasoning-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/graph-guided-reasoning/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> Graph-Guided Reasoning for Multi-Hop Question Answering in Large Language Models&lt;/p>
&lt;p>&lt;strong>Institution:&lt;/strong> Korea University, Amazon Alexa AI&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Jinyoung Park, Ameen Patel, Omar Zia Khan, Hyunwoo J. Kim, Joo-Kyung Kim&lt;/p>
&lt;p>&lt;strong>Arxiv Link:&lt;/strong> &lt;a href="https://arxiv.org/abs/2311.09762" target="_blank" rel="noopener">https://arxiv.org/abs/2311.09762&lt;/a>&lt;/p>
&lt;p>&lt;strong>Code Link:&lt;/strong> None&lt;/p>
&lt;p>&lt;strong>Date:&lt;/strong> 2023.11.16&lt;/p>
&lt;p>&lt;strong>Abstract:&lt;/strong> Chain-of-Thought (CoT) prompting has boosted the multi-step reasoning capabilities of Large Language Models (LLMs) by generating a series of rationales before the final answer. This paper analyzes the reasoning paths generated by CoT and identifies two issues in multi-step reasoning: (i) Generating rationales irrelevant to the question, (ii) Unable to compose subquestions or queries for generating/retrieving all the relevant information. To address these issues, the authors propose a graph-guided CoT prompting method, which guides the LLMs to reach the correct answer with graph representation/verification steps. This involves leveraging LLMs to construct a &amp;ldquo;question/rationale graph&amp;rdquo; using knowledge extraction prompting given the initial question and the rationales generated in previous steps. Then, the graph verification step diagnoses the current rationale triplet by comparing it with the existing question/rationale graph to filter out irrelevant rationales and generate follow-up questions to obtain relevant information. Additionally, CoT paths that exclude the extracted graph information are generated to represent the context information missed from the graph extraction. The proposed graph-guided reasoning method shows superior performance compared to previous CoT prompting and its variants on multi-hop question answering benchmark datasets.&lt;/p>
&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;p>The paper proposes an LLM-based, graph-guided reasoning approach for multi-step reasoning problems.&lt;/p>
&lt;p>It makes two main contributions:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>The reasoning approach described above&lt;/p>
&lt;/li>
&lt;li>
&lt;p>An in-context learning method for knowledge triplet extraction that allows variable definitions&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h1 id="an-llm-based-graph-guided-reasoning-approach-for-multi-step-reasoning">An LLM-Based, Graph-Guided Reasoning Approach for Multi-Step Reasoning&lt;/h1>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/graph-guided-reasoning/0.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>The method has four steps:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Build the question graph&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Decompose the question and generate intermediate subquestions&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Answer the subquestions&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Verify the intermediate reasoning&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h2 id="question-graph">Question graph&lt;/h2>
&lt;p>The question graph is built by extracting triplets from the question. What &amp;ldquo;graph-based&amp;rdquo; means here is essentially converting the question into a symbolic reasoning process that forms part of a graph.&lt;/p>
&lt;p>For example, the question &amp;ldquo;When did the director of film Hypocrite (Film) die?&amp;rdquo; can be converted into two subquestions serving as two edges in the graph: (&amp;ldquo;Hypocrite (Film)&amp;rdquo;, directed by, $1), ($1, death date, $2).&lt;/p>
&lt;p>The novelty here is that the paper introduces formal logic into the reasoning process in a form resembling first-order logic (FOL). In this process, the variables ($1, $2) can only stand for individuals, not for propositions or other functions.&lt;/p>
&lt;p>The authors introduce variable entities to handle wh-questions.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;Wh-questions&amp;rdquo; are a type of question in English that begin with &amp;ldquo;wh-&amp;rdquo; words, such as &amp;ldquo;who,&amp;rdquo; &amp;ldquo;what,&amp;rdquo; &amp;ldquo;where,&amp;rdquo; &amp;ldquo;when,&amp;rdquo; &amp;ldquo;why,&amp;rdquo; and &amp;ldquo;how&amp;rdquo; (though &amp;ldquo;how&amp;rdquo; does not start with &amp;ldquo;wh,&amp;rdquo; it is grouped with them functionally).&lt;/p>
&lt;/blockquote>
&lt;h2 id="intermediate-subquestion-generation">Intermediate subquestion generation&lt;/h2>
&lt;p>What distinguishes the subquestion generation here from other work is that it is carried out under the guidance of the graph.&lt;/p>
&lt;p>Concretely, the paper filters out question triplets whose subject and object are both variables or both entities, so the process only attends to triplets pairing an entity subject with a variable object, or a variable subject with an entity object.&lt;/p>
&lt;p>The reason is easy to see: for a triplet (variable1, relationship, variable2) or a triplet (entity1, relationship, entity2), further decomposition serves no purpose.&lt;/p>
&lt;h2 id="answering-the-subquestions">Answering the subquestions&lt;/h2>
&lt;p>Subquestions are shorter and simpler than the original question, so a correct answer is easier to produce. Because LLMs are prone to hallucination and may never have been trained on the documents in question, the output can still be wrong; RAG is one way to improve answer accuracy.&lt;/p>
&lt;h2 id="verifying-the-intermediate-reasoning">Verifying the intermediate reasoning&lt;/h2>
&lt;p>The generated rationale triplets are checked for validity by verifying that the answers align with the question graph.&lt;/p>
&lt;p>Concretely, at least two components must match between the rationale triplet and some triplet in the question graph. If they do, we accept the rationale that produced the matched triplet; if the triplet matches nothing in the question graph, we reject it.&lt;/p>
&lt;p>Take the rationale triplet (&amp;ldquo;Hypocrite (Film)&amp;rdquo;, directed by, &amp;ldquo;Miguel Morayta&amp;rdquo;) and the question graph (&amp;ldquo;Hypocrite (Film)&amp;rdquo;, directed by, $1), ($1, death date, $2). The question graph contains the triplet (&amp;ldquo;Hypocrite (Film)&amp;rdquo;, directed by, $1), whose subject is &amp;ldquo;Hypocrite (Film)&amp;rdquo; and whose relation is &amp;ldquo;directed by&amp;rdquo;, so the rationale is accepted.&lt;/p>
&lt;p>For a counterexample, no triplet in the question graph matches the rationale triplet (&amp;ldquo;Miguel Morayta&amp;rdquo;, place of death, &amp;ldquo;Mexico&amp;rdquo;), so it is rejected.&lt;/p>
&lt;h1 id="experiments">Experiments&lt;/h1>
&lt;h2 id="setup">Setup&lt;/h2>
&lt;p>&lt;strong>Datasets:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>
&lt;p>2WikiMultihopQA consists of complex 2-hop questions that require composition or comparison.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>MuSiQue is a more challenging dataset whose 2- to 4-hop questions can be decomposed into simpler ones.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Bamboogle consists of 125 two-hop questions whose supporting evidence comes from Wikipedia.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Models:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Llama-2 13B&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Llama-2 70B&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="result">Result&lt;/h2>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/graph-guided-reasoning/1.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>The figure above shows part of the experimental results: the proposed method outperforms every baseline.&lt;/p></description></item><item><title>Paper Review | GraphText — Mapping Graphs to Text</title><link>https://geyuyao.com/post/graphtext-en/</link><pubDate>Tue, 14 Nov 2023 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/graphtext-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/graphtext/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> GraphText: Graph Reasoning in Text Space&lt;/p>
&lt;p>&lt;strong>Institute:&lt;/strong> Université de Montréal&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Jianan Zhao, Le Zhuo, Yikang Shen, Meng Qu, Kai Liu, Michael Bronstein, Zhaocheng Zhu, Jian Tang&lt;/p>
&lt;p>&lt;strong>Link:&lt;/strong> &lt;a href="https://arxiv.org/abs/2310.01089" target="_blank" rel="noopener">https://arxiv.org/abs/2310.01089&lt;/a>&lt;/p>
&lt;p>&lt;strong>Date:&lt;/strong> 2023.10.02&lt;/p>
&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;p>We have previously covered two papers that use LLMs to solve graph problems. In both, the authors imported prompting techniques from the LLM reasoning literature, ran them on graph problems, and released a benchmark. Fruitful as they were, neither proposed a new way of generating prompts tailored to the nature of graphs. Here the authors draw on the properties of graph structure to propose &lt;strong>GraphText&lt;/strong>, a framework that maps graphs into text space.&lt;/p>
&lt;p>&lt;strong>GraphText&lt;/strong> builds a graph-syntax tree for each graph; the tree encapsulates both node attributes and the relations between nodes. Traversing this tree produces a graph-text sequence, which is then handled by a large language model (LLM), turning the graph task into a text generation task.&lt;/p>
&lt;p>Beyond its headline advantage — &lt;strong>mapping graph space into text space&lt;/strong> — the paper makes the following contributions:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Conventional GNN approaches require training a separate GNN model for every graph, whereas here a general-purpose LLM suffices via in-context learning&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>GraphText&lt;/strong> is a general framework that works on both plain graphs and text-attributed graphs&lt;/p>
&lt;/li>
&lt;li>
&lt;p>It is interactive&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h1 id="methodology">Methodology&lt;/h1>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>The method can be summarized by the following formula:&lt;/p>
$\tilde{y}_i=h(f_{LLM}(g(G)_i;\phi))$
&lt;p>Notation:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>
$G$ the graph&lt;/p>
&lt;/li>
&lt;li>
&lt;p>
$g(G)_i=T_{in}[i]$ the textual description of node
$i$&lt;/p>
&lt;/li>
&lt;li>
&lt;p>
$\phi$ the LLM parameters&lt;/p>
&lt;/li>
&lt;li>
&lt;p>
$f_\text{LLM}(\cdot;\phi):\mathcal{T}\to\mathcal{T}$ the LLM-based mapping function, whose input and output both live in text space&lt;/p>
&lt;/li>
&lt;li>
&lt;p>
$h:T_{out}\mapsto\tilde{Y}$ maps the LLM output to a label&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="building-the-graph-syntax-tree">Building the graph-syntax tree&lt;/h2>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/graphtext/0.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>It should first be made clear that in this paper a graph consists of two parts: the attributes of its nodes and the relations between them.&lt;/p>
&lt;p>The root of the graph-syntax tree is an empty node, the leaves
$\tilde{T}_\mathrm{L}$ are the textual attributes of the graph nodes, and the internal nodes
$\tilde{T}_{I}$ are natural-language sequences.&lt;/p>
&lt;p>Building the graph-syntax tree involves three parts:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Construct the ego-subgraph&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Select the leaf nodes&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Construct the internal nodes and edges&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>As shown in panel (c) above, the attributes in the graph are
$F={\mathrm{F}_{X}[i],\mathrm{F}_{Y}[i]|\forall v_{i}\in V}$, and the relations are defined by shortest-path distance — center-node, 1st-hop, and 2nd-hop — that is,
$R={\boldsymbol{R_{\mathrm{SPD=0}}},\boldsymbol{R_{\mathrm{SPD=1}}},\boldsymbol{R_{\mathrm{SPD=2}}}}$. Taking node 0 as the center, the ego-subgraph is constructed. Next the leaf nodes
$\tilde{T_{\mathrm{L}}}={\mathrm{F_{\mathrm{X}}[0]},\mathrm{F_{\mathrm{X}}[1]},\mathrm{F_{\mathrm{X}}[2]}\mathrm{F_{\mathrm{X}}[3]},\mathrm{F_{\mathrm{X}}[4]},\mathrm{F_{\mathrm{Y}}[1]},\mathrm{F_{\mathrm{Y}}[3]}}$, the internal nodes
$\tilde{T}_\mathrm{I}=\{\text{“center-node",“}1\text{st-}\text{hop",“2nd-hop”,“label”,“feature”}\}$, and the tree edges are constructed. Finally, traversing the graph-syntax tree yields the natural-language sequence.&lt;/p></description></item><item><title>Paper Review | ReAct — Combining Reasoning and Acting in LLMs</title><link>https://geyuyao.com/post/react-en/</link><pubDate>Fri, 27 Oct 2023 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/react-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/react/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> ReAct: Synergizing Reasoning and Acting in Language Models&lt;/p>
&lt;p>&lt;strong>Institute:&lt;/strong> Department of Computer Science, Princeton University&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan, Yuan Cao&lt;/p>
&lt;p>&lt;strong>Link:&lt;/strong> &lt;a href="https://arxiv.org/pdf/2210.03629.pdf" target="_blank" rel="noopener">https://arxiv.org/pdf/2210.03629.pdf&lt;/a>&lt;/p>
&lt;p>&lt;strong>Shared Link:&lt;/strong> &lt;a href="https://mp.weixin.qq.com/s/5DFnutIpNIPRyJ7EUlfiEw" target="_blank" rel="noopener">https://mp.weixin.qq.com/s/5DFnutIpNIPRyJ7EUlfiEw&lt;/a>&lt;/p>
&lt;h1 id="motivation">Motivation&lt;/h1>
&lt;ul>
&lt;li>
&lt;p>CoT is black-box reasoning: both the reasoning process and the knowledge it draws on stay inside the model&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Earlier work has explored using pretrained language models to plan and act in interactive environments&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h1 id="inspiration">Inspiration&lt;/h1>
&lt;p>Between two actions, humans track their progress in language — &amp;ldquo;all the ingredients are chopped now, so I should boil the water,&amp;rdquo; for instance. Drawing on this habit, the authors set out to make an LLM&amp;rsquo;s reasoning process explicit.&lt;/p>
&lt;h1 id="react">ReAct&lt;/h1>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://picdl.sunbangyan.cn/2023/11/03/36bea36781157e6f982ac30387947ca3.png" alt="image.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/react/9ea5e0e989d7c7d5e8eab5058b037ca7.png" alt="1698584125954.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>ReAct is a framework that lets an LLM combine thought and action.&lt;/p>
&lt;p>At time $t$, let the observed information be $o_t\in\mathcal{O}$ and the action be $a_t\in\mathcal{A}$, where $a_t$ follows the policy $\pi(a_t|c_t)$ with $c_t=\left(o_1,a_1,\cdots,o_{t-1},a_{t-1},o_t\right)$. Mapping $c_t\mapsto a_t$ directly, however, is implicit and computationally expensive.&lt;/p>
&lt;p>ReAct&amp;rsquo;s approach is simple: augment the set $\mathcal{A}$ into $\hat{\mathcal{A}}=\mathcal{A}\cup\mathcal{L}$, where $\mathcal{L}$ is the space of thoughts, or reasoning steps. Now $\hat a_t\in\mathcal{L}$ is the action obtained from the context $c_t$, and in the next round $c_{t+1}=\left(c_{t},\hat{a}_{t}\right)$ serves as the context for generating the next action.&lt;/p>
&lt;p>Every ReAct cycle consists of acting, thinking, and observing the environment.&lt;/p>
&lt;p>The approach does come with a drawback: model capacity has to be large enough, and the paper uses a 540B model.&lt;/p>
&lt;p>The authors split tasks into two categories, reasoning-dominant and decision-dominant.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Reasoning-dominant: for tasks where reasoning carries most of the weight, such as multi-step reasoning, the authors use a thought-action-observation loop.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Decision-dominant: for decision tasks involving many operations, by contrast, thoughts only need to surface occasionally — you are in a kitchen, the environment is such-and-such, and you need to find such-and-such.&lt;/p>
&lt;/li>
&lt;/ul></description></item><item><title>Paper Review | Reasoning with Language Model is Planning with World Model</title><link>https://geyuyao.com/post/rap-en/</link><pubDate>Thu, 26 Oct 2023 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/rap-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/rap/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> Reasoning with Language Model is Planning with World Model&lt;/p>
&lt;p>&lt;strong>Institute:&lt;/strong> UC San Diego, University of Florida&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Shibo Hao, Yi Gu, Haodi Ma, Joshua Jiahua Hong, Zhen Wang, Daisy Zhe Wang, Zhiting Hu&lt;/p>
&lt;p>&lt;strong>Link:&lt;/strong> &lt;a href="https://arxiv.org/pdf/2305.14992.pdf" target="_blank" rel="noopener">https://arxiv.org/pdf/2305.14992.pdf&lt;/a>&lt;/p>
&lt;p>&lt;strong>Shared Link:&lt;/strong> &lt;a href="https://mp.weixin.qq.com/s/ZLktf__PCPsMYdX-Ikm_5A" target="_blank" rel="noopener">https://mp.weixin.qq.com/s/ZLktf__PCPsMYdX-Ikm_5A&lt;/a>&lt;/p>
&lt;h1 id="overview">Overview&lt;/h1>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://picss.sunbangyan.cn/2023/11/03/4d42c35d2b5aa8f42937109c06d235f6.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>Prior research has shown that humans possess an internal world model that lets them simulate actions and their effects on the state of the world, enabling deliberate planning for complex tasks such as motor control, imagination, reasoning, and decision making. LLMs, by contrast, can only reason autoregressively. The authors identify three main factors that limit LLM reasoning:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>The lack of an internal model that simulates the current state&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The lack of a reward mechanism to guide the model&amp;rsquo;s reasoning&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The inability to balance exploration of the future against exploitation of past experience&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>For the first problem, they borrow the idea of a world model from &lt;strong>reinforcement learning&lt;/strong> and use the LLM itself to simulate the current state.&lt;/p>
&lt;p>For the second problem, they &lt;strong>design four LLM-based reward schemes&lt;/strong>.&lt;/p>
&lt;p>For the third problem, they turn to &lt;strong>Monte Carlo tree search&lt;/strong>.&lt;/p>
&lt;h1 id="world-model">World model&lt;/h1>
&lt;p>The world model here is the notion from reinforcement learning, covering the external environment, the simulation of actions, the outcomes of behavior, and so on. The authors implement it with prompting and an LLM.&lt;/p>
&lt;p>Let the current state be
$s_{t,t=0,1,2,3...T}$. The process in which the LLM, acting as an agent, infers action $a_t$ from
$s_t$ and prompt
$ c$ can be written as
$a_t \sim p(a|s_t,c)$ . The LLM, now acting as the world model, then predicts the next state
$s_{t+1}$ from
$ a_t$ and
$s_t$ .&lt;/p>
&lt;h1 id="reward">Reward&lt;/h1>
&lt;p>Every reasoning step has to be assessed for feasibility so that the assessment can steer the reasoning. The authors design an evaluation function
$r_t=r(s_t,a_t)\in\mathbb{R}$ that returns a reward for the state $s_t$ and action $a_t$ at time $t$.&lt;/p>
&lt;h1 id="reasoning-via-monte-carlo-tree-search">Reasoning via Monte Carlo tree search&lt;/h1>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://picst.sunbangyan.cn/2023/11/03/7e2aa5c36dcec92ef666a82d215af279.png" alt="1698568853722.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>Monte Carlo tree search consists of four main steps:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Selection: pick the leaf node with the highest expected return according to its UCB value&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Expansion: expand that leaf node&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Simulation: simulate from the expanded leaf node and judge the outcome&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Back-propagation: propagate the result back up the tree&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>The Selection and Simulation stages are worth a closer look.&lt;/p>
&lt;h2 id="selection">Selection&lt;/h2>
&lt;p>Each candidate node gets a UCB value, computed as follows:&lt;/p>
$a^*=\arg\max\limits_{a\in A(s)}\left[Q(s,a)+w\sqrt{\frac{\ln N(s)}{N(c(s,a))}}\right]$
&lt;ul>
&lt;li>
&lt;p>The first term, the Q value, is the node&amp;rsquo;s average reward over past visits; it represents exploitation of past experience.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>In the second term,
$N$ is the visit count and
$c(s,a)$ is the child of this node (the result of applying action $a$ to state $s$); this term represents exploration of the future.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>$w$ is the weight of the second term.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>The formula gives the Selection policy two tendencies:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>It favors nodes that have yielded higher rewards in the past&lt;/p>
&lt;/li>
&lt;li>
&lt;p>It favors nodes that have not yet been explored&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>The UCB formula in Monte Carlo tree search therefore resolves the &lt;strong>exploration vs. exploitation&lt;/strong> dilemma.&lt;/p>
&lt;h2 id="simulation">Simulation&lt;/h2>
&lt;p>This stage uses the &lt;strong>world model&lt;/strong> to simulate the future of the current node. Starting from that node, at each node
$s_t$ we create an action
$a_t$ following an expansion policy and use the world model to predict the next state
$a_{t+1}$. Expansion continues until it reaches a terminal state.&lt;/p>
&lt;p>See panel $(c)$ of the figure above.&lt;/p></description></item><item><title>Paper Review | Can Language Models Solve Graph Problems in Natural Language?</title><link>https://geyuyao.com/post/lm-graph-problems-natural-language-en/</link><pubDate>Mon, 23 Oct 2023 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/lm-graph-problems-natural-language-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/lm-graph-problems-natural-language/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Title:&lt;/strong> Can Language Models Solve Graph Problems in Natural Language?&lt;/p>
&lt;p>&lt;strong>Institute:&lt;/strong> Xi&amp;rsquo;an Jiaotong University, University of Washington&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Heng Wang, Shangbin Feng, Tianxing He, Zhaoxuan Tan, Xiaochuang Han, Yulia Tsvetkov&lt;/p>
&lt;p>&lt;strong>Date:&lt;/strong> 2023.5.13&lt;/p>
&lt;p>&lt;strong>Link:&lt;/strong> &lt;a href="https://arxiv.org/pdf/2305.10037v1.pdf" target="_blank" rel="noopener">2305.10037v1.pdf (arxiv.org)&lt;/a>&lt;/p>
&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;p>This is the first attempt to use large language models to solve graph problems. The authors introduce &lt;strong>NLGraph&lt;/strong>, a natural-language benchmark containing over a thousand basic graph problems, and draw several conclusions from experiments on GPT-3/4. At the end of the paper they propose two methods for improving how LLMs handle graph problems.&lt;/p>
&lt;p>In summary, the contributions are:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>The first benchmark for handling graph problems in natural language, &lt;strong>NLGraph&lt;/strong>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Experiments on GPT-3/4 with measurements of LLM performance, yielding several regularities&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Two methods for improving performance&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h1 id="nlgraph">NLGraph&lt;/h1>
&lt;p>Put simply, this benchmark is a collection of graphs described in natural language, each paired with its answer.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/lm-graph-problems-natural-language/1698054409045.png" alt="1698054409045.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;h2 id="graph-generation">Graph generation&lt;/h2>
&lt;p>Generate n nodes and connect each pair of nodes with probability p, so graph generation is controlled by n and p. Individual tasks impose additional constraints.&lt;/p>
&lt;h2 id="tasks">Tasks&lt;/h2>
&lt;p>NLGraph contains eight kinds of tasks:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Connectivity: whether two nodes are connected&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Cycle detection: whether the graph contains a cycle&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Topological sort&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Shortest path&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Maximum flow&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Bipartite graph matching&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Hamiltonian path&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Simulating a graph neural network&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="statistics">Statistics&lt;/h2>
&lt;p>The basic version contains 5,902 examples; the extended version contains 29,370.&lt;/p>
&lt;h1 id="experimental-setup">Experimental Setup&lt;/h1>
&lt;h2 id="baselines">Baselines&lt;/h2>
&lt;p>The authors use a variety of prompts as baselines:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>ZERO-SHOT&lt;/p>
&lt;/li>
&lt;li>
&lt;p>FEW-SHOT&lt;/p>
&lt;/li>
&lt;li>
&lt;p>CoT&lt;/p>
&lt;/li>
&lt;li>
&lt;p>0-CoT&lt;/p>
&lt;/li>
&lt;li>
&lt;p>least-to-most (LTM-2023): break a large problem into several subproblems and solve them one by one&lt;/p>
&lt;/li>
&lt;li>
&lt;p>self-consistency (SC-2023): ask the same question in multiple ways and take the most consistent result&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>The authors also use random guessing as a baseline — for yes/no questions the baseline is 50%, and for shortest-path questions the baseline is whether a randomly chosen path is correct.&lt;/p>
&lt;h2 id="models">Models&lt;/h2>
&lt;p>TEXT-DAVINCI-003, GPT-3/4&lt;/p>
&lt;h1 id="conclusions">Conclusions&lt;/h1>
&lt;h2 id="llms-have-preliminary-reasoning-ability-on-graph-problems">LLMs have preliminary reasoning ability on graph problems&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>On connectivity, cycle detection, and shortest path, LLM performance is markedly above Random, showing that the model is not answering at random and does possess preliminary reasoning ability.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>With CoT or CoT+SC prompting, accuracy exceeds the Random baseline by 37.33%–57.82%&lt;/p>
&lt;/li>
&lt;li>
&lt;p>On connectivity and shortest path, ZERO-SHOT exceeds Random accuracy by 33.81% and 23.33% respectively&lt;/p>
&lt;/li>
&lt;li>
&lt;p>On shortest path, CoT and CoT+SC exceed Random by 22.81%–62.83%&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="advanced-prompting-is-not-necessarily-beneficial">Advanced prompting is not necessarily beneficial&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>Advanced prompts such as CoT and SC improve accuracy on most problems&lt;/p>
&lt;/li>
&lt;li>
&lt;p>But on complex graph problems, advanced prompts such as CoT, CoT+SC, and LTM actually underperform Few-shot&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The authors attribute this to the LLM&amp;rsquo;s inability to generate a chain of thought for complex graph problems&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="in-context-prompting-can-backfire">In-context prompting can backfire&lt;/h2>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/lm-graph-problems-natural-language/1698055792161.png" alt="1698055792161.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/lm-graph-problems-natural-language/1698055805107.png" alt="1698055805107.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;ul>
&lt;li>
&lt;p>On complex graph reasoning problems such as Hamiltonian path and bipartite matching, ZERO-SHOT outperforms Few-shot&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The reason may be that on complex problems the LLM cannot extract knowledge from the context, and the context instead dilutes its attention&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="llms-are-unsurprisingly-brittle">LLMs are (un)surprisingly brittle&lt;/h2>
&lt;p>The heading means that the LLM may have misconstrued the reasoning process behind the question.&lt;/p>
&lt;p>Although the LLM performs well, it may be arriving at correct answers by exploiting spurious correlations. For example, since higher-degree nodes are mentioned more often and are more likely to be connected, the language model may simply be counting node occurrences rather than actually searching for a path. In other words, on connectivity problems, nodes with especially high degree tend to be connected to one another, which may lead the model to assume that high-degree nodes are connected instead of verifying a path.&lt;/p>
&lt;p>The authors therefore constructed two special datasets.&lt;/p>
&lt;h3 id="chain">Chain&lt;/h3>
&lt;p>Split a graph into k parts, each an independent chain, and ask whether the head and tail nodes of each chain are connected. The head and tail have the lowest degree yet are in fact connected.&lt;/p>
&lt;h3 id="clique">Clique&lt;/h3>
&lt;p>Build k dense, independent subgraphs. Pick two nodes from different subgraphs; because the subgraphs are dense, both nodes have high degree, but because the subgraphs are disjoint, the two nodes are not connected.&lt;/p>
&lt;p>Unsurprisingly, LLM performance on these two datasets dropped by 40%, confirming the authors&amp;rsquo; suspicion.&lt;/p>
&lt;h1 id="two-methods-for-improving-performance">Two Methods for Improving Performance&lt;/h1>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/lm-graph-problems-natural-language/1698056360356.png" alt="1698056360356.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;h2 id="build-a-graph-prompting-bag">Build-a-Graph Prompting (BAG)&lt;/h2>
&lt;p>The authors reason that mapping the textual description of the graph into an actual conceptual space may help, so they add the sentence &amp;ldquo;Let&amp;rsquo;s construct a graph with the nodes and edges first&amp;rdquo;.&lt;/p>
&lt;h2 id="algorithmic-prompting">Algorithmic Prompting&lt;/h2>
&lt;p>Hint that a specific algorithm can be used to solve the problem — for instance, telling the model to use DFS or BFS.&lt;/p>
&lt;h2 id="result">Result&lt;/h2>
&lt;p>On simple problems, the authors&amp;rsquo; two methods improve performance by 3.07%–16.85%. On complex problems, however, there is no improvement.&lt;/p>
&lt;h1 id="summary">Summary&lt;/h1>
&lt;h2 id="comparison-with-talk-like-a-graph-encoding-graphs-for-large-language-models">Comparison with Talk Like a Graph: Encoding Graphs for Large Language Models&lt;/h2>
&lt;p>Since &amp;ldquo;Talk Like a Graph: Encoding Graphs for Large Language Models&amp;rdquo; is the more recent work, it is referred to below as &amp;ldquo;the latter&amp;rdquo;, while the present paper is &amp;ldquo;the former&amp;rdquo;.&lt;/p>
&lt;h3 id="benchmark">Benchmark&lt;/h3>
&lt;p>The two papers&amp;rsquo; benchmarks complement each other, with some overlap in problem types&lt;/p>
&lt;h3 id="on-prompting">On prompting&lt;/h3>
&lt;p>The latter adds an encoding component relative to the former&lt;/p>
&lt;p>Their prompting differs: the former has LTM and SC prompts, while the latter has BAG prompting (COT-BAG). It is unclear why the latter dropped LTM and SC.&lt;/p>
&lt;h3 id="on-experiments">On experiments&lt;/h3>
&lt;ul>
&lt;li>
&lt;p>The latter adds the effect of model capacity on performance&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The latter adds the effect of graph shape&lt;/p>
&lt;/li>
&lt;li>
&lt;p>On simple graph tasks, ZERO-SHOT beats ZERO-COT in both papers&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Both find that advanced prompting degrades LLM performance on complex graph tasks&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Both hold that &amp;ldquo;mapping the textual description of the graph into an actual conceptual space may help&amp;rdquo;, but the former merely adds the sentence &amp;ldquo;Let&amp;rsquo;s construct a graph with the nodes and edges first&amp;rdquo;, whereas the latter actually tests the LLM on real-world problems.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h3 id="on-novelty">On novelty&lt;/h3>
&lt;ul>
&lt;li>
&lt;p>The former&amp;rsquo;s novelty lies in the dataset, the experimental design, and its pioneering nature&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The latter&amp;rsquo;s novelty lies in treating encoding as a variable&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="questions">Questions&lt;/h2>
&lt;h3 id="solved">Solved&lt;/h3>
&lt;p>Since I read the latter first and had no prior knowledge of the former&amp;rsquo;s work, I raised several questions in my write-up of the latter; here are the answers.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>How well do LLMs handle shortest-path problems? Is the complexity the same as for cycle problems?&lt;/p>
&lt;ul>
&lt;li>
&lt;p>First, the two tasks are different in nature: one is about finding a correct path, the other is a True/False question&lt;/p>
&lt;/li>
&lt;li>
&lt;p>In this paper, shortest path and cycle detection are not equally hard. Cycle detection is classified as a basic problem with three difficulty levels, whereas shortest path is classified as an advanced problem with two difficulty levels.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="generated">Generated&lt;/h3>
&lt;ul>
&lt;li>
&lt;p>Following the latter, what other variables could be mined for experiments?&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Language?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The number of nodes and edges, small graphs $\rightarrow$ large graphs&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Representing graphs as adjacency matrices&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>Classic tree-related problems seem to go unmentioned&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Minimum spanning tree&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Tree diameter&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&amp;hellip;&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>Fine-tuning / LoRA&lt;/p>
&lt;/li>
&lt;/ul></description></item><item><title>Paper Review | Talk Like a Graph: Encoding Graphs for Large Language Models</title><link>https://geyuyao.com/post/talk-like-a-graph-en/</link><pubDate>Sat, 21 Oct 2023 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/talk-like-a-graph-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/talk-like-a-graph/">中文&lt;/a>
&lt;/div>
&lt;p>&lt;strong>Institute:&lt;/strong> Google Research&lt;/p>
&lt;p>&lt;strong>Authors:&lt;/strong> Bahare Fatemi, Jonathan Halcrow, Bryan Perozzi&lt;/p>
&lt;p>&lt;strong>Link:&lt;/strong> &lt;a href="https://arxiv.org/abs/2310.04560" target="_blank" rel="noopener">https://arxiv.org/abs/2310.02207&lt;/a>&lt;/p>
&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;p>This paper feeds graphs into an LLM using a variety of natural-language formulations and measures how performance changes.&lt;/p>
&lt;h2 id="background">Background&lt;/h2>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/talk-like-a-graph/image.png" alt="image.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>There are currently four ways in the literature to tackle graph problems with an LLM:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Natural-language input&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Embedding&lt;/p>
&lt;/li>
&lt;li>
&lt;p>LLM tuning&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Hybrid: GNN &amp;amp; LLM&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>This paper focuses on the first of these. The authors report that encoding graphs according to the patterns they uncover here improves LLM performance on graph reasoning tasks by anywhere from 4.8% to 61.8%.&lt;/p>
&lt;h2 id="contributions">Contributions&lt;/h2>
&lt;ol>
&lt;li>
&lt;p>The authors search for the best way to have an LLM handle graph reasoning problems, splitting the question into two aspects:&lt;/p>
&lt;ol start="2">
&lt;li>
&lt;p>encoding&lt;/p>
&lt;/li>
&lt;li>
&lt;p>prompt&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/li>
&lt;li>
&lt;p>They introduce a new set of benchmarks, &lt;strong>GraphQA&lt;/strong>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h1 id="encoding">Encoding&lt;/h1>
&lt;p>Encoding a graph as text breaks down into two parts: encoding the nodes and encoding the edges.&lt;/p>
&lt;p>Encoding Nodes:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Integers&lt;/p>
&lt;/li>
&lt;li>
&lt;p>English surnames&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Characters from film and television&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Politicians&amp;rsquo; surnames&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Letters&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>Encoding Edges:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Parentheses&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Friendship&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Co-authorship&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Social relations&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Arrows&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Connection, e.g. Node 0 is connected to nodes 1, 2.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>The graph encodings studied in this paper are combinations of the two lists above:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Adjacency: integers + parentheses&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Incident: integers + connection&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Friendship: English surnames + friendship&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Co-authorship: English surnames + co-authorship&lt;/p>
&lt;/li>
&lt;li>
&lt;p>SP: characters from film and television + friendship&lt;/p>
&lt;/li>
&lt;li>
&lt;p>GOT: characters from film and television + friendship&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Social network: English surnames + social relations&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Politician: politicians&amp;rsquo; surnames + social relations&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Expert: letters + arrows&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/talk-like-a-graph/1697950797666.png" alt="1697950797666.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;h1 id="prompt">Prompt&lt;/h1>
&lt;ol>
&lt;li>
&lt;p>Zero-shot prompting (ZERO-SHOT): describe the problem and ask directly&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Few-shot in-context learning (FEW-SHOT): provide examples&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Chain-of-thought (CoT): provide examples together with the steps that solve them&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Zero-shot CoT prompting (ZERO-COT): provide the solution steps but no examples — &amp;ldquo;Let&amp;rsquo;s think step by step&amp;rdquo;&lt;/p>
&lt;/li>
&lt;li>
&lt;p>BAG prompting (COT-BAG)&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h1 id="graphqa">GraphQA&lt;/h1>
&lt;p>GraphQA covers a range of elementary graph problems:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Edge existence&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Node existence&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Node counting&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Edge counting&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Connectivity&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Cycle check&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Disconnected nodes&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h1 id="experiments">Experiments&lt;/h1>
&lt;h2 id="1-encoding--prompt">1. Encoding &amp;amp; Prompt&lt;/h2>
&lt;p>Model used: PaLM 62B&lt;/p>
&lt;ul>
&lt;li>
&lt;p>LLMs perform poorly on basic graph problems&lt;/p>
&lt;/li>
&lt;li>
&lt;p>On simple graph tasks ZERO-SHOT beats ZERO-COT; on complex tasks the ordering reverses&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The choice of encoding has a large effect on performance&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Encoding nodes as integers improves performance&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="2-varying-prompt-questions">2. Varying Prompt Questions&lt;/h2>
&lt;ul>
&lt;li>In the vast majority of experiments, casting the graph question as a real-world question improves model performance&lt;/li>
&lt;/ul>
&lt;h2 id="3-encoding-with-multiple-relation-types">3. Encoding with multiple relation types&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>Using several relation types to encode a graph does not hurt LLM performance — it actually improves it&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The improvement may come from diverse relations being closer to the LLM&amp;rsquo;s training distribution&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="4-model-capacity">4. Model capacity&lt;/h2>
&lt;ul>
&lt;li>Model capacity has a pronounced effect on performance&lt;/li>
&lt;/ul>
&lt;h2 id="5-reasoning-about-disconnected-nodes">5. Reasoning about disconnected nodes&lt;/h2>
&lt;ul>
&lt;li>Accuracy is close to zero: LLMs have almost no ability to reason about disconnected nodes&lt;/li>
&lt;/ul>
&lt;h2 id="6-does-graph-shape-matter">6. Does graph shape matter?&lt;/h2>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/talk-like-a-graph/1697955235299.png" alt="1697955235299.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Graph structure significantly affects LLM performance&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Extraneous structure in the graph hurts the LLM: performance is best on path- and star-shaped graphs&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Providing examples and reasoning chains improves LLM performance&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h1 id="conclusion">Conclusion&lt;/h1>
&lt;ul>
&lt;li>
&lt;p>LLMs perform poorly on basic graph problems&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The graph encoding scheme significantly affects LLM performance&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The number of model parameters has a pronounced effect on accuracy&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h1 id="reflections">Reflections&lt;/h1>
&lt;ol>
&lt;li>
&lt;p>On models&lt;/p>
&lt;p>a. How would 6B or 7B models perform?&lt;/p>
&lt;p>b. Encoding schemes adapted to small models&lt;/p>
&lt;p>c. Why do no emergent abilities show up on graph problems?&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/talk-like-a-graph/1697957401519.png" alt="1697957401519.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The graphs used in the experiments are mostly small&lt;/p>
&lt;p>a. What is the relationship between LLM performance and graph size?&lt;/p>
&lt;p>b. Could an input format be designed specifically for large graphs?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Why do LLMs do better on real-world graph problems? Does this phenomenon appear on other problems as well?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Could LoRA or LoRA tuning be used to improve model performance?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Why is there no comparison against embedding-based approaches?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>How do LLMs perform on shortest-path problems? Is the complexity the same as for cycle problems?&lt;/p>
&lt;/li>
&lt;/ol></description></item><item><title>Paper Review | Language Models Represent Space and Time</title><link>https://geyuyao.com/post/language-models-space-time-en/</link><pubDate>Wed, 11 Oct 2023 00:00:00 +0000</pubDate><guid>https://geyuyao.com/post/language-models-space-time-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/language-models-space-time/">中文&lt;/a>
&lt;/div>
&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/language-models-space-time/0.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>Are the many astonishing abilities of large language models nothing more than the product of statistics over massive data? Or does a world model exist inside them? Recently, a paper posted on arXiv by two MIT authors, &amp;ldquo;&lt;strong>Language Models Represent Space and Time&lt;/strong>&amp;rdquo;, drew wide attention in the research community. Taking the Llama-2 family as their subject, the authors ran experiments on self-constructed spatial and temporal datasets and found evidence for the latter.&lt;/p>
&lt;p>The paper delivers six contributions: four major ones and two minor ones.&lt;/p>
&lt;p>The six contributions (1–4 major, 5–6 minor):&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Produced three spatial datasets and three temporal datasets&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Showed that LLMs do represent space and time, and that this depends on the model and the dataset&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Showed that these representations are linear&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Showed that these representations are robust to changes in the prompt&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Robustness checks&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Space neurons and time neurons&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>The first contribution — six new datasets — is a solid amount of work in itself.&lt;/p>
&lt;p>Contributions two through four provide indirect evidence that a world model exists inside LLMs. Prior to this, similar experiments had only been carried out on small models.&lt;/p>
&lt;p>As for the fifth and sixth experiments, I would say they exist for the sake of rigor and to pad the list of novelties. The sixth in particular — claiming the existence of &amp;ldquo;space neurons&amp;rdquo; and &amp;ldquo;time neurons&amp;rdquo; — is hard to read as anything other than an attention-grabbing headline.&lt;/p>
&lt;p>Before diving in, a few terms are worth clarifying for the reader.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>What I call &amp;ldquo;&lt;strong>representation&lt;/strong>&amp;rdquo; corresponds to &amp;ldquo;representation&amp;rdquo; in the original paper. I believe the authors use the word to refer to the state of the LLM&amp;rsquo;s internal hidden layers. For example, the claim quoted above that &amp;ldquo;LLMs represent time and space linearly&amp;rdquo; corresponds, in the experiments, to the mapping from the LLM&amp;rsquo;s internal hidden state to the $label$ being linear.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>What I call an &amp;ldquo;&lt;strong>entity&lt;/strong>&amp;rdquo; corresponds to &amp;ldquo;entity&amp;rdquo; in the original paper. Here the word carries the sense of &amp;ldquo;sample&amp;rdquo; — one example from a dataset.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>What exactly is the somewhat mystical &amp;ldquo;&lt;strong>world model&lt;/strong>&amp;rdquo;? If an LLM only predicts the next token likely to follow a stretch of text, then no world model exists inside it. Conversely, if we can find evidence of structured storage of space and time inside the LLM, then we can say a world model does exist.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The authors&amp;rsquo; experiments center on &amp;ldquo;&lt;strong>probes&lt;/strong>&amp;rdquo; (&amp;ldquo;probe&amp;rdquo; in the original). Let the input be $X$, the model output $Y$, and the hidden state $h$. Train a shallow model using $h$ as the feature and $Y$ as the label; that shallow model is the probe.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&amp;ldquo;&lt;strong>Space-time&lt;/strong>&amp;rdquo; is shorthand for &amp;ldquo;space and time&amp;rdquo;. In the original paper, space appears as both &amp;ldquo;spatial&amp;rdquo; and &amp;ldquo;space&amp;rdquo;, and time as both &amp;ldquo;temporal&amp;rdquo; and &amp;ldquo;time&amp;rdquo;.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h1 id="paper-walkthrough">Paper Walkthrough&lt;/h1>
&lt;h2 id="abstract">Abstract&lt;/h2>
&lt;p>The rise of large language models (LLMs) has sparked a debate over whether such systems merely perform shallow statistics over massive corpora or genuinely learn a world model. Using Llama-2 as the subject, the authors run experiments on three spatial datasets and three temporal datasets and find evidence for the latter. They find that across model sizes, LLMs represent time and space linearly; that these representations are robust to prompt variations; that they generalize across entity types (for example, cities and landmarks); and they identify &amp;ldquo;space neurons&amp;rdquo; and &amp;ldquo;time neurons&amp;rdquo;.&lt;/p>
&lt;h2 id="motivation">Motivation&lt;/h2>
&lt;p>Although the arrival of LLMs has attracted attention from every quarter, our understanding of what happens inside them remains very limited. Whether an LLM&amp;rsquo;s operation amounts to statistics over massive data or to something like thinking has been contested since LLMs first appeared.&lt;/p>
&lt;p>In this paper, the authors attempt to address the question from the angle of space and time.&lt;/p>
&lt;h2 id="preliminaries">Preliminaries&lt;/h2>
&lt;h3 id="datasets">Datasets&lt;/h3>
&lt;p>The authors created six datasets: three spatial and three temporal. Every entity in each dataset consists of a name and a corresponding location or time. The three spatial datasets are built from place names in the world, the United States, and New York City. The three temporal datasets are built from historical figures, artworks, and news.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Dataset&lt;/th>
&lt;th>Examples&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>World&lt;/td>
&lt;td>Los Angeles, Saint Petersburg, the Caspian Sea&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>USA&lt;/td>
&lt;td>Fenway Park, Columbia, Riverside County (in California)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>NYC&lt;/td>
&lt;td>Borden Avenue Bridge, Trump International Hotel&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Figures&lt;/td>
&lt;td>Cleopatra, Dante Alighieri, Carl Sagan&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Artworks&lt;/td>
&lt;td>It, Bohemian Rhapsody&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>News&lt;/td>
&lt;td>omitted&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="model">Model&lt;/h3>
&lt;p>The Llama-2 family.&lt;/p>
&lt;h3 id="activation-datasets">Activation datasets&lt;/h3>
&lt;p>Suppose a dataset contains n entities and the LLM has a hidden dimension of $d_{model}$. Feeding the n entities through the LLM and recording the activations at a given hidden layer yields an &lt;strong>activation dataset&lt;/strong> $A\in\mathbb{R}^{n\times d_{model}}$.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/language-models-space-time/1.jpg" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;h3 id="probes">Probes&lt;/h3>
&lt;p>The authors feed place names, person names, and so on as the input $x$ to the model. Using the hidden state $h$ as the $feature$ and the $y$ corresponding to $x$ as the $label$, they train a probe and evaluate its performance on a test set.&lt;/p>
&lt;blockquote>
&lt;p>Understanding intermediate layers using linear classifier probes.
Probing classifiers: Promises, shortcomings, and advances.&lt;/p>
&lt;/blockquote>
&lt;h3 id="evaluation-metrics">Evaluation metrics&lt;/h3>
&lt;p>$R^2$ and Spearman rank correlation.&lt;/p>
&lt;h2 id="main-experiments-and-results">Main Experiments and Results&lt;/h2>
&lt;h3 id="1-do-llms-internally-represent-space-and-time-if-so-where--and-does-it-depend-on-model-size">1. Do LLMs internally represent space and time? If so, where — and does it depend on model size?&lt;/h3>
&lt;p>The authors train probes on the six activation datasets derived from their six self-built datasets, then evaluate them on held-out test sets, obtaining probe accuracy across LLM sizes, layer depths, and datasets.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/language-models-space-time/2.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>Five findings emerge from the figure above.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Both spatial and temporal features can be fit by a linear probe&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The larger the model, the higher the probe accuracy&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Accuracy rises smoothly over the first 50% of the layers&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Among the three spatial datasets, NYC performs worst. The authors speculate this is because the NYC map covers a small area and many of its place names are obscure, so the model simply does not know them&lt;/p>
&lt;/li>
&lt;li>
&lt;p>On the NYC map, the accuracy gap induced by model size is the most pronounced&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>To my mind, the steadily rising curve already shows that the model&amp;rsquo;s internal representation of spatio-temporal information has a certain structural regularity — enough for a probe to learn it. The fourth and fifth findings also lend indirect support to the possibility that a knowledge base or store exists inside the model. &lt;strong>If that possibility can be confirmed, LLMs might serve as a form of data compression.&lt;/strong>&lt;/p>
&lt;h3 id="2-is-the-llms-representation-of-spatio-temporal-information-linear">2. Is the LLM&amp;rsquo;s representation of spatio-temporal information linear?&lt;/h3>
&lt;p>Here the authors first hedge a little, spelling out how their work differs from earlier efforts. They note that while prior work has argued for the linear representation hypothesis inside neural networks, that work targeted discrete tasks such as binary or multi-class classification, whereas the labels in this paper&amp;rsquo;s task are continuous.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/language-models-space-time/3.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>The authors train both a simple linear probe and a nonlinear MLP probe and evaluate them on the test set; as the figure shows, the accuracy gap between the two is essentially nonexistent. For a mapping $f$, if it is linear, then both linear and nonlinear models can fit it well and the performance gap is small. If it is nonlinear, the linear model fits worse than the nonlinear one. The authors therefore conclude that the mapping from $h$ to $label$ is linear — which is what the paper means when it says &amp;ldquo;LLMs represent time and space linearly&amp;rdquo;.&lt;/p>
&lt;h3 id="3-sensitivity-to-the-prompt">3. Sensitivity to the prompt&lt;/h3>
&lt;p>This experiment was designed to test whether spatio-temporal representations are sensitive to changes in the prompt.&lt;/p>
&lt;p>For the five datasets other than news, the authors designed four prompts.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>empty: no additional prompt&lt;/p>
&lt;/li>
&lt;li>
&lt;p>coords/when: adding a descriptive, disambiguating prompt such as &amp;ldquo;What is the latitude and longitude of &amp;lt;place&amp;gt;&amp;rdquo; or &amp;ldquo;What was the release date of &amp;lt;author&amp;gt;&amp;rsquo;s &amp;lt;book&amp;gt;&amp;rdquo;&lt;/p>
&lt;/li>
&lt;li>
&lt;p>baseline: append 10 random tokens&lt;/p>
&lt;/li>
&lt;li>
&lt;p>all_cap: all uppercase&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>For the news dataset, the authors designed four prompts.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>empty prompt&lt;/p>
&lt;/li>
&lt;li>
&lt;p>add a period&lt;/p>
&lt;/li>
&lt;li>
&lt;p>add a descriptive, disambiguating prompt&lt;/p>
&lt;/li>
&lt;li>
&lt;p>add a descriptive, disambiguating prompt plus a period&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/language-models-space-time/4.png" alt="" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>Looking at the figure above, the authors observe the following.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>There is almost no accuracy difference between empty and the descriptive, disambiguating prompts&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Baseline accuracy is very low — random tokens degrade accuracy substantially&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Uppercasing also degrades accuracy, though this is unsurprising since earlier work has reported the same phenomenon&lt;/p>
&lt;/li>
&lt;li>
&lt;p>On the news dataset, adding a period improves accuracy substantially&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>Overall, spatio-temporal representations are fairly robust to the prompt.&lt;/p>
&lt;h3 id="limitations">Limitations&lt;/h3>
&lt;p>At the end of the paper the authors mention several limitations.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>A discrete encoder could be used to extract the model&amp;rsquo;s spatio-temporal representations&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The model does not recognize every entity in the datasets; in principle those should be filtered out&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h1 id="afterthoughts">Afterthoughts&lt;/h1>
&lt;p>My first reaction on finishing the paper was &amp;ldquo;is that all?&amp;rdquo; The contributions and novelty do stand out, but next to the &amp;ldquo;world model&amp;rdquo; the media made of it, the framing is hard not to call clickbait. That said, the clickbait was probably not the authors&amp;rsquo; intent — some outlets may simply have been chasing the hype.&lt;/p>
&lt;p>On contribution: collecting, building, and curating the datasets alone constitutes enough work for a top-tier conference paper, to say nothing of deploying probes on every layer of multiple LLMs. In sheer volume of work, it is far ahead of comparable papers. On novelty, the paper does not innovate much methodologically; it transplants techniques that were routine on small models onto large ones. And while the findings are not as mystical as the headline-chasers suggest, the discovery that LLMs represent space and time linearly is novel enough for a top-tier paper.&lt;/p>
&lt;p>On content, this is a textbook &amp;ldquo;experiment report&amp;rdquo;: no mathematical proofs, no derivations — just experiment design, execution, and analysis of results.&lt;/p>
&lt;p>On language, the word choice and writing are carefully done. As a Chinese reader I found it somewhat demanding, a very different experience from reading papers written by Chinese authors.&lt;/p>
&lt;p>All told, this is a paper comfortably above the bar for a top-tier conference, but it falls short of the &amp;ldquo;proof of a world model&amp;rdquo; that the headline-chasers advertised.&lt;/p></description></item><item><title>LLaMA Quantization Report (Part 2)</title><link>https://geyuyao.com/post/llama-quantization-part2-en/</link><pubDate>Fri, 11 Aug 2023 23:39:01 +0000</pubDate><guid>https://geyuyao.com/post/llama-quantization-part2-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/llama-quantization-part2/">中文&lt;/a>
&lt;/div>
&lt;h1 id="0-overview-of-the-task">0. Overview of the Task&lt;/h1>
&lt;ol>
&lt;li>Study the LLM.int8 method in depth&lt;/li>
&lt;/ol>
&lt;ul>
&lt;li>
&lt;p>Read &lt;a href="https://arxiv.org/pdf/2110.02861.pdf" target="_blank" rel="noopener">https://arxiv.org/pdf/2110.02861.pdf&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;del>Understand the emergent feature phenomenon &lt;a href="https://arxiv.org/pdf/2208.07339.pdf" target="_blank" rel="noopener">https://arxiv.org/pdf/2208.07339.pdf&lt;/a>&lt;/del>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;del>In the paper &amp;ldquo;LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale&amp;rdquo;, what exactly do int8 absmax and zeropoint mean?&lt;/del>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;del>Where did the author&amp;rsquo;s inspiration for this method come from?&lt;/del>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;del>Does the conjecture hold that &amp;ldquo;outliers&amp;rdquo; exist so that the model can extract features? If it does, how much accuracy would be lost by keeping only the outliers? Could one design a method that retains a certain fraction of the non-outliers, so as to balance the performance loss against the model&amp;rsquo;s demand for compute resources?&lt;/del>&lt;/p>
&lt;/li>
&lt;/ul>
&lt;ol>
&lt;li>What is the algorithm behind llama.cpp? &lt;a href="https://github.com/ggerganov/llama.cpp" target="_blank" rel="noopener">https://github.com/ggerganov/llama.cpp&lt;/a>&lt;/li>
&lt;/ol>
&lt;h1 id="8-bit-optimizers-via-block-wise-quantization">8-bit Optimizers via Block-wise Quantization&lt;/h1>
&lt;p>Author: &lt;a href="https://timdettmers.com/" target="_blank" rel="noopener">Tim Dettmers&lt;/a>&lt;/p>
&lt;p>A method for quantizing the optimizer: without changing any hyperparameters or hurting model accuracy, it quantizes the Adam / momentum state to int8, thereby easing GPU memory pressure during training.&lt;/p>
&lt;p>Not closely related to this project.&lt;/p>
&lt;h1 id="llmint8-8-bit-matrix-multiplication-for-transformers-at-scale">LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale&lt;/h1>
&lt;p>Author: &lt;a href="https://timdettmers.com/" target="_blank" rel="noopener">Tim Dettmers&lt;/a>&lt;/p>
&lt;h2 id="0-background">0. Background&lt;/h2>
&lt;h3 id="absmax-quantization">&lt;strong>Absmax quantization:&lt;/strong>&lt;/h3>
&lt;p>The simplest quantization scheme, taking fp16$\rightarrow$int8.&lt;/p>
&lt;p>In short, it maps fp16 values onto int8 integers in [-127, 127].&lt;/p>
&lt;p>For example, given the fp16 vector [-100, 0, 50, 100], absmax quantization maps 100 to 127, 50 to 63.5, 0 to 0, and -100 to -98.73.&lt;/p>
&lt;p>The trouble is that &lt;strong>if the vector contains large-valued outliers, the other values get wiped out by the quantization.&lt;/strong>&lt;/p>
&lt;p>For instance, take the vector [-0.10, -0.23, 0.08, -0.38, -0.28, -0.29, -2.11, 0.34, -0.53, -67.0]. After int8 quantization and dequantization it becomes [ -0.00, -0.00, 0.00, -0.53, -0.53, -0.53, -2.11, 0.53, -0.53, -67.00] — clearly most of the information has been lost.&lt;/p>
&lt;h3 id="zeropoint-quantization">&lt;strong>Zeropoint quantization:&lt;/strong>&lt;/h3>
&lt;p>The idea is similar to absmax; the difference is that absmax is symmetric while this method is asymmetric.&lt;/p>
&lt;p>Taking the vector [-100, 0, 50, 100] as an example, zeropoint quantization maps 100 to 127, 50 to 63.5, 0 to 0, and -100 to -127.&lt;/p>
&lt;p>The two methods are equivalent in &lt;strong>approach&lt;/strong>, &lt;strong>performance&lt;/strong>, and &lt;strong>accuracy&lt;/strong>, and &lt;strong>neither solves the outlier problem&lt;/strong>.&lt;/p>
&lt;h3 id="llmint8">LLM.int8:&lt;/h3>
&lt;p>The author first tried quantizing models with both of the methods above, but accuracy dropped severely, so he set out to find an approach that preserves accuracy while still reducing memory usage.&lt;/p>
&lt;blockquote>
&lt;p>Through experiments the author found that the matrix $\textbf{X}_{f16}\in\mathbb{R}^{s\times h}$ contains outliers, and that while these outliers occur across all of the sequence dimension s, their distribution along the feature/hidden dimension h follows a clear pattern.&lt;/p>
&lt;/blockquote>
&lt;p>Based on &lt;a href="https://flowus.cn/61f7e285-74d6-4ff9-bb9f-15b38feabb58#80ff2cef-177a-4b6a-ba0c-57991f54c07c" target="_blank" rel="noopener">this observation&lt;/a>, the author had the idea of separating out the dimensions that contain outliers and computing them in fp16, while computing the remaining dimensions in int8.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part2/1.png" alt="1.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>&lt;strong>How outliers are defined:&lt;/strong>&lt;/p>
&lt;p>The author sets a threshold $\alpha$; any value exceeding $\alpha$ is defined as an outlier, and any dimension containing an outlier must be computed in fp16. Experimentally, the author found that setting $\alpha$ to 6 or above keeps accuracy from degrading.
With $\alpha$ set to 6, 99.9% of the dimensions are quantized to int8, while the remaining 0.1% that contain outliers are left unquantized. For a 13B model, no more than 7 dimensions contain outliers. Splitting the matrix costs an extra 0.1% of storage.&lt;/p>
&lt;h2 id="1-emergent-feature">1. Emergent Feature&lt;/h2>
&lt;h3 id="definition">Definition:&lt;/h3>
&lt;p>The original text reads: &amp;ldquo;&lt;em>Emergence is a gradual change in a property that suddenly undergoes a phase shift and then changes the quality of its substrate.&lt;/em>&amp;rdquo; In plain terms, the transformer changes gradually, then abruptly undergoes a phase shift, after which a qualitative change takes place — quantitative change leading to qualitative change. What changes over the course of this process is the model&amp;rsquo;s parameter count.&lt;/p>
&lt;h3 id="findings">Findings:&lt;/h3>
&lt;p>Before explaining this process, the author introduces two things that happen in parallel inside a transformer: the network gradually extracts features, and at the same time it strips away noisy, context-irrelevant ones. An example makes this concrete. To classify cats and dogs, you can apply sharpening, which both accentuates the features that differ between the two animals (eyes, ears) and removes the features they share (color, underlying texture). The transformer works on the same principle. During inference, &lt;strong>the transformer discards 99% of the useless information and retains only the 1% that is useful.&lt;/strong>&lt;/p>
&lt;p>Before the &lt;strong>qualitative change&lt;/strong>, different layers use &lt;strong>different dimensions&lt;/strong> to accentuate the important features. After the &lt;strong>qualitative change&lt;/strong>, all layers use &lt;strong>the same six dimensions&lt;/strong> to do so.&lt;/p>
&lt;p>In summary:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Below 6.7B parameters, outliers are scattered across different dimensions in individual layers with no discernible pattern.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>At 6.7B parameters, the outliers&amp;rsquo; &lt;strong>values jump sharply&lt;/strong> and they &lt;strong>suddenly appear in all layers&lt;/strong>, and only &lt;strong>in the same six dimensions&lt;/strong>. This also explains why earlier quantization methods do not carry over to LLMs: from 6.7B onward there are large numbers of outliers, and earlier methods cannot handle them well.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Values jump sharply&lt;/strong>: the maximum is 15 at 6B, 60 at 13B, and 95 at 66B.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Suddenly appear in all layers&lt;/strong>: below 6.7B, different layers use different dimensions to amplify features. Above 6.7B, all layers work together to amplify them.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Only in the same six dimensions&lt;/strong>: this means attention has become concentrated.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part2/2.png" alt="2" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
The x-axis is the model&amp;rsquo;s parameter count and the y-axis is the percentage of layers affected by outliers.
The figure shows that below 6.7B parameters, outliers appear in only some of the layers.
Once the parameter count reaches 6.7B, a qualitative change occurs and they appear in almost every layer.&lt;/p>
&lt;h2 id="2-reflections">2. Reflections&lt;/h2>
&lt;ol>
&lt;li>Does the emergent feature depend only on the parameter count?
No — it is also related to perplexity (ppl).&lt;/li>
&lt;/ol>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part2/3.png" alt="3" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
The left panel shows the emergent feature against parameter count, where the qualitative change is visible.
The right panel shows it against ppl, where the growth is monotonically exponential.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part2/4.png" alt="4" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
The left panel shows the median outlier value against ppl; the median rises sharply when emergence occurs.
The right panel shows the number of outliers against ppl; as ppl decreases, the number of outliers grows.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Why do ordinary quantization methods, such as zeropoint and absmax in the int8 family, fail on LLMs?
Because as the parameter count grows so does the number of outliers, and ordinary quantization methods suffer severe accuracy loss whenever they encounter outliers.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>To summarize the phenomena that accompany the qualitative change:&lt;/p>
&lt;/li>
&lt;/ol>
&lt;ul>
&lt;li>
&lt;p>Outliers appear in all layers&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Outliers are distributed regularly across a handful of dimensions&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Outlier values rise sharply&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The number of outliers also increases&lt;/p>
&lt;/li>
&lt;/ul>
&lt;ol start="3">
&lt;li>Can the dimensions other than the outliers be removed?
No. The author notes in his blog that removing 95% of the parameters of a vision model does not seriously hurt accuracy, but for NLP transformers that figure drops to 30%, and once emergence has occurred it drops to 5%.&lt;/li>
&lt;/ol></description></item><item><title>LLaMA Quantization Report (Part 1)</title><link>https://geyuyao.com/post/llama-quantization-part1-en/</link><pubDate>Fri, 04 Aug 2023 21:12:03 +0000</pubDate><guid>https://geyuyao.com/post/llama-quantization-part1-en/</guid><description>
&lt;div class="travel-langswitch" role="group" aria-label="Language">
&lt;span class="travel-langswitch__btn is-active" aria-current="true">English&lt;/span>
&lt;a class="travel-langswitch__btn" href="https://geyuyao.com/post/llama-quantization-part1/">中文&lt;/a>
&lt;/div>
&lt;h2 id="0-overview-of-the-task">0. Overview of the Task&lt;/h2>
&lt;p>The full task list:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Survey existing LLMs and the background needed to quantize LLaMA-based models&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Survey the available quantization tooling&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Run comparative quantization experiments: quality and performance&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Evaluate the experiments: quality (human? automated? &amp;hellip;) and performance (speed, GPU memory before quantization -&amp;gt; after quantization)&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Summarize and draw conclusions&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>What this article covers:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Survey existing LLMs and the background needed to quantize LLaMA-based models&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Survey the available quantization tooling&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="1-the-current-llm-landscape">1. The Current LLM Landscape&lt;/h2>
&lt;p>The dominant way of building on LLMs today is &lt;strong>foundation model + prompt engineering&lt;/strong>: the big internet companies open-source the former, while developers tailor the latter to their own business scenarios.&lt;/p>
&lt;p>Among the mainstream foundation models is the &lt;strong>LLaMA&lt;/strong> family released by &lt;strong>Meta&lt;/strong>.&lt;/p>
&lt;p>The LLaMA series comes in four sizes: 7B, 13B, 33B, and 65B.&lt;/p>
&lt;p>This project uses LLaMA 33B as its base model.&lt;/p>
&lt;h2 id="2-background-on-quantization">2. Background on Quantization&lt;/h2>
&lt;p>Q1. What is quantization?&lt;/p>
&lt;p>Quantization is the process of approximating the continuous values of a signal with a finite set of discrete values. It is a form of model compression.&lt;/p>
&lt;p>Q2. Why quantize?&lt;/p>
&lt;p>Serving these models consumes a great deal of GPU memory, and under high concurrency the service may crash outright. Quantizing the model saves both memory and bandwidth.&lt;/p>
&lt;p>Q3. What kinds of quantization are there?&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Binarization&lt;/strong> uses bitwise operations to achieve parallel computation.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Logarithmic quantization&lt;/strong> has no acceleration library implemented on any of the three major platforms, presumably because the speedup it delivers is not significant. Only some special-purpose chips make use of it.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Linear quantization&lt;/strong> uses uniformly distributed cluster centers, so that a simple linear transformation relates the original floating-point data to the quantized fixed-point data. It is the most widely used approach. Song Han&amp;rsquo;s best-paper work at ICLR 2016, for example, was the first to propose parameter quantization: a clustering algorithm groups nearby values into a single class so that they can all reuse one value.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>None of the three approaches above, however, seems applicable to LLMs.&lt;/p>
&lt;h2 id="3-quantization-methods">3. Quantization Methods&lt;/h2>
&lt;h3 id="1-llmint8">1. LLM.int8&lt;/h3>
&lt;p>Proposed in 2022 by Tim Dettmers, a PhD student at the University of Washington.&lt;/p>
&lt;p>Paper: &lt;a href="https://arxiv.org/pdf/2208.07339.pdf" target="_blank" rel="noopener">https://arxiv.org/pdf/2208.07339.pdf&lt;/a>&lt;/p>
&lt;p>GitHub: &lt;a href="https://github.com/timdettmers/bitsandbytes" target="_blank" rel="noopener">https://github.com/timdettmers/bitsandbytes&lt;/a>&lt;/p>
&lt;h4 id="1-introduction-to-int8">(1) Introduction to int8&lt;/h4>
&lt;p>Before getting to LLM.int8, we need to understand plain int8 quantization.
The core idea of int8 quantization is to map FP16 floating-point numbers into the 8-bit integer range, i.e. [-127, 127].
Suppose we want to quantize the vector $\mathbf{x} : [1.2, -0.5, -4.3, 1.2, -3.1, 0.8, 2.4, 5.4]$. We first find its maximum, $max(\mathbf{x}) = 5.4$, and then compute the quantization coefficient $\alpha = 127/5.4 = 23.5$. Multiplying every element of the vector by $\alpha$ gives the quantized vector $\mathbf{x&amp;rsquo;} : [28, -12, -101, 28, -73, 19, 56, 127]$.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part1/1.jpg" alt="1.jpg" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>&lt;a href="https://flowus.cn/737727b2-9344-4972-8073-c40202e3bab4#54618e2f-6b4e-4946-a2be-685a44a66955" target="_blank" rel="noopener">The section above&lt;/a> explains how to quantize a single int8 vector, but the method breaks down as soon as the vector contains &lt;strong>outliers (emergent features)&lt;/strong>. For instance, take the vector [-0.10, -0.23, 0.08, -0.38, -0.28, -0.29, -2.11, 0.34, -0.53, -67.0]. After int8 quantization and dequantization it becomes [ -0.00, -0.00, 0.00, -0.53, -0.53, -0.53, -2.11, 0.53, -0.53, -67.00] — clearly most of the information has been destroyed. &lt;strong>Applying int8 quantization directly to a model therefore degrades its accuracy.&lt;/strong>&lt;/p>
&lt;h4 id="2-introduction-to-llmint8">(2) Introduction to LLM.int8&lt;/h4>
&lt;p>Through experiments, the author observed the following phenomenon (this passage draws on &lt;a href="https://zhuanlan.zhihu.com/p/624855002" target="_blank" rel="noopener">Strong&lt;/a>&amp;rsquo;s article on Zhihu) and proposed a mixed-precision quantization method, LLM.int8.&lt;/p>
&lt;blockquote>
&lt;p>Outliers appear in virtually every layer, and applying int8 quantization blindly causes a severe accuracy drop. The good news is that these outliers are distributed in a regular pattern. If a 6.7B transformer model has 150,000 outliers per sequence, they will occur in only six feature dimensions (six distinct values of i in X[:, :, i]).&lt;/p>
&lt;/blockquote>
&lt;p>Building on &lt;a href="https://flowus.cn/737727b2-9344-4972-8073-c40202e3bab4#8984e294-6096-40e5-9daa-b427162f3391" target="_blank" rel="noopener">this observation&lt;/a>, the author proposed LLM.int8: &lt;strong>separate the few dimensions that contain outliers out of the matrix, compute their matrix product in high precision, and quantize everything else.&lt;/strong> By the author&amp;rsquo;s account, 99.9% of the dimensions can be handled in int8, while the remaining 0.1% require fp16 multiplication.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part1/2.png" alt="2.jpg" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>The highlighted parts are the outliers; they are left unquantized and computed in fp16. The non-outlier parts are quantized with int8. They are scaled by the row-wise and column-wise absolute maxima $C_x$ and $C_w$, the outputs are quantized to Int8, an 8-bit matrix multiplication is performed, and the result is then dequantized.&lt;/p>
&lt;h4 id="3-accuracy-and-efficiency-of-llmint8">(3) Accuracy and Efficiency of LLM.int8&lt;/h4>
&lt;p>&lt;strong>On accuracy:&lt;/strong>&lt;/p>
&lt;p>As shown below, the author experimented with different quantization schemes on models of 125M, 1.3B, 2.7B, 6.7B, and 13B parameters, and evaluated the &lt;strong>perplexity&lt;/strong> of each model before and after quantization. &lt;strong>Lower perplexity is better.&lt;/strong>&lt;/p>
&lt;p>Both the symmetric and asymmetric variants of conventional quantization suffer large accuracy drops; compared with the other schemes, models quantized with LLM.int8 lose very little accuracy and are almost on par with fp32.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part1/3.png" alt="3.jpg" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>Note that once the model grows past a critical size, the accuracy of conventional int8 falls off sharply, whereas LLM.int8 barely degrades at all.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part1/4.png" alt="4.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>&lt;strong>On speed:&lt;/strong>&lt;/p>
&lt;p>There are currently two sources of speed measurements: the author&amp;rsquo;s blog and the paper.&lt;/p>
&lt;p>&lt;strong>From the blog:&lt;/strong>&lt;/p>
&lt;p>The author compares per-token latency (ms) across model sizes. The experiments show that &lt;strong>BLOOM-176B with LLM.int8 is 15% to 23% slower than the fp16 version&lt;/strong>; see the figure below for details. For the smaller models the slowdown is several times worse.&lt;/p>
&lt;p>The author mentions that within a single day he cut the per-token inference latency of T5-3B (bottom row, fourth column from the left) from 312 ms to 173 ms. In other words, the latency in this figure comes mainly from the algorithm, and the team was still optimizing it at the time.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part1/5.png" alt="5" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
The three models are BLOOM-176B, T5-11B, and T5-3B.&lt;/p>
&lt;p>&lt;strong>From the paper:&lt;/strong>&lt;/p>
&lt;p>Speed of the 16-bit matrix multiplication in the first hidden layer relative to the baseline, for models of different sizes. Anything below 1.0x is a slowdown.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part1/6.png" alt="6" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
Experiments were conducted on GPT-3&lt;/p>
&lt;p>The two sets of measurements agree on some points and disagree on others. &lt;strong>Where they agree:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Both int8 quantization and LLM.int8 favor larger models in terms of speed&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Where they differ:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Under the per-token measurement, LLM.int8 is slower than fp16. Under the 16-bit hidden-layer matrix multiplication measurement, inference on small models slows down noticeably while inference on large models speeds up.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>On GPU memory&lt;/strong>&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part1/7.png" alt="7" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
The 8-bit method in this paper makes many previously inaccessible models accessible, in particular OPT-175B/BLOOM&lt;/p>
&lt;h4 id="4-practice">(4) Practice&lt;/h4>
&lt;p>Using the third-party &lt;code>Linear8bitLt&lt;/code> class:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Python" data-lang="Python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">torch&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">torch.nn&lt;/span> &lt;span class="k">as&lt;/span> &lt;span class="nn">nn&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">bitsandbytes&lt;/span> &lt;span class="k">as&lt;/span> &lt;span class="nn">bnb&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">bnb.nn&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Linear8bitLt&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Python" data-lang="Python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">fp16_model&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">nn&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">Sequential&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">nn&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">Linear&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">64&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">64&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">nn&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">Linear&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">64&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">64&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Python" data-lang="Python">&lt;span class="line">&lt;span class="cl">&lt;span class="p">[&lt;/span>&lt;span class="o">...&lt;/span> &lt;span class="n">train&lt;/span> &lt;span class="n">the&lt;/span> &lt;span class="n">model&lt;/span> &lt;span class="o">...&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">torch&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">fp16_model&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">state_dict&lt;/span>&lt;span class="p">(),&lt;/span> &lt;span class="s2">&amp;#34;model.pt&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Python" data-lang="Python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">int8_model&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">nn&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">Sequential&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">Linear8bitLt&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">64&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">64&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">has_fp16_weights&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">False&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">Linear8bitLt&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">64&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">64&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">has_fp16_weights&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">False&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># The has_fp16_weights flag matters a great deal here. It defaults to True, which enables Int8/FP16 mixed precision during training. For inference, however, we care more about saving memory, so we need has_fp16_weights=False.&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Python" data-lang="Python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">int8_model&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">load_state_dict&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">torch&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">load&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;model.pt&amp;#34;&lt;/span>&lt;span class="p">))&lt;/span> &lt;span class="c1"># not quantized yet at this point&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">int8_model&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">int8_model&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">to&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="c1"># quantization happens here&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># quantization only takes place once the model is moved onto the GPU&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Python" data-lang="Python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">input_&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">torch&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">randn&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">64&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">dtype&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">torch&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">float16&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">hidden_states&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">int8_model&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">input_&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">to&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">torch&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">device&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;cuda&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">0&lt;/span>&lt;span class="p">)))&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Beyond this basic usage, the author also provides sample code targeting LLaMA models.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Python" data-lang="Python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">torch&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">transformers&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">AutoModelForCausalLM&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">AutoTokenizer&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># maximum length of the generated text&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">MAX_NEW_TOKENS&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">128&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># name of the pretrained model to use&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">model_name&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s1">&amp;#39;decapoda-research/llama-7b-hf&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># the text to process&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">text&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s1">&amp;#39;Hamburg is in which country?&lt;/span>&lt;span class="se">\n&lt;/span>&lt;span class="s1">&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># turn the text into the input format the model expects (input_ids is the integer sequence the model consumes)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">tokenizer&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">AutoTokenizer&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">from_pretrained&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">model_name&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">input_ids&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">tokenizer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">text&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">return_tensors&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;pt&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">input_ids&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># GPU-related settings&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">free_in_GB&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="nb">int&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">torch&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">cuda&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">mem_get_info&lt;/span>&lt;span class="p">()[&lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="mi">1024&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="mi">3&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">max_memory&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="sa">f&lt;/span>&lt;span class="s1">&amp;#39;&lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="nb">int&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">torch&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">cuda&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">mem_get_info&lt;/span>&lt;span class="p">()[&lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="mi">1024&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="mi">3&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s1">GB&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">n_gpus&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">torch&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">cuda&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">device_count&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">max_memory&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">max_memory&lt;/span> &lt;span class="k">for&lt;/span> &lt;span class="n">i&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="nb">range&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">n_gpus&lt;/span>&lt;span class="p">)}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># load_in_8bit=True loads the model at 8-bit precision to reduce memory usage&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">model&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">AutoModelForCausalLM&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">from_pretrained&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">model_name&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">device_map&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;auto&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">load_in_8bit&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">True&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">max_memory&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">max_memory&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">generated_ids&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">model&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">generate&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">input_ids&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">max_length&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">MAX_NEW_TOKENS&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">tokenizer&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">decode&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">generated_ids&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="n">skip_special_tokens&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">True&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="5-qa">(5) Q&amp;amp;A&lt;/h4>
&lt;ol>
&lt;li>&lt;strong>Why does inference get slower after quantization?&lt;/strong>&lt;/li>
&lt;/ol>
&lt;p>Quantization requires splitting the matrix apart, and that extra work slows inference down.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Why do small models slow down more?&lt;/strong>&lt;/li>
&lt;/ol>
&lt;p>The author has identified the &lt;a href="https://github.com/TimDettmers/bitsandbytes/issues/6" target="_blank" rel="noopener">cause&lt;/a>: it comes down to the CUDA kernels. In short, int8 cannot saturate the GPU, so it runs at the same speed as fp16, while the extra overhead introduced by quantization drags inference down. In theory a 6B model should see a 20–40% speedup. The author cannot estimate the cost of that overhead, which is more complicated and depends on sequence length and batch size.&lt;/p>
&lt;p>Six months ago the author said that speed would improve in later releases.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>What is the relationship between the number of outliers and time/space complexity?&lt;/strong>&lt;/li>
&lt;/ol>
&lt;p>Several of the author&amp;rsquo;s findings bear on this question, but as noted in question 2 the author himself has not fully worked out the overhead issue.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>The emergence of outliers is not sudden but gradual, and it is exponentially related to &lt;strong>perplexity&lt;/strong> rather than to model size.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>After the phase shift occurs, outliers start to grow rapidly.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>&amp;ldquo;Phase shift&amp;rdquo; means that outliers suddenly appear in all layers and begin to coordinate with one another.&lt;/p>
&lt;/blockquote>
&lt;h4 id="6-summary">(6) Summary&lt;/h4>
&lt;p>The method is fairly new, easy to use, essentially lossless in accuracy, and effective at reducing GPU memory. Whether &lt;strong>its runtime speed falls within an acceptable range, however, still needs to be verified experimentally.&lt;/strong>&lt;/p>
&lt;h4 id="7-references">(7) References&lt;/h4>
&lt;ol>
&lt;li>
&lt;p>Blog post by the author, Tim Dettmers: &lt;a href="https://timdettmers.com/2022/08/17/llm-int8-and-emergent-features/" target="_blank" rel="noopener">https://timdettmers.com/2022/08/17/llm-int8-and-emergent-features/&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Blog post by Younes Belkada: &lt;a href="https://huggingface.co/blog/zh/hf-bitsandbytes-integration" target="_blank" rel="noopener">https://huggingface.co/blog/zh/hf-bitsandbytes-integration&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Video by Bilibili creator &lt;a href="https://space.bilibili.com/602175518" target="_blank" rel="noopener">米粒方糖&lt;/a>: &lt;a href="https://www.bilibili.com/video/BV1Tx4y1d7sG/?spm_id_from=333.880.my_history.page.click&amp;amp;vd_source=3a72dc49e723efef59bcf133fb8fe42e" target="_blank" rel="noopener">https://www.bilibili.com/video/BV1Tx4y1d7sG/?spm_id_from=333.880.my_history.page.click&amp;amp;vd_source=3a72dc49e723efef59bcf133fb8fe42e&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The original paper: &lt;a href="https://arxiv.org/pdf/2208.07339.pdf" target="_blank" rel="noopener">https://arxiv.org/pdf/2208.07339.pdf&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h3 id="2-gptq-quantization-work-in-progress">2. GPTQ Quantization (work in progress)&lt;/h3>
&lt;p>Only 20 GB of GPU memory is needed to run LLaMA 33B.&lt;/p>
&lt;p>Proposed by Elias Frantar of the Institute of Science and Technology Austria. The paper was published at ICLR 2023.&lt;/p>
&lt;p>Paper: &lt;a href="https://arxiv.org/pdf/2210.17323.pdf" target="_blank" rel="noopener">https://arxiv.org/pdf/2210.17323.pdf&lt;/a>&lt;/p>
&lt;p>GitHub (LLaMA version): &lt;a href="https://github.com/qwopqwop200/GPTQ-for-LLaMa" target="_blank" rel="noopener">https://github.com/qwopqwop200/GPTQ-for-LLaMa&lt;/a>&lt;/p>
&lt;h4 id="1-the-method">(1) The Method&lt;/h4>
&lt;p>The lineage runs from OBD to OBS to OBQ and finally to GPTQ.&lt;/p>
&lt;p>To be completed.&lt;/p>
&lt;h4 id="2-performance-on-llama-33b">(2) Performance on LLaMA 33B&lt;/h4>
&lt;p>Experiments were run on an A100.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://geyuyao.com/post/llama-quantization-part1/8.png" alt="8.png" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;h4 id="3-usage">(3) Usage&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Plain" data-lang="Plain">&lt;span class="line">&lt;span class="cl">python llama.py LLAMA_HF_FOLDER c4 --wbits 4 --true-sequential --act-order --new-eval
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="4-differences-from-llmint8">(4) Differences from LLM.int8&lt;/h4>
&lt;p>GPTQ quantizes an fp16 model directly into 4-bit format. LLM.int8, by contrast, reads fp16 weights and &lt;a href="https://flowus.cn/737727b2-9344-4972-8073-c40202e3bab4#0b2da9fa-7c71-46fe-91e6-9bbe7a4da4dd" target="_blank" rel="noopener">loads them into Linear8bitLt layers&lt;/a>, with quantization happening when the model is moved to the GPU.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">int8_model&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">load_state_dict&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">torch&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">load&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;model.pt&amp;#34;&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">int8_model&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">int8_model&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">to&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="c1"># quantization happens here&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="5-todo">5. TODO&lt;/h2>
&lt;ol>
&lt;li>Study the LLM.int8 method in depth&lt;/li>
&lt;/ol>
&lt;ul>
&lt;li>
&lt;p>Read &lt;a href="https://arxiv.org/pdf/2110.02861.pdf" target="_blank" rel="noopener">https://arxiv.org/pdf/2110.02861.pdf&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Understand the emergent feature phenomenon &lt;a href="https://arxiv.org/pdf/2208.07339.pdf" target="_blank" rel="noopener">https://arxiv.org/pdf/2208.07339.pdf&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>In the paper &amp;ldquo;LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale&amp;rdquo;, what exactly do int8 absmax and zeropoint mean?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Where did the author&amp;rsquo;s inspiration for this method come from?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Does the conjecture hold that &amp;ldquo;outliers&amp;rdquo; exist so that the model can extract features? If it does, how much accuracy would be lost by keeping only the outliers? Could one design a method that retains a certain fraction of the non-outliers, so as to balance the performance loss against the model&amp;rsquo;s demand for compute resources?&lt;/p>
&lt;/li>
&lt;/ul>
&lt;ol>
&lt;li>
&lt;p>What is the algorithm behind llama.cpp? &lt;a href="https://github.com/ggerganov/llama.cpp" target="_blank" rel="noopener">https://github.com/ggerganov/llama.cpp&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Flesh out the explanation of how GPTQ works by reading the original paper and blog posts. From Zhihu &amp;amp; arXiv&lt;/p>
&lt;/li>
&lt;/ol>
&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://arxiv.org/pdf/2210.17323.pdf" target="_blank" rel="noopener">https://arxiv.org/pdf/2210.17323.pdf&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://zhuanlan.zhihu.com/p/625701227" target="_blank" rel="noopener">https://zhuanlan.zhihu.com/p/625701227&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://zhuanlan.zhihu.com/p/616969812" target="_blank" rel="noopener">https://zhuanlan.zhihu.com/p/616969812&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://zhuanlan.zhihu.com/p/623047485" target="_blank" rel="noopener">https://zhuanlan.zhihu.com/p/623047485&lt;/a>&lt;/p>
&lt;/li>
&lt;/ul>
&lt;ol>
&lt;li>Learn how to use GPTQ &amp;amp; LLM.int8 from others&amp;rsquo; experience. From YouTube&lt;/li>
&lt;/ol>
&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://www.youtube.com/watch?v=mii-xFaPCrA" target="_blank" rel="noopener">https://www.youtube.com/watch?v=mii-xFaPCrA&lt;/a> GPTQ&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://www.youtube.com/watch?v=p9_pbJwvEL8" target="_blank" rel="noopener">https://www.youtube.com/watch?v=p9_pbJwvEL8&lt;/a> GPTQ 33B&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://www.youtube.com/watch?v=SvfZO47ShoU" target="_blank" rel="noopener">https://www.youtube.com/watch?v=SvfZO47ShoU&lt;/a> GPTQ&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://www.youtube.com/watch?v=bTzM45kaK44" target="_blank" rel="noopener">https://www.youtube.com/watch?v=bTzM45kaK44&lt;/a> LLM.int8&lt;/p>
&lt;/li>
&lt;/ul></description></item></channel></rss>