🚀 在我们的新课程中掌握提示工程和构建AI智能体!使用 PROMPTING20 享 8 折优惠 ➜ 立即报名
Gemma

Gemma

Google DeepMind 发布了 Gemma,这是一系列受用于创建 Gemini 的相同研究和技术启发而产生的开放语言模型。Gemma 模型发布包括 2B(在 2T tokens 上训练)和 7B(在 6T tokens 上训练)模型,包含基础模型和指令微调检查点。这些模型在 8192 tokens 的上下文长度上进行训练,并且在多项 benchmark 上总体优于 Llama 2 7B 和 Mistral 7B 模型。

Gemma 模型架构基于 transformer decoder,并进行了改进,包括多查询注意力 (在新标签页中打开)(2B 模型使用)、多头注意力(7B 模型使用)、RoPE 嵌入 (在新标签页中打开)GeGLU 激活 (在新标签页中打开)以及归一化器位置 (在新标签页中打开)

根据技术报告 (在新标签页中打开),Gemma 2B 和 7B 主要在包含网络文档、数学和代码的 2T 和 6T tokens 数据集上进行训练。与 Gemini 不同,这些模型并未明确训练以支持多语言或多模态功能。词汇表大小为 256K tokens,并使用 Gemini 的 SentencePiece 分词器的子集,保留数字分割中的空格,并依赖字节级编码处理未知 tokens。

指令微调模型使用监督微调(基于文本合成和人类生成的提示-响应对)和人类反馈强化学习 (RLHF) 进行调整,其中奖励模型在带标签的偏好数据上训练,策略基于一组高质量的提示。请注意,所有使用的数据集仅限英文。如下表所示,指令微调模型还使用特定的格式控制 tokens 来指示对话中的角色和轮次。

"Gemma Control Tokens"

结果

如下图所示,Gemma 7B 模型在数学、科学和代码相关任务上表现出色。分数对应于按能力分组的学术 benchmark 评估的平均得分。

"Gemma Capabilities"

Gemma 7B 在各种学术 benchmark 上优于 Llama 2 7B 和 Mistral 7B,在 HumanEval、GSM8K、MATH 和 AGIEval 上表现显著,并在推理、对话、数学和代码方面有所改进。

"Gemma Safety"

经人工评估,Gemma 7B 指令微调模型在安全性和指令遵循方面也优于 Mistral-7B v0.2 Instruct 模型。

"Gemma Safety"

Gemma 还在多项安全学术 benchmark 上进行了评估,并与 Mistral 进行了比较。技术报告还提到了使用去偏技术和红队测试来潜在缓解与大型语言模型 (LLM) 相关的常见风险。您可以在模型卡 (在新标签页中打开)负责任的生成式 AI 工具包 (在新标签页中打开)中找到有关如何负责任地使用 Gemma 进行开发的更多信息。

"Gemma Safety"

Gemma 7B 提示格式

Gemma 基础模型不使用任何特定的提示格式,但可以通过零样本/少样本提示来执行任务。Gemma Instruct 模型使用以下格式

<start_of_turn>user
Generate a Python function that multiplies two numbers <end_of_turn>
<start_of_turn>model

下表显示了 Gemma 中可用的相关格式控制 tokens

上下文相关 Token
用户轮次user
模型轮次model
对话轮次开始<start_of_turn>
对话轮次结束<end_of_turn>

您也可以在多轮用户提示的上下文中使用这些特殊的控制 tokens,如下所示

<start_of_turn>user
What is a good place for travel in the US?<end_of_turn>
<start_of_turn>model
California.<end_of_turn>
<start_of_turn>user
What can I do in California?<end_of_turn>
<start_of_turn>model

如何提示 Gemma 7B

有效提示 Gemma 7B 需要能够正确使用提示模板。在以下示例中,我们将介绍几个示例,展示如何有效使用 Gemma 7B Instruct 的提示模板来执行各种任务。

零样本提示

与任何模型一样,您只需按如下方式提示 Gemma 即可利用其零样本能力

<start_of_turn>user
Explain why the sky is blue<end_of_turn>
<start_of_turn>model

带系统提示的零样本提示

添加系统角色或系统提示有助于更好地引导 LLM。虽然 Gemma 中没有明确的系统角色,但您可以将额外指令作为提示的一部分添加,如下所示

<start_of_turn>user
Answer the following question in a concise and informative manner:
 
Explain why the sky is blue<end_of_turn>
<start_of_turn>model

在上面的示例中,我们将 "Answer the following question in a concise and informative manner:" 添加为额外指令或系统提示,以更好地引导模型。

角色扮演

我们还可以测试 Gemma 的角色扮演能力,这是一项有用的能力,不仅可以个性化模型响应,还可以构建更复杂的领域特定LLM 智能体 (在新标签页中打开)

提示

<start_of_turn>user
You are a helpful 2nd-grade teacher. Help a 2nd grader to answer questions in a short and clear manner.

Explain why the sky is blue<end_of_turn>
<start_of_turn>model

模型响应

Sure, here is an explanation for why the sky is blue:

The sky appears blue because of a phenomenon called Rayleigh Scattering.

Here's the science behind it:

Sunlight is made up of different colors of light, like red, green, blue, and violet.
When sunlight hits the Earth's atmosphere, the different colors of light scatter in different directions.
Blue light scatters more easily than other colors because it has shorter wavelengths.
The scattered blue light travels in all directions, including towards your eyes.
That's why we see the sky as blue.
It's important to note that this explanation is simplified and does not account for all scientific details. However, it gives you a good understanding of the basic science behind why the sky appears blue.

请注意,我们尚未检查响应的准确性以及它是否适合二年级学生。但是,您可以将上述响应与接下来的思维链提示获得的响应进行比较。

推理

您可以通过使用零样本思维链提示 (在新标签页中打开)来引出 Gemma 的推理能力,如下所示

提示

<start_of_turn>user
Think and write your step-by-step reasoning before responding.
 
Explain why the sky is blue.<end_of_turn>
<start_of_turn>model

模型响应 (为简洁起见已截断)

Step 1: Scattering of Light

The sky appears blue due to the phenomenon of scattering of light. When sunlight hits the Earth's atmosphere, it interacts with the particles of air, primarily nitrogen and oxygen molecules.

Step 2: Rayleigh Scattering

Rayleigh scattering is the specific scattering mechanism that occurs when light interacts with particles much smaller than the wavelength of light. In this process, shorter wavelengths (blue light) are scattered more effectively than longer wavelengths (red light).

Step 3: Blue Scattered Light Travels in All Directions

...

Conclusion

The sky appears blue due to the scattering of light, specifically Rayleigh scattering. Shorter wavelengths of light are scattered more effectively, and this scattered light travels in all directions, with the scattered light that travels opposite to the sun's rays being most visible to our eyes.

关于 Gemma 模型需要注意的一点是,它可以自动输出 Markdown 格式。我们稍微编辑了文本格式以进行演示和简化,但内容完全是模型响应的原貌。请注意,我们也没有评估响应的准确性或模型是否存在幻觉。

资源与集成

以下是 Gemma 发布中包含的几个资源和集成

根据官方博客发布 (在新标签页中打开)使用条款 (在新标签页中打开)允许所有规模的组织进行负责任的商业使用和分发。

参考文献