Stephen Wolfram:嵌入的概念

The Concept of Embeddings 

嵌入的概念

Neural nets—at least as they’re currently set up—are fundamentally based on numbers. So if we’re going to to use them to work on something like text we’ll need a way to represent our text with numbers. And certainly we could start (essentially as ChatGPT does) by just assigning a number to every word in the dictionary. But there’s an important idea—that’s for example central to ChatGPT—that goes beyond that. And it’s the idea of “embeddings”. One can think of an embedding as a way to try to represent the “essence” of something by an array of numbers—with the property that “nearby things” are represented by nearby numbers.

神经网络——至少在目前的设置中——是基于数字的。所以,如果我们要使用它们来处理像文本这样的东西,我们需要一种用数字表示文本的方法。当然,我们可以开始(就像 ChatGPT 所做的那样)为字典中的每个单词分配一个数字。但是,还有一个重要的想法——例如,这是 ChatGPT 的核心思想——超越了这一点。这个想法就是“嵌入”。我们可以将嵌入看作是一种尝试通过一组数字来表示事物“本质”的方法——其特性是“相邻的事物”由相邻的数字表示。

And so, for example, we can think of a word embedding as trying to lay out words in a kind of “meaning space” in which words that are somehow “nearby in meaning” appear nearby in the embedding. The actual embeddings that are used—say in ChatGPT—tend to involve large lists of numbers. But if we project down to 2D, we can show examples of how words are laid out by the embedding:

因此,例如,我们可以将词嵌入视为尝试在一种“意义空间”中布局单词,其中在意义上“相近”的单词在嵌入中也相邻。实际使用的嵌入——比如在 ChatGPT 中——倾向于涉及大量的数字列表。但如果我们将其投影到二维空间,我们可以展示单词在嵌入中的布局示例:

376d54539b67350205720d5ccf0138ad.png

And, yes, what we see does remarkably well in capturing typical everyday impressions. But how can we construct such an embedding? Roughly the idea is to look at large amounts of text (here 5 billion words from the web) and then see “how similar” the “environments” are in which different words appear. So, for example, “alligator” and “crocodile” will often appear almost interchangeably in otherwise similar sentences, and that means they’ll be placed nearby in the embedding. But “turnip” and “eagle” won’t tend to appear in otherwise similar sentences, so they’ll be placed far apart in the embedding.

是的,我们看到的确实在很大程度上捕捉到了典型的日常印象。但是我们如何构建这样的嵌入呢?大致的想法是查看大量的文本(这里是来自网络的 50 亿个单词),然后看看不同单词出现的“环境”有多“相似”。因此,例如,“alligator”和“crocodile”通常会在其他相似的句子中几乎可以互换地出现,这意味着它们在嵌入中会被放置得很近。但“turnip”和“eagle”不会出现在其他类似的句子中,因此它们在嵌入中的位置会相距较远。

But how does one actually implement something like this using neural nets? Let’s start by talking about embeddings not for words, but for images. We want to find some way to characterize images by lists of numbers in such a way that “images we consider similar” are assigned similar lists of numbers.

但是,如何使用神经网络实际实现这样的功能呢?让我们先谈谈关于图像而不是单词的嵌入。我们希望建立某种方法,通过数字列表来描述图像,使得“我们认为相似的图像”被分配相似的数字列表。

How do we tell if we should “consider images similar”? Well, if our images are, say, of handwritten digits we might “consider two images similar” if they are of the same digit. Earlier we discussed a neural net that was trained to recognize handwritten digits. And we can think of this neural net as being set up so that in its final output it puts images into 10 different bins, one for each digit.

我们如何判断我们是否应该“认为图像相似”呢?好吧,如果我们的图像是,比如说,手写数字,我们可能会“认为两个图像相似”,如果它们是相同的数字。之前我们讨论了一个经过训练的神经网络,用于识别手写数字。我们可以将这个神经网络看作是设置成在其最终输出中将图像放入 10 个不同的箱子,每个数字一个。

But what if we “intercept” what’s going on inside the neural net before the final “it’s a ‘4’” decision is made? We might expect that inside the neural net there are numbers that characterize images as being “mostly 4-like but a bit 2-like” or some such. And the idea is to pick up such numbers to use as elements in an embedding.

但是,如果我们在最终做出“这是‘4’”的决定之前,“拦截”神经网络内部正在进行的操作会怎样呢?我们可能会期望神经网络内部有一些数字来表征图像,比如“大部分像 4,但有点像 2 ”之类的。这个想法就是利用这些数字作为嵌入中的元素。

So here’s the concept. Rather than directly trying to characterize “what image is near what other image”, we instead consider a well-defined task (in this case digit recognition) for which we can get explicit training data—then use the fact that in doing this task the neural net implicitly has to make what amount to “nearness decisions”. So instead of us ever explicitly having to talk about “nearness of images” we’re just talking about the concrete question of what digit an image represents, and then we’re “leaving it to the neural net” to implicitly determine what that implies about “nearness of images”.

这里是概念。我们不是直接尝试描述“哪个图像靠近哪个图像”,而是考虑一个可以获得明确训练数据的明确定义任务(在这种情况下是数字识别),然后利用神经网络在执行这个任务时必须隐含地进行类似“靠近决策”的事实。所以我们不需要明确地讨论“图像的靠近性”,我们只是讨论一个具体问题,即图像代表的数字是什么,然后我们“把它留给神经网络”来隐含地确定这对“图像的靠近性”意味着什么。

So how in more detail does this work for the digit recognition network? We can think of the network as consisting of 11 successive layers, that we might summarize iconically like this (with activation functions shown as separate layers):

那么,对于数字识别网络,这个方法具体是如何工作的呢?我们可以将网络看作是由 11 个连续的层组成,我们可以用图标表示如下(激活函数显示为单独的层):

72691945cb3e8a9f0fb8f2fdb6a2bfec.png

At the beginning we’re feeding into the first layer actual images, represented by 2D arrays of pixel values. And at the end—from the last layer—we’re getting out an array of 10 values, which we can think of saying “how certain” the network is that the image corresponds to each of the digits 0 through 9.

在开始时,我们将实际图像(由像素值的二维数组表示)输入到第一层。在最后,从最后一层中,我们得到一个包含 10 个值的数组,我们可以认为它表示网络确定图像对应 0 到 9 的每个数字的“确定程度”。

Feed in the image 

cd43527d0d72bdb90b40ffa06e9f2263.png

 and the values of the neurons in that last layer are:

输入图像:最后一层神经元的值为:

fd3c131ca7bfac4278addd25517563cf.png

In other words, the neural net is by this point “incredibly certain” that this image is a 4—and to actually get the output “4” we just have to pick out the position of the neuron with the largest value.

换句话说,到目前为止,神经网络“非常确定”这个图像是 4——要实际得到输出“4”,我们只需要找到数值最大的神经元的位置。

But what if we look one step earlier? The very last operation in the network is a so-called softmax which tries to “force certainty”. But before that’s been applied the values of the neurons are:

但是,如果我们再往前看一步会怎样呢?网络中的最后一个操作是所谓的“softmax”,它试图“强制确定”。但在应用“softmax”之前,神经元的值是:

0fd57248993b46e0af50b62aeb9d50f7.png

The neuron representing “4” still has the highest numerical value. But there’s also information in the values of the other neurons. And we can expect that this list of numbers can in a sense be used to characterize the “essence” of the image—and thus to provide something we can use as an embedding. And so, for example, each of the 4’s here has a slightly different “signature” (or “feature embedding”)—all very different from the 8’s:

表示“4”的神经元仍然具有最高的数值。但是其他神经元的值中也有信息。我们可以期望这个数字列表在某种程度上用来描述图像的“本质”,从而提供我们可以用作嵌入的东西。因此,例如,这里的每个 4 都有一个略有不同的“签名”(或“特征嵌入”)——与 8 完全不同:

8d3f1b0b6d69adeea7951094065b3b37.png

Here we’re essentially using 10 numbers to characterize our images. But it’s often better to use much more than that. And for example in our digit recognition network we can get an array of 500 numbers by tapping into the preceding layer. And this is probably a reasonable array to use as an “image embedding”.

在这里,我们实质上使用了 10 个数字来描述我们的图像。但通常使用更多的数字会更好。例如,在我们的数字识别网络中,我们可以通过连接到前一层来获得一个包含 500 个数字的数组。这可能是一个合理的“图像嵌入”。

If we want to make an explicit visualization of “image space” for handwritten digits we need to “reduce the dimension”, effectively by projecting the 500-dimensional vector we’ve got into, say, 3D space:

如果我们想为手写数字的“图像空间”制作一个明确的可视化,我们需要“降低维度”,实际上是将我们得到的 500 维向量投影到,例如,3D 空间:

2efa62e8b6f13e9df4e2d53f842a0606.png

We’ve just talked about creating a characterization (and thus embedding) for images based effectively on identifying the similarity of images by determining whether (according to our training set) they correspond to the same handwritten digit. And we can do the same thing much more generally for images if we have a training set that identifies, say, which of 5000 common types of object (cat, dog, chair, …) each image is of. And in this way we can make an image embedding that’s “anchored” by our identification of common objects, but then “generalizes around that” according to the behavior of the neural net. And the point is that insofar as that behavior aligns with how we humans perceive and interpret images, this will end up being an embedding that “seems right to us”, and is useful in practice in doing “human-judgement-like” tasks.

我们刚刚讨论了如何根据确定图像是否(根据我们的训练集)对应于相同的手写数字来识别图像的相似性,从而为图像创建一个特征(因此嵌入)。对于图像,如果我们有一个训练集,该训练集可以识别出,例如,每个图像是 5000 种常见类型的对象(猫、狗、椅子等)中的哪一种,我们可以做同样的事情。通过这种方式,我们可以制作一个以我们识别常见物体为“锚点”的图像嵌入,然后根据神经网络的行为“在此基础上进行推广”。关键在于,只要该行为与我们人类感知和解释图像的方式相一致,这将最终成为一个“对我们来说看似正确”的嵌入,并在实践中用于执行“类似人类判断”的任务。

OK, so how do we follow the same kind of approach to find embeddings for words? The key is to start from a task about words for which we can readily do training. And the standard such task is “word prediction”. Imagine we’re given “the ___ cat”. Based on a large corpus of text (say, the text content of the web), what are the probabilities for different words that might “fill in the blank”? Or, alternatively, given “___ black ___” what are the probabilities for different “flanking words”?

好的,那么我们如何采用相同的方法来找到单词的嵌入呢?关键是从一个可以轻松进行训练的单词任务开始。标准的这类任务是“单词预测”。想象一下,我们得到了“the ___ cat”。基于大量的文本语料库(比如,互联网的文本内容),可能填入空白处的不同单词的概率是多少?或者,换个说法,给定“___ black ___”,不同的“外围词”的概率是多少?

How do we set this problem up for a neural net? Ultimately we have to formulate everything in terms of numbers. And one way to do this is just to assign a unique number to each of the 50,000 or so common words in English. So, for example, “the” might be 914, and “ cat” (with a space before it) might be 3542. (And these are the actual numbers used by GPT-2.) So for the “the ___ cat” problem, our input might be {914, 3542}. What should the output be like? Well, it should be a list of 50,000 or so numbers that effectively give the probabilities for each of the possible “fill-in” words. And once again, to find an embedding, we want to “intercept” the “insides” of the neural net just before it “reaches its conclusion”—and then pick up the list of numbers that occur there, and that we can think of as “characterizing each word”.

我们如何为神经网络设置这个问题?归根结底,我们必须用数字来表达一切。实现这一目标的一种方法就是为英语中大约 50000 个常用单词中的每一个分配一个唯一的数字。例如,“the”可能是 914,“cat”(前面有一个空格)可能是 3542。(这些实际上是 GPT-2 使用的数字。)所以对于“the ___ cat”问题,我们的输入可能是{914, 3542}。输出应该是什么样的呢?嗯,它应该是一个包含大约 50000 个数字的列表,有效地给出每个可能的“填空”单词的概率。再次强调,要找到嵌入,我们希望在神经网络“得出结论”之前的某个时刻“拦截”它的“内部”,然后获取那里出现的数字列表,我们可以认为这个列表是“描述每个单词”的。

OK, so what do those characterizations look like? Over the past 10 years there’ve been a sequence of different systems developed (word2vec, GloVe, BERT, GPT, …), each based on a different neural net approach. But ultimately all of them take words and characterize them by lists of hundreds to thousands of numbers.

那么,这些描述看起来是什么样的呢?在过去的 10 年里,已经有一系列不同的系统(word2vec、GloVe、BERT、GPT等)被开发出来,每一个都基于不同的神经网络方法。但最终,它们都会将单词表示为包含数百到数千个数字的列表。

In their raw form, these “embedding vectors” are quite uninformative. For example, here’s what GPT-2 produces as the raw embedding vectors for three specific words:

在其原始形式下,这些“嵌入向量”并不包含太多信息。例如,这是 GPT-2 对三个特定单词生成的原始嵌入向量:

5941fff52d2188fee5bd848ec422484c.png

If we do things like measure distances between these vectors, then we can find things like “nearnesses” of words. Later we’ll discuss in more detail what we might consider the “cognitive” significance of such embeddings. But for now the main point is that we have a way to usefully turn words into “neural-net-friendly” collections of numbers.

如果我们测量这些向量之间的距离,那么我们可以找到诸如单词之间的“接近度”。稍后我们将更详细地讨论这种嵌入的“认知”意义。但目前最主要的一点是,我们有一种方法可以将单词有效地转换成适合神经网络的数字集合。

But actually we can go further than just characterizing words by collections of numbers; we can also do this for sequences of words, or indeed whole blocks of text. And inside ChatGPT that’s how it’s dealing with things. It takes the text it’s got so far, and generates an embedding vector to represent it. Then its goal is to find the probabilities for different words that might occur next. And it represents its answer for this as a list of numbers that essentially give the probabilities for each of the 50,000 or so possible words.

实际上,我们不仅可以通过数字集合来描述单词,还可以用它们来描述单词序列,甚至整个文本块。在 ChatGPT 中,就是这样处理事物的。它接收到目前为止的文本,并生成一个嵌入向量来表示它。然后它的目标是找到接下来可能出现的不同单词的概率。它将这个答案表示为一个数字列表,这个列表基本上给出了大约 50000 个可能单词的概率。

(Strictly, ChatGPT does not deal with words, but rather with “tokens”—convenient linguistic units that might be whole words, or might just be pieces like “pre” or “ing” or “ized”. Working with tokens makes it easier for ChatGPT to handle rare, compound and non-English words, and, sometimes, for better or worse, to invent new words.)

(严格来说,ChatGPT 处理的不是单词,而是“标记”——便捷的语言单位,可能是整个单词,也可能仅仅是像“pre”、“ing”或“ized”这样的部分。使用标记使 ChatGPT 更容易处理罕见、复合和非英语单词,有时候,或好或坏地,创造新词。)

0e77829b1e92d96dc3b9f8ba8e087ddd.jpeg

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

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

快速实现一个div的水平垂直居中

效果 实现 给父盒子宽高和flex&#xff0c;子盒子margin&#xff1a;auto 代码 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-sc…

No112.精选前端面试题,享受每天的挑战和学习

文章目录 说一说JavaScript有几种方法判断变量的类型&#xff1f;说一说defer和async区别&#xff1f;HTTP&#xff08;超文本传输协议&#xff09;是什么&#xff1f;说一下浏览器输入URL发生了什么&#xff1f;一只青蛙一次可以跳上1级台阶&#xff0c;也可以跳上2级。求该青…

rest api client code generator

一、搜索&#xff1a;REST API Client Code Generator 二、 安装成功后 配置java环境和node环境

软件使用 | jupyter notebook 使用技巧大全

本文记录使用 jupyter notebook 的使用方法。 更新&#xff1a;2023 / 8 / 6 软件使用 | jupyter notebook 使用技巧大全 图片表格参考链接 图片 插入图片并控制大小和对其方式 1: <img src"https://www.domain.com/image_file_name.jpg" alt"ImageFile&…

MFC第二十八天 WM_SIZE应用,CFrameWnd类LoadFrame的方法,PreCreateWindow窗口预处理,Frame-view窗口视图

文章目录 WM_SIZE应用通过WM_SIZE消息实现窗口布局管理通过控件属性实现窗口布局管理 CFrameWnd类CFrameWnd类简介OnCreate和OnCreateClient的方法注册时的要素与窗口设置PreCreateWindow创建窗口的预处理函数 附录预处理函数的结构体CFrameWnd::LoadFrame与CreateFrame WM_SIZ…

程序环境和预处理(含C语言程序的编译+链接)--2

文章前言&#xff1a; 上章我们把 程序的翻译环境 程序的执行环境 C语言程序的编译链接 预定义符号介绍 预处理指令 #define 宏和函数的对比 预处理操作符 #和##的介绍 的相关知识进行了梳理讲解&#xff0c;接下来被把剩余知识 命令定义 …

机器学习:训练集与测试集分割train_test_split

1 引言 在使用机器学习训练模型算法的过程中&#xff0c;为提高模型的泛化能力、防止过拟合等目的&#xff0c;需要将整体数据划分为训练集和测试集两部分&#xff0c;训练集用于模型训练&#xff0c;测试集用于模型的验证。此时&#xff0c;使用train_test_split函数可便捷高…

数字孪生的「三张皮」问题:数据隐私、安全与伦理挑战

引言 随着数字化时代的来临&#xff0c;数据成为了当今社会的宝贵资源。然而&#xff0c;数据的广泛使用也带来了一系列隐私、安全与伦理挑战。数字孪生作为一种虚拟的数字化实体&#xff0c;通过收集和分析大量数据&#xff0c;模拟和预测现实世界中的各种情境&#xff0c;为…

【Jenkins】Jenkins 安装

Jenkins 安装 文章目录 Jenkins 安装一、安装JDK二、安装jenkins三、访问 Jenkins 初始化页面 Jenkins官网地址&#xff1a;https://www.jenkins.io/zh/download/ JDK下载地址&#xff1a;https://www.oracle.com/java/technologies/downloads/ 清华源下载RPM包地址&#xff…

简单认识ELK日志分析系统

一. ELK日志分析系统概述 1.ELK 简介 ELK平台是一套完整的日志集中处理解决方案&#xff0c;将 ElasticSearch、Logstash 和 Kiabana 三个开源工具配合使用&#xff0c; 完成更强大的用户对日志的查询、排序、统计需求。 好处&#xff1a; &#xff08;1&#xff09;提高安全…

【每天40分钟,我们一起用50天刷完 (剑指Offer)】第四十八天 48/50【字符串处理】【最低公共祖先】

专注 效率 记忆 预习 笔记 复习 做题 欢迎观看我的博客&#xff0c;如有问题交流&#xff0c;欢迎评论区留言&#xff0c;一定尽快回复&#xff01;&#xff08;大家可以去看我的专栏&#xff0c;是所有文章的目录&#xff09;   文章字体风格&#xff1a; 红色文字表示&#…

DQN原理和代码实现

参考&#xff1a;王树森《强化学习》书籍、课程、代码 1、基本概念 折扣回报&#xff1a; U t R t γ ⋅ R t 1 γ 2 ⋅ R t 2 ⋯ γ n − t ⋅ R n . U_tR_t\gamma\cdot R_{t1}\gamma^2\cdot R_{t2}\cdots\gamma^{n-t}\cdot R_n. Ut​Rt​γ⋅Rt1​γ2⋅Rt2​⋯γn−…

基于 APN 的 CXL 链路训练

&#x1f525;点击查看精选 CXL 系列文章&#x1f525; &#x1f525;点击进入【芯片设计验证】社区&#xff0c;查看更多精彩内容&#x1f525; &#x1f4e2; 声明&#xff1a; &#x1f96d; 作者主页&#xff1a;【MangoPapa的CSDN主页】。⚠️ 本文首发于CSDN&#xff0c…

Dockerfile构建mysql

使用dockerfile构建mysql详细教学加案例 Dockerfile 文件 # 使用官方5.6版本&#xff0c;latest为默认版本 FROM mysql:5.6 #复制my.cof至容器内 ADD my.cnf /etc/mysql/my.cof #设置环境变量 密码 ENV MYSQL_ROOT_PASSWORD123456my.cof 文件 [mysqld] character-set-server…

LNMP搭建

LNMP&#xff1a;目前成熟的企业网站的应用模式之一&#xff0c;指的是一套协同工作的系统和相关软件 能够提供静态页面服务&#xff0c;也可以提供动态web服务。 这是一个缩写 L linux系统&#xff0c;操作系统。 N nginx网站服务&#xff0c;也可也理解为前端&#xff0c…

企业计算机服务器中了locked勒索病毒怎么办,如何预防勒索病毒攻击

计算机服务器是企业的关键信息基础设备&#xff0c;随着计算机技术的不断发展&#xff0c;企业的计算机服务器也成为了众多勒索者的攻击目标&#xff0c;勒索病毒成为当下计算机服务器的主要攻击目标。近期&#xff0c;我们收到很多企业的求助&#xff0c;企业的服务器被locked…

uni-app、H5实现瀑布流效果封装,列可以自定义

文章目录 前言一、效果二、使用代码三、核心代码总结 前言 最近做项目需要实现uni-app、H5实现瀑布流效果封装&#xff0c;网上搜索有很多的例子&#xff0c;但是代码都是不够完整的&#xff0c;下面来封装一个uni-app、H5都能用的代码。在小程序中&#xff0c;一个个item渲染…

Godot 4 源码分析 - Path2D与PathFollow2D

学习演示项目dodge_the_creeps&#xff0c;发现里面多了一个Path2D与PathFollow2D 研究GDScript代码发现&#xff0c;它主要用于随机生成Mob var mob_spawn_location get_node(^"MobPath/MobSpawnLocation")mob_spawn_location.progress randi()# Set the mobs dir…

【机器学习】编码、创造和筛选特征

在机器学习和数据科学领域中&#xff0c;特征工程是提取、转换和选择原始数据以创建更具信息价值的特征的过程。假设拿到一份数据集之后&#xff0c;如何逐步完成特征工程呢&#xff1f; 文章目录 一、特性类型分析1.1 数值型特征1.2 类别型特征1.3 时间型特征1.4 文本型特征1.…

Android Studio安装AI编程助手Github Copilot

csdn原创谢绝转载 简介 文档链接 https://docs.github.com/en/copilot/getting-started-with-github-copilot 它是个很牛B的编程辅助工具&#xff0c;装它&#xff0c;快装它&#xff0e; 支持以下IDE: IntelliJ IDEA (Ultimate, Community, Educational)Android StudioAppC…
最新文章