Commit e4152378 by wangchenglong

update.

parent 11a34d21
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,6 +3,23 @@ ...@@ -3,6 +3,23 @@
@inproceedings{guo-etal:connecting,
title={Connecting large language models with evolutionary algorithms yields powerful prompt optimizers},
author={Guo, Qingyan and Wang, Rui and Guo, Junliang and Li, Bei and Song, Kaitao and Tan, Xu and Liu, Guoqing and Bian, Jiang and Yang, Yujiu},
booktitle={International Conference on Learning Representations},
volume={2024},
pages={34133--34156},
year={2024}
}
@inproceedings{deng-etal:rlprompt,
title={Rlprompt: Optimizing discrete text prompts with reinforcement learning},
author={Deng, Mingkai and Wang, Jianyu and Hsieh, Cheng-Ping and Wang, Yihan and Guo, Han and Shu, Tianmin and Song, Meng and Xing, Eric and Hu, Zhiting},
booktitle={Proceedings of the 2022 conference on empirical methods in natural language processing},
pages={3369--3391},
year={2022}
}
@article{holtzman-etal:curious, @article{holtzman-etal:curious,
title={The curious case of neural text degeneration}, title={The curious case of neural text degeneration},
......
\begin{tikzpicture}[
x=1cm,
y=1cm,
font=\small,
line/.style={
draw=black,
line width=0.55pt
},
arrow/.style={
line,
-{Stealth[length=2.1mm,width=1.5mm]}
},
feedback/.style={
draw=black!45,
line width=0.5pt,
dashed,
opacity=0.45,
-{Stealth[length=1.8mm,width=1.3mm]}
},
box/.style={
draw=black,
line width=0.55pt,
sharp corners,
align=center,
inner sep=5pt,
outer sep=0pt
},
token/.style={
box,
minimum width=0.72cm,
minimum height=0.48cm
},
distribution/.style={
fill=white,
align=center,
inner sep=3pt,
outer sep=0pt,
font=\scriptsize
},
toptext/.style={
anchor=west,
align=left,
inner sep=0pt,
font=\small
},
topformula/.style={
anchor=west,
align=left,
inner sep=0pt,
font=\small
}
]
% ============================================================
% Colors
% ============================================================
\definecolor{tokenblue}{RGB}{230,239,250}
\definecolor{tokenyellow}{RGB}{252,239,208}
\definecolor{tokengreen}{RGB}{229,241,224}
% ============================================================
% Divider
% ============================================================
\draw[dashed,gray!65,line width=0.65pt]
(0,-0.55) -- (0,6.40);
% ============================================================
% LEFT: LANGUAGE MODEL TRAINING
% ============================================================
\begin{scope}[xshift=-4.10cm]
% Left-aligned explanation and objective
\node[toptext] at (-3.50,6.00)
{Minimizing the next-token prediction loss: \\ $\mathcal{L}_{\mathrm{LM}} =-\sum_{i=1}^{N} \log \mathrm{Pr}_{\theta}(z_i\mid\mathbf{z}_{<i})$};
% ------------------------------------------------------------
% Language model
% ------------------------------------------------------------
\node[
box,
minimum width=7.0cm,
minimum height=0.78cm,
font=\normalsize
] (llmL) at (0,2.00)
{Large Language Model};
% ------------------------------------------------------------
% Input tokens: begin with z_1, not BOS
% ------------------------------------------------------------
\node[token,fill=tokenblue]
(lz1) at (-2.60,0.90) {$z_1$};
\node[token,fill=tokenblue]
(lz2) at (-0.65,0.90) {$z_2$};
\node at (0.85,0.90) {$\cdots$};
\node[token,fill=tokenblue,minimum width=0.95cm]
(lzN) at (2.40,0.90) {$z_{N-1}$};
\foreach \n in {lz1,lz2,lzN}{
\draw[arrow]
(\n.north) -- (\n.north |- llmL.south);
}
% ------------------------------------------------------------
% Predicted distributions
% ------------------------------------------------------------
\node[distribution] (lp2) at (-2.60,3.05)
{$\mathrm{Pr}_{\theta}(\cdot\mid z_1)$};
\node[distribution] (lp3) at (-0.65,3.05)
{$\mathrm{Pr}_{\theta}(\cdot\mid\mathbf{z}_{<3})$};
\node at (0.85,3.05) {$\cdots$};
\node[distribution] (lpN) at (2.40,3.05)
{$\mathrm{Pr}_{\theta}(\cdot\mid\mathbf{z}_{<N})$};
\foreach \n in {lp2,lp3,lpN}{
\draw[arrow]
(llmL.north -| \n.south) -- (\n.south);
}
% ------------------------------------------------------------
% Ground-truth next tokens
% ------------------------------------------------------------
\node[token,fill=tokenblue]
(target2) at (-2.60,4.65) {$z_2$};
\node[token,fill=tokenblue]
(target3) at (-0.65,4.65) {$z_3$};
\node at (0.85,4.65) {$\cdots$};
\node[token,fill=tokenblue]
(targetN) at (2.40,4.65) {$z_N$};
% Cross-entropy comparison
\foreach \p/\q/\name in {
lp2/target2/ce2,
lp3/target3/ce3,
lpN/targetN/ceN
}{
\node[
box,
fill=white,
minimum width=0.62cm,
minimum height=0.34cm,
inner sep=2pt,
font=\scriptsize
] (\name) at ($(\p.center)!0.55!(\q.center)$)
{CE};
\draw[arrow] (\p.north) -- (\name.south);
\draw[arrow] (\q.south) -- (\name.north);
}
% ------------------------------------------------------------
% Bottom annotations
% ------------------------------------------------------------
\draw[
decorate,
decoration={brace,mirror,amplitude=4pt},
line width=0.7pt
]
(-3.02,0.46) -- (2.93,0.46);
\node[font=\scriptsize] at (0,0.04)
{Observed token sequence};
\node[font=\scriptsize,text=black!65] at (0,-0.35)
{CE: cross-entropy with the observed target};
\node[align=center] at (0,-0.90)
{\textbf{(a)} Next-token prediction during training};
\end{scope}
% ============================================================
% RIGHT: MULTI-STEP AUTOREGRESSIVE GENERATION
% ============================================================
\begin{scope}[xshift=4.10cm]
% Left-aligned explanation and formula
\node[toptext] at (-3.50,6.00)
{Generating successive tokens by an inference \\ algorithm (e.g., sampling): $y_t\sim \mathrm{Pr}_{\theta}(\cdot\mid\mathbf{x},\mathbf{y}_{<t})$};
% ------------------------------------------------------------
% Language model
% ------------------------------------------------------------
\node[
box,
minimum width=7.0cm,
minimum height=0.78cm,
font=\normalsize
] (llmR) at (0,2.00)
{Large Language Model};
% ------------------------------------------------------------
% Prompt and previously generated tokens
% ------------------------------------------------------------
\node[token,fill=tokenyellow]
(rx1) at (-3.00,0.90) {$x_1$};
\node at (-2.23,0.90) {$\cdots$};
\node[token,fill=tokenyellow]
(rxm) at (-1.45,0.90) {$x_m$};
\node[token,fill=tokengreen]
(ry1) at (0.25,0.90) {$y_1$};
\node at (1.35,0.90) {$\cdots$};
\node[token,fill=tokengreen,minimum width=0.95cm]
(ryprev) at (2.65,0.90) {$y_{t-1}$};
\foreach \n in {rx1,rxm,ry1,ryprev}{
\draw[arrow]
(\n.north) -- (\n.north |- llmR.south);
}
% ------------------------------------------------------------
% Generated outputs
%
% x_m position -> y_1
% y_1 position -> y_2
% y_{t-1} position -> y_t
% ------------------------------------------------------------
\node[token,fill=tokengreen]
(out1) at (-1.45,4.65) {$y_1$};
\node[token,fill=tokengreen]
(out2) at (0.25,4.65) {$y_2$};
\node at (1.35,4.65) {$\cdots$};
\node[token,fill=tokengreen]
(outt) at (2.65,4.65) {$y_t$};
% Vertical prediction / sampling paths
% Draw before formula labels so labels remain legible
\foreach \n in {out1,out2,outt}{
\draw[arrow]
(llmR.north -| \n.south) -- (\n.south);
}
% ------------------------------------------------------------
% Staggered distributions
%
% White backgrounds interrupt the vertical paths at each label.
% Formulas are placed on different levels to avoid overlap.
% ------------------------------------------------------------
\node[distribution]
(rp1) at (-1.45,2.72)
{$\mathrm{Pr}_{\theta}(\cdot\mid\mathbf{x})$};
\node[distribution]
(rp2) at (0.25,3.30)
{$\mathrm{Pr}_{\theta}(\cdot\mid\mathbf{x},y_1)$};
\node[
distribution,
anchor=east
] (rpt) at (3.43,3.84)
{$\mathrm{Pr}_{\theta}(\cdot\mid\mathbf{x},\mathbf{y}_{<t})$};
% Keep the final sampling arrow visible above the formula label.
\draw[arrow]
(2.65,3.84) -- (outt.south);
% Sampled tokens are appended to the context for subsequent steps.
\draw[feedback]
(out1.south east) to[out=-45,in=105] (ry1.north west);
% ------------------------------------------------------------
% Bottom annotations
% ------------------------------------------------------------
\draw[
decorate,
decoration={brace,mirror,amplitude=4pt},
line width=0.7pt
]
(-3.38,0.46) -- (-1.07,0.46);
\node[font=\scriptsize] at (-2.225,0.04)
{Input prompt $\mathbf{x}$};
\draw[
decorate,
decoration={brace,mirror,amplitude=4pt},
line width=0.7pt
]
(-0.13,0.46) -- (3.18,0.46);
\node[font=\scriptsize] at (1.525,0.04)
{Generated tokens $\mathbf{y}_{<t}$};
\node[
font=\scriptsize,
text=black!65,
align=center
] at (0,-0.35)
{Successive steps: append the selected token to the context};
\node[align=center] at (0,-0.90)
{\textbf{(b)} Autoregressive generation with prompting};
\end{scope}
\end{tikzpicture}
...@@ -50,7 +50,7 @@ However, pre-training primarily teaches the model to perform language modeling r ...@@ -50,7 +50,7 @@ However, pre-training primarily teaches the model to perform language modeling r
\subsubsection{Prompting} \subsubsection{Prompting}
Prompting is a simple and lightweight way to adapt an LLM to different tasks without updating its parameters. In the context of LLMs, a \textit{prompt} refers to the input text provided to guide the model toward a desired task or output. It may contain an instruction, user-provided content, output requirements, or demonstrations. For example, if we want an LLM to act as a homework assistant and answer a student's question, we can provide the following prompt: Prompting is a simple and lightweight way to adapt an LLM to different tasks without updating its parameters. A \textit{prompt} is the input text used to guide the model toward a desired task or output. It may contain an instruction, user-provided content, output requirements, or demonstrations. For example, if we want an LLM to act as a homework assistant and answer a student's question, we can provide the following prompt:
\vspace{0.1cm} \vspace{0.1cm}
...@@ -76,7 +76,7 @@ Please make the response clear, practical, and easy to follow. \\[1mm] ...@@ -76,7 +76,7 @@ Please make the response clear, practical, and easy to follow. \\[1mm]
\vspace{0.5em} \vspace{0.5em}
In this example, the prompt itself specifies the task, and the LLM generates the answer by continuing the sequence. A prompt can also be obtained from a prompt template. A prompt template is a piece of text containing placeholders, where each placeholder is filled with concrete information before being sent to the LLM. For example, we can use the following template to construct prompts for a homework assistant: In this example, the input itself specifies the task, and the LLM generates the answer by continuing the sequence. Prompts can also be constructed from templates. A prompt template is a piece of text containing placeholders, where each placeholder is filled with concrete information before being sent to the LLM. For example, we can use the following template to construct prompts for a homework assistant:
\vspace{0.1cm} \vspace{0.1cm}
...@@ -103,7 +103,7 @@ Please make the response clear, practical, and easy to follow. \\[1mm] ...@@ -103,7 +103,7 @@ Please make the response clear, practical, and easy to follow. \\[1mm]
\vspace{0.5em} \vspace{0.5em}
If we set \{*subject*\} to ``math'', the template becomes the prompt used above. In this way, users can easily construct different prompts by changing the placeholder while keeping the main task description unchanged. If we set \{*subject*\} to ``math'', the template becomes the prompt used above. In this way, users can construct different prompts by changing the placeholder while keeping the main task description unchanged.
Another important concept related to prompting is in-context learning. When prompting an LLM, we can add demonstrations to the context and let the model infer the desired input-output pattern from these examples. For instance, we can show the model how to answer similar student questions before asking it to respond to a new one: Another important concept related to prompting is in-context learning. When prompting an LLM, we can add demonstrations to the context and let the model infer the desired input-output pattern from these examples. For instance, we can show the model how to answer similar student questions before asking it to respond to a new one:
...@@ -124,15 +124,8 @@ Another important concept related to prompting is in-context learning. When prom ...@@ -124,15 +124,8 @@ Another important concept related to prompting is in-context learning. When prom
\end{tcolorbox} \end{tcolorbox}
\vspace{0.5em} \vspace{0.5em}
Prompting is crucial because it directly influences how the LLM understands the task and generates the output. A well-designed prompt can guide the model to produce more accurate, relevant, and appropriately formatted responses. However, since the model parameters are unchanged, the result can also be sensitive to the wording, structure, and demonstrations provided in the prompt. Prompting adapts an LLM by changing the context used for generation. Therefore, prompt quality can strongly affect model performance. Even for the same task, we can write the prompt in many different ways. For example, ``Give me two tips to improve my English writing.'' can also be written as ``What are two simple ways to improve my English writing skills?''. The two prompts express nearly the same intent, but they may lead to noticeably different outputs. In practice, we often refine prompts through repeated trial and error for a given LLM. More advanced methods automate this process and search for better prompts using techniques such as RL \citep{deng-etal:rlprompt} or evolutionary algorithms \citep{guo-etal:connecting}.
Following the notation used above, we denote the entire prompt by $\mathbf{x}=x_1...x_m$. Prompting asks the LLM to generate an output $\mathbf{y}=y_1...y_T$ according to the conditional distribution $\mathrm{Pr}_{\theta}(\mathbf{y}|\mathbf{x})$. The probability of the output is factorized as
\begin{align}
\mathrm{Pr}_{\theta}(\mathbf{y}|\mathbf{x}) & = \prod_{t=1}^{T} \mathrm{Pr}_{\theta}(y_t|\mathbf{x},\mathbf{y}_{<t}) \\
\log \mathrm{Pr}_{\theta}(\mathbf{y}|\mathbf{x}) & = \sum_{t=1}^{T} \log \mathrm{Pr}_{\theta}(y_t|\mathbf{x},\mathbf{y}_{<t})
\end{align}
where $\mathbf{y}_{<t}=y_1...y_{t-1}$ denotes the tokens that have already been generated. This conditional generation formulation will be repeatedly used in the following sections. From this perspective, a prompt mainly changes the condition under which the same language model distribution is used.
\subsubsection{Supervised Fine-Tuning} \subsubsection{Supervised Fine-Tuning}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论