Stephen Wolfram:一次只添加一个词

It’s Just Adding One Word at a Time

一次只添加一个词

That ChatGPT can automatically generate something that reads even superficially like human-written text is remarkable, and unexpected. But how does it do it? And why does it work? My purpose here is to give a rough outline of what’s going on inside ChatGPT—and then to explore why it is that it can do so well in producing what we might consider to be meaningful text. I should say at the outset that I’m going to focus on the big picture of what’s going on—and while I’ll mention some engineering details, I won’t get deeply into them. (And the essence of what I’ll say applies just as well to other current “large language models” [LLMs] as to ChatGPT.)

ChatGPT 能够自动生成一些看起来像人类编写的文本的内容,这是非常了不起,也是出乎意料的。但是它是如何做到的呢?为什么会起作用?我在这里的目的是给出 ChatGPT 内部发生的事情的大致轮廓,然后探讨为什么它能够如此出色地生成我们认为有意义的文本。首先我要说的是,我将关注整个过程的大局观,虽然我会提到一些工程细节,但不会深入探讨。(我将要说的内容同样适用于当前像 ChatGPT 那样的其他“大型语言模型”[LLMs]。)

The first thing to explain is that what ChatGPT is always fundamentally trying to do is to produce a “reasonable continuation” of whatever text it’s got so far, where by “reasonable” we mean “what one might expect someone to write after seeing what people have written on billions of webpages, etc.”

首先要解释的是,ChatGPT 基本上总是试图生成与迄今为止得到的文本“合理延续”,其中“合理”是指“在浏览了数十亿网页等内容后,人们可能预期会写下什么”。

So let’s say we’ve got the text “The best thing about AI is its ability to”. Imagine scanning billions of pages of human-written text (say on the web and in digitized books) and finding all instances of this text—then seeing what word comes next what fraction of the time. ChatGPT effectively does something like this, except that (as I’ll explain) it doesn’t look at literal text; it looks for things that in a certain sense “match in meaning”. But the end result is that it produces a ranked list of words that might follow, together with “probabilities”:

那么假设我们有这样一段文本:“关于 AI 最棒的是它的能力”。试想一下,扫描数十亿页由人类书写的文本(比如在网页和数字图书中),找到所有这段文本的实例,然后观察下一个单词出现的频率。ChatGPT 实际上就是执行类似的操作,不过(正如我将解释的),它并不查看字面文本,而是寻找某种意义上“意义相匹配”的内容。最终,它会生成一个可能接下来出现的单词的排序列表,同时附带“概率”:

d50df42e2014842847510c0e0154b961.png

And the remarkable thing is that when ChatGPT does something like write an essay what it’s essentially doing is just asking over and over again “given the text so far, what should the next word be?”—and each time adding a word. (More precisely, as I’ll explain, it’s adding a “token”, which could be just a part of a word, which is why it can sometimes “make up new words”.)

而令人惊讶的是,当 ChatGPT 做类似于写一篇文章的事情时,它实质上所做的就是一遍又一遍地询问“根据目前的文本,下一个词应该是什么?”——并且每次都添加一个词。(更准确地说,正如我将解释的,它添加的是一个“令牌”,这可能只是一个词的一部分,这就是为什么它有时可以“创造新词”的原因。)

But, OK, at each step it gets a list of words with probabilities. But which one should it actually pick to add to the essay (or whatever) that it’s writing? One might think it should be the “highest-ranked” word (i.e. the one to which the highest “probability” was assigned). But this is where a bit of voodoo begins to creep in. Because for some reason—that maybe one day we’ll have a scientific-style understanding of—if we always pick the highest-ranked word, we’ll typically get a very “flat” essay, that never seems to “show any creativity” (and even sometimes repeats word for word). But if sometimes (at random) we pick lower-ranked words, we get a “more interesting” essay.

好的,在每一步中,它会得到一个带概率的词汇列表。但是,它究竟应该选择哪个词来添加到正在撰写的文章(或其他内容)中呢?人们可能会认为它应该选择“排名最高”的词(即被分配了最高“概率”的词),但这里就开始出现一些神秘的东西了。因为由于某种原因——或许有一天我们会对此有科学式的理解——如果我们总是选择排名最高的词,我们通常会得到一篇非常“平淡”的文章,似乎从未“表现出任何创造力”(甚至有时会逐字重复)。但如果我们有时(随机地)选择排名较低的词汇,我们就能得到一篇“更有趣”的文章。

The fact that there’s randomness here means that if we use the same prompt multiple times, we’re likely to get different essays each time. And, in keeping with the idea of voodoo, there’s a particular so-called “temperature” parameter that determines how often lower-ranked words will be used, and for essay generation, it turns out that a “temperature” of 0.8 seems best. (It’s worth emphasizing that there’s no “theory” being used here; it’s just a matter of what’s been found to work in practice. And for example the concept of “temperature” is there because exponential distributions familiar from statistical physics happen to be being used, but there’s no “physical” connection—at least so far as we know.)

事实上,这里的随机性意味着如果我们多次使用相同的提示,我们可能每次都会得到不同的文章。为了保持神秘感,有一个所谓的“温度”参数用来决定使用排名较低的词汇的频率,而对于生成文章来说,0.8 的“温度”似乎是最佳的。(值得强调的是,这里并没有使用任何“理论”;这只是根据实践中发现的有效方法。例如,“温度”的概念之所以存在,是因为碰巧使用了熟悉的指数分布,这是从统计物理中得出的,但并没有“物理”联系——至少就我们所知。)

Before we go on I should explain that for purposes of exposition I’m mostly not going to use the full system that’s in ChatGPT; instead I’ll usually work with a simpler GPT-2 system, which has the nice feature that it’s small enough to be able to run on a standard desktop computer. And so for essentially everything I show I’ll be able to include explicit Wolfram Language code that you can immediately run on your computer. (Click any picture here to copy the code behind it.)

在继续之前,我需要解释一下,为了阐述的目的,我在大多数情况下不会使用 ChatGPT 中的完整系统;相反,我通常会使用一个更简单的 GPT-2 系统,它的一个好处是它足够小,可以在标准桌面电脑上运行。因此,对于我展示的几乎所有内容,我都能够包含明确的 Wolfram 语言代码,您可以立即在您的电脑上运行。(点击这里的任何图片都可以复制其背后的代码。)

For example, here’s how to get the table of probabilities above. First, we have to retrieve the underlying “language model” neural net:

 例如,这是如何得到上述概率表的方法。首先,我们需要获取底层的“语言模型”神经网络:

e7335b5d3a0d580e171e63ea55c8fe34.png

Later on, we’ll look inside this neural net, and talk about how it works. But for now we can just apply this “net model” as a black box to our text so far, and ask for the top 5 words by probability that the model says should follow:

稍后,我们将深入这个神经网络,并讨论它是如何工作的。但现在我们可以将这个“网络模型”作为一个黑盒子应用到目前的文本上,并询问模型认为应该接下来的概率排名前五的词汇:

2ae77c030ead70fccf4a89ddc840dcb2.png

This takes that result and makes it into an explicit formatted “dataset”:

这将结果转换成一个显式格式化的“数据集”:

18723a8ef419282363d27d8abc4a993c.png

Here’s what happens if one repeatedly “applies the model”—at each step adding the word that has the top probability (specified in this code as the “decision” from the model):

以下是反复“应用模型”的结果——在每一步中添加概率最高的词汇(在此代码中,将其指定为模型的“决策”):

3f0c417438110b5f6d390e9ac588fd3f.png

What happens if one goes on longer? In this (“zero temperature”) case what comes out soon gets rather confused and repetitive:

如果持续更长时间会发生什么?在这种(“零温度”)情况下,生成的内容很快变得混乱且重复:

2a94acc8269541f834a6f8736672d37f.png

But what if instead of always picking the “top” word one sometimes randomly picks “non-top” words (with the “randomness” corresponding to “temperature” 0.8)? Again one can build up text:

但是,如果不总是选择“排名最高”的词汇,而是有时随机选择“非排名最高”的词汇(这里的“随机性”对应于“温度” 0.8)呢?我们再次生成文本:

6e7bba99967fc4e24ad1de5dec52596e.png

And every time one does this, different random choices will be made, and the text will be different—as in these 5 examples:

每次执行这个操作时,都会做出不同的随机选择,生成的文本也会有所不同,就像这 5 个例子中的情况一样:

f5fad014e7d5056e7140156534fa3e06.png

It’s worth pointing out that even at the first step there are a lot of possible “next words” to choose from (at temperature 0.8), though their probabilities fall off quite quickly (and, yes, the straight line on this log-log plot corresponds to an n–1 “power-law” decay that’s very characteristic of the general statistics of language):

值得指出的是,即使在第一步,也有很多可能的“接下来的词汇”可以选择(在温度为 0.8 的情况下),尽管它们的概率下降得相当快(是的,在这个对数-对数图上的直线对应于一个 n-1 的“幂律”衰减,这是语言通用统计特征的一个典型特征):

3ce9ff0e46d3b1e9710e3565fd91dc42.png

So what happens if one goes on longer? Here’s a random example. It’s better than the top-word (zero temperature) case, but still at best a bit weird:

那么,如果持续更长时间会发生什么呢?以下是一个随机示例。相比于总选择排名最高的词汇(零温度)情况要好,但最多也只是有点奇怪:

369589635e1a8af0c42095eba656d062.png

This was done with the simplest GPT-2 model (from 2019). With the newer and bigger GPT-3 models the results are better. Here’s the top-word (zero temperature) text produced with the same “prompt”, but with the biggest GPT-3 model:

这是使用最简单的 GPT-2 模型(2019 年发布)完成的。使用更新且更大的 GPT-3 模型,结果会更好。以下是使用相同的“提示”生成的排名最高词汇(零温度)文本,但使用的是最大的 GPT-3 模型:

2f870b0f7b7765cc5e6a58e662132768.png

And here’s a random example at “temperature 0.8”:

以下是一个“温度 0.8”下的随机示例:

82cfb0eb7af4984302530d212622a952.png

7c2244cec2e11cd6831b60748cb1c847.jpeg

“点赞有美意,赞赏是鼓励”

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/7720.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql进阶1——proxysql中间件

文章目录 一、基本了解二、安装部署三、proxysql管理配置3.1 内置库3.1.1 main库表3.1.2 stats库表3.1.3 monitor库 3.2 常用管理变量3.2.1 添加管理用户3.2.2 添加普通用户3.2.3 修改监听套接字 四、多层配置系统4.1 系统结构4.2 修改变量加载配置4.3 启动加载流程 一、基本了…

单机和集群以及分布式的浅析

假设一个大系统分为A、B、C、D、E五个模块,也可以认为是五个基本的服务,该系统靠这五个模块协同工作,共同为用户提供服务。 单机 单机:显然,单机表名该系统完完全全的部署在该台机器上,拥有完整的服务&am…

C++_03_C++的增强

本人亦可见 一、C相较于C&#xff0c;实用性增强 1、C相较于C&#xff0c;全局变量检查增强 #include<stdio.h> int m20; //先定义 int m; //再声明 int main() {printf("m %d\n",m); //m20return 0; } //严格意义上来说&#xff0c;先定义后声明…

集成学习——Boosting算法:Adaboost、GBDT、XGBOOST和lightGBM的简要原理和区别

1、Boosting算法 Boosting算法是通过串联的方式&#xff0c;将一组弱学习器提升为强学习器算法。它的工作机制如下&#xff1a; &#xff08;1&#xff09;用初始训练集训练出一个基学习器&#xff1b; &#xff08;2&#xff09;依据基学习器的表现对训练样本分布进行调整&…

设计模式之命令模式

写在前面 本文看下命令设计模式。 1&#xff1a;介绍 1.1&#xff1a;什么时候使用命令设计模式 如果某个对象依赖于外部传入的具体参数来执行具体的操作时&#xff0c;就可以考虑使用命令设计模式&#xff0c;如空调的制冷&#xff0c;制热&#xff0c;小爱同学的唱歌&…

opencv 图像距离变换 distanceTransform

图像距离变换&#xff1a;计算图像中每一个非零点距离离自己最近的零点的距离&#xff0c;然后通过二值化0与非0绘制图像。 #include "iostream" #include "opencv2/opencv.hpp" using namespace std; using namespace cv;int main() {Mat img, dst, dst…

洛必达法则和分部积分的应用之计算数学期望EX--概率论浙大版填坑记

如下图所示&#xff0c;概率论与数理统计浙大第四版有如下例题&#xff1a; 简单说就是&#xff1a;已知两个相互独立工作电子装置寿命的概率密度函数&#xff0c;将二者串联成整机&#xff0c;求整机寿命的数学期望。 这个题目解答中的微积分部分可谓是相当的坑爹&#xff0c;…

Jenkins中sh函数的用法

在Jenkins的Pipeline中&#xff0c;sh函数的用法 用法一 单个命令字符串包括使用&#xff0c;示例如下&#xff1a; sh echo "Hello, Jenkins!"用法二 多个命令字符串包括命令列表使用&#xff0c;示例如下&#xff1a; sh echo "Step 1" echo "…

vue/cli 自定义配置

vue/cli 自定义配置 1、更改默认的端口号8080 只需要更改vue.config.js文件 1、更改默认的端口号8080 只需要更改vue.config.js文件

脑电信号处理与特征提取——4.脑电信号的预处理及数据分析要点(彭微微)

目录 四、脑电信号的预处理及数据分析要点 4.1 脑电基础知识回顾 4.2 伪迹 4.3 EEG预处理 4.3.1 滤波 4.3.2 重参考 4.3.3 分段和基线校正 4.3.4 坏段剔除 4.3.5 坏导剔除/插值 4.3.6 独立成分分析ICA 4.4 事件相关电位&#xff08;ERPs&#xff09; 4.4.1 如何获…

使用flask-sqlacodegen自动生成model实体类

使用flask-sqlacodegen自动生成model实体类 依赖库版本如下(供参考)&#xff1a; flask-sqlacodegen 1.1.7sqlalchemy 1.4.36flask-sqlalchemy 3.0.3安装依赖库 pip install -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com sqlalchem…

flutter fl_chart 柱状图 柱条数量较多 实现左右滑动 固定y轴

一、引入插件 pub.dev&#xff1a;fl_chart package - All Versions 根据项目版本&#xff0c;安装可适配的 fl_chart 版本 二、官网柱状图示例 github参数配置&#xff1a;&#xff08;x轴、y轴、边框、柱条数据、tooltip等&#xff09; https://github.com/imaNNeo/fl_c…

【LeetCode】70.爬楼梯

题目 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢&#xff1f; 示例 1&#xff1a; 输入&#xff1a;n 2 输出&#xff1a;2 解释&#xff1a;有两种方法可以爬到楼顶。 1. 1 阶 1 阶 2. 2 阶 示例 2…

什么是UE像素流送,像素流推流是什么原理?

游戏开发者通常在运行游戏逻辑时会将游戏渲染到屏幕的同一台设备上来运行虚幻引擎应用&#xff0c;多人联网游戏可能会在应用程序的多个实例之间分发部分游戏逻辑&#xff0c;但每个单独的实例仍然会为自己的玩家在本地渲染游戏。即使是使用 HTML5 部署选项创建可以在 Web 浏览…

解决@Scope(“prototype“)不生效的问题

目录 Scope(“prototype“)不生效Scope(“prototype“)正确用法——解决Bean多例问题 1.问题&#xff0c;Spring管理的某个Bean需要使用多例2.问题升级3. Spring给出的解决问题的办法&#xff08;解决Bean链中某个Bean需要多例的问题&#xff09; Scope(“prototype“)不生效 …

【ribbon】Ribbon的使用与原理

负载均衡介绍 负载均衡&#xff08;Load Balance&#xff09;&#xff0c;其含义就是指将负载&#xff08;工作任务&#xff09;进行平衡、分摊到多个操作单元上进行运行&#xff0c;例如FTP服务器、Web服务器、企业核心应用服务器和其它主要任务服务器等&#xff0c;从而协同…

【《Go编程进阶实战:开发命令行应用、HTTP应用和gRPC应用》——指导你使用Go语言构建健壮的、生产级别的应用程序】

谷歌在2009年发布了Go编程语言&#xff0c;并于2012年发布了1.0版。Go语言具有强大的兼容性&#xff0c;一直用于编写可扩展的重量级程序(命令行应用程序、关键基础设施工具乃至大规模分布式系统)。凭借简单性、丰富的标准库和蓬勃发展的第三方软件包生态系统&#xff0c;Go语言…

工程安全监测无线振弦采集仪在建筑物中的应用

工程安全监测无线振弦采集仪在建筑物中的应用 工程安全监测无线振弦采集仪是一种用于建筑物结构安全监测的设备&#xff0c;它采用了无线传输技术&#xff0c;具有实时性强、数据精度高等优点&#xff0c;被广泛应用于建筑物结构的实时监测和预警。下面将从设备的特点、应用场…

FPGA中RAM的结构理解

FPGA中RAM的结构理解 看代码的过程中对RAM的结构不是很理解&#xff0c;搞脑子一片浆糊&#xff0c;反复推算&#xff0c;好不容易理清了思路&#xff0c;记录下来&#xff0c;防止忘记。开辟的RAM总容量为128bytes&#xff0c;数据的位宽为32位&#xff08;即一个单元有32bit…

WebGL系列教程:WebGL入门

一、WebGL简介 1.1 概述 WebGL(全写 Web Graphics Library)是一种 3D 绘图标准,这种绘图技术标准允许把 JavaScript 和 OpenGL ES 2.0 结合在一起,通过增加 OpenGL ES 2.0 的一个 JavaScript 绑 定,WebGL 可以为 HTML5 Canvas 提供硬件 3D 加速渲染,这样 Web 开发人员就可…