当前位置: 首页 > news >正文

Word Embeddings

Count-based Approach

在这里插入图片描述

Term-document matrix: Document vectors

Two ways to extract information from the matrix:

  1. Column-wise: a document is represented by a |V|-dim vector (V: vocabulary)
    在这里插入图片描述

Widely used in information retrieval:

  • find similar documents 查找類似的文件

    • Two documents that are similar will tend to have similar words
    • 在这里插入图片描述
  • find documents close to a query 查找附近的查詢的文件

    • Consider a query as a document
    • 在这里插入图片描述
  1. Row-wise: a word is represented by a |D|-dim vector (D: document set

在这里插入图片描述

Term-term matrix

we have seen it before (co-occurrence vectors): Count how many times a word u appearing with a word v
在这里插入图片描述

  • raw frequency is bad 原始頻率不良
    • Not all contextual words are equally important: of, a, … vs. sugar, jam, fruit… 並非所有上下文單詞同樣重要
    • Which words are important, which ones are not?
      • infrequent words are more important than frequent ones (examples?
      • ) 不頻繁的單詞比常見單詞更重要
      • correlated words are more important than uncorrelated ones (examples?)

→ weighing schemes (TF-IDF, PMI,…)

Weighing terms: TF-IDF (for term-document matrix)
  • tf (frequency count):
    t f ( t , d ) = log ⁡ 10 ( 1 + c o u n t ( t , d ) ) tf(t,d)=\log_{10}(1+count(t,d)) tf(t,d)=log10(1+count(t,d))

  • idf (inverse document frequency): popular terms (terms that appear in many documents) are down weighed
    t f ( t , d ) = log ⁡ 10 N d f ( t ) tf(t,d)=\log_{10}\frac{N}{df(t)} tf(t,d)=log10df(t)N

  • TF - IDF:
    t f − i d f ( t , d ) = t f ( t , d ) ∗ i d f ( t ) tf - idf(t,d) = tf(t,d) *idf(t) tfidf(t,d)=tf(t,d)idf(t)
    在这里插入图片描述

  • Many word pairs should have > 0 counts, but their corresponding matrix entries are 0s because of lacking data (data sparsity)
    → Laplace smoothing: adding 1 to every entry (pseudocount)

ProsCons
Simple and intuitiveWord/document vectors are sparse (dims are |V|, vocabulary size, or |D|, number of documents, often from 2k to 10k) → difficult for machine learning algorithms
Dimensions are meaningful (e.g., each dim is a document / a contextual word)

→ easy to debug and interpret (Think about Explainable AI)
How to represent word meaning in a specific context?
(From sparse vectors to dense vectors)->Employ dimensionality reduction (e.g., latent semantic analysis - LSA)
Use a different approach: prediction (coming up next)

Prediction-based Approach

Introduction to ANNs used to learn word embeddings

  • two major count-based approach methods:
    • term-document matrix 術語文檔矩陣
    • term-term matrix 術語矩陣
  • Raw frequency is bed
    • using weighing schemes to “correct” counts使用稱重方案
    • using smoothing to take into account “unseen” events使用平滑來考慮看不見的事件

Formalisation

Assumptions:
● each word w ∈ V is represented by a vector v ∈ R d (d is often smaller than 3k)
● there is a mechanism to compute the probability Pr (w|u 1 , u 2 , …, u l) of the event that a target word w appears in a context (u 1 , u 2 , …, u l ).

Task: find a vector v for each word w such that those probabilities are as high as
possible for each w and its context (u 1 , u 2 , …, u l ).

We use a neural network with parameters θ to compute the probability by minimizing the cross-entropy loss使用具有最小參數θ的神經網絡。透過最小化交叉熵損失來計算概率

L ( θ ) = − ∑ ( w , u 1 , … , u l ) ∈ D train log ⁡ Pr ⁡ ( w ∣ u 1 , … , u l ) L(\theta) = -\sum_{(w, u_1, \ldots, u_l) \in D_{\text{train}}} \log \Pr(w \mid u_1, \ldots, u_l) L(θ)=(w,u1,,ul)DtrainlogPr(wu1,,ul)

Bengio

在这里插入图片描述

CBOW:

CBOW 模型的工作原理
  1. 輸入 (Input Layer)

    • 給定一個目標詞 w t w_t wt ​,選取其 前 m 個詞後 m 個詞 作為上下文詞 (context words)
    • 這些詞會從詞嵌入矩陣 CCC 中查找對應的詞向量。
  2. 投影層 (Projection Layer)

    • 將這些上下文詞對應的詞向量取平均: y = average ( w t − 1 , . . . , w t − m , w t + 1 , . . . , w t + m ) y = \text{average}(w_{t-1}, ..., w_{t-m}, w_{t+1}, ..., w_{t+m}) y=average(wt1,...,wtm,wt+1,...,wt+m)
    • 這一步沒有非線性變換 (例如 ReLU 或 tanh),只是簡單的平均
  3. 輸出層 (Output Layer)

    • 計算該平均向量 y y y 與詞彙矩陣 W W W 的線性變換,並使用 softmax 來預測中心詞 wtw_twt​: P ( w t ∣ w t − 1 , . . . , w t − m , w t + 1 , . . . , w t + m ) = softmax ( W y ) P ( w t ​ ∣ w t − 1 ​ , . . . , w t − m ​ , w t + 1 ​ , . . . , w t + m ​ ) = s o f t m a x ( W y ) P(w_t | w_{t-1}, ..., w_{t-m}, w_{t+1}, ..., w_{t+m}) = \text{softmax}(Wy)P(wt​∣wt−1​,...,wt−m​,wt+1​,...,wt+m​)=softmax(Wy) P(wtwt1,...,wtm,wt+1,...,wt+m)=softmax(Wy)P(wtwt1​,...,wtm,wt+1​,...,wt+m)=softmax(Wy)
    • Softmax 的輸出是一個機率分佈,表示詞彙表 (vocabulary) 中每個詞作為中心詞的可能性。
CBOW 的特點
  1. 上下文到目標詞:它是從上下文詞預測中心詞(這與 Skip-gram 相反,Skip-gram 是用中心詞預測周圍的上下文詞)。
  2. 計算高效:由於使用平均詞向量,CBOW 計算速度通常比 Skip-gram 更快,尤其是在大語料庫上訓練時。
  3. 適合大規模語料庫:CBOW 在大語料庫下通常表現更穩定,適合訓練大詞彙的詞向量。
CBOW 在 NLP 任務中的影響
  • 詞向量學習:CBOW 提供了一種高效的方式來學習詞向量,後來影響了 GloVe、FastText 等模型的發展。
  • 語意計算:學到的詞向量可以用來計算詞語之間的語義相似性,例如餘弦相似度 (cosine similarity)
  • 下游應用:CBOW 訓練出的詞向量可以應用於 文本分類、情感分析、機器翻譯 等 NLP 任務。

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

CBOWSkip-gram
目标用上下文词预测中心词用中心词预测上下文词
计算速度慢(因为对每个中心词要预测多个上下文词)
适用场景大数据、大语料库小数据、小语料库
效果适合学习常见词的词向量在低频词的词向量学习上更优

word2vec

  • Skip-gram model
  • “a baby step in Deep Learning but a giant leap towards Natural Language Processing”
  • can capture linear relational meanings (i.e., analogy):
    • king - man + women = queen

在这里插入图片描述

在这里插入图片描述

Problems : biases (gender, ethnic, …)
  • Word embeddings are learned from data → they also capture biases implicitly appearing in the data
  • Gender bias:
    • “computer_programmer” is closer to “man” than “woman”
    • “homemaker” is closer to “woman” than “man”
  • Ethnic bias:
    • African-American names are associated with unpleasant words (more than European-American names)

  • → Debiasing embeddings is a hot (and very needed) research topic

Dealing with unknown words

  • Many words are not in dictionaries
  • New words are invented everyday
  • Solution 1: using a special token #UNK # for all unknown words
  • Solution 2: using characters/sub-words instead of words
    • Characters (c-o-m-p-u-t-e-r instead of computer)
    • Subwords (com-omp-mpu-put-ute-ter instead of computer)

Word embeddings in a specific context

  • The meaning of a word standing alone can be different than its meaning in a specific context
    • He lost all of his money when the bank failed.
    • He stood on the bank of Amstel river and thought about his future.
  • Solution: w |c = f (w, c)
  • Solution 1: f is continuous w.r.t. c (contextual embeddings, e.g., ELMO, BERT - next week)
  • Solution 2: f is discrete w.r.t. c (e.g., word sense disambiguation - coming up in the next video)

Summary

  • Prediction-based approaches require neural network models, which are not
    intuitive as count-based ones
  • Low dimensional vectors (about 200-400 dimensions)
    • Dimensions are not easy to interpret
  • Robust performance for NLP tasks

延伸:Word Embeddings 進化

  1. 靜態詞嵌入(Static Embeddings)

    • Word2Vec、GloVe、FastText
    • 缺點:一個詞的向量固定,不能根據不同上下文改變語義(如「bank」的不同意思)。
  2. 上下文敏感的詞嵌入(Contextualized Embeddings)

    • ELMo、BERT、GPT
    • 解決了詞義多義性(Polysemy)問題,能夠根據上下文動態調整詞向量。

Contextualised Word Embedding

Static map 靜態地圖

f trained on large corpus Based on co-occurrence of words
在这里插入图片描述

相关文章:

Word Embeddings

Count-based Approach Term-document matrix: Document vectors Two ways to extract information from the matrix: Column-wise: a document is represented by a |V|-dim vector (V: vocabulary) Widely used in information retrieval: find similar documents 查找類似…...

相机开发调中广角和焦距有什么不一样

在相机中,调整广角和调整焦距是两个不同的概念,它们的作用和实现方式也不同。以下是两者的详细对比和解释: 1. 调整广角 定义 广角是指相机的视野范围(Field of View, FOV)。调整广角实际上是调整相机的视野范围。更广的视野意味着可以捕捉到更多的场景内容(更宽的画面)…...

krpano学习笔记,端口修改,krpano二次开发文档,krpano三维div信息展示,krpano热点显示文字

一、修改krpano端口 .\tour_testingserver -port8085 &#xff0c;修改端口&#xff0c;指定启动时的端口 二、给krpano添加div展示信息 和场景一起转动&#xff0c;不是layer&#xff0c;layer是固定的&#xff0c;没啥用。 主要是onloaded里面的1个方法。 <action name…...

Jenkins 给任务分配 节点(Node)、设置工作空间目录

Jenkins 给任务分配 节点(Node)、设置工作空间目录 创建 Freestyle project 类型 任务 任务配置 Node 打开任务-> Configure-> General 勾选 Restrict where this project can be run Label Expression 填写一个 Node 的 Label&#xff0c;输入有效的 Label名字&#x…...

深入解析iOS视频录制(二):自定义UI的实现

深入解析 iOS 视频录制&#xff08;一&#xff09;&#xff1a;录制管理核心MWRecordingController 类的设计与实现 深入解析iOS视频录制&#xff08;二&#xff09;&#xff1a;自定义UI的实现​​​​​​​ 深入解析 iOS 视频录制&#xff08;三&#xff09;&#xff1a;完…...

跳表的C语言实现

跳表&#xff08;Skip List&#xff09;是一种基于链表的动态数据结构&#xff0c;用于实现高效的查找、插入和删除操作。它通过引入多级索引来加速查找过程&#xff0c;类似于多级索引的有序链表。跳表的平均时间复杂度为 O(logn)&#xff0c;在某些场景下可以替代平衡树。 以…...

Java Web开发实战与项目——Spring Security与权限管理实现

Web应用中&#xff0c;权限管理是系统安全的核心部分&#xff0c;确保用户只能访问他们被授权的资源。Spring Security是Spring框架中的一个安全框架&#xff0c;它提供了强大的认证和授权功能&#xff0c;用于实现用户认证和权限控制。本章节将详细讲解如何使用Spring Securit…...

单元测试方法的使用

import java.util.Date; import org.junit.Test; /** java中的JUnit单元测试* * 步骤:* 1.选中当前项目工程 --》 右键:build path --》 add libraries --》 JUnit 4 --》 下一步* 2.创建一个Java类进行单元测试。* 此时的Java类要求:①此类是公共的 ②此类提供一个公共的无参…...

VScode内接入deepseek包过程(本地部署版包会)

目录 1. 首先得有vscode软件 2. 在我们的电脑本地已经部署了ollama&#xff0c;我将以qwen作为实验例子 3. 在vscode上的扩展商店下载continue 4. 下载完成后&#xff0c;依次点击添加模型 5. 在这里可以添加&#xff0c;各种各样的模型&#xff0c;选择我们的ollama 6. 选…...

flink写入hdfs数据如何保证幂等的?

在 Flink 中使用 HDFS Connector 将数据写入 HDFS 时&#xff0c;保证幂等性是一个重要的需求&#xff0c;尤其是在数据可靠性要求较高的场景下。以下是详细介绍如何通过 Flink 和 HDFS 的特性以及一些设计上的优化来实现幂等性。 一、Flink 的 Checkpoint 机制 Flink 的 Chec…...

newgrp docker需要每次刷新问题

每次都需要运行 newgrp docker 的原因: 当用户被添加到 docker 组后&#xff0c;当前会话并不会立即更新组信息&#xff0c;因此需要通过 newgrp docker 切换到新的用户组以使权限生效 如果不想每次都手动运行 newgrp docker&#xff0c;可以在终端中配置一个自动刷新的脚本。…...

LM_Funny-2-01 递推算法:从数学基础到跨学科应用

目录 第一章 递推算法的数学本质 1.1 形式化定义与公理化体系 定理1.1 (完备性条件) 1.2 高阶递推的特征分析 案例&#xff1a;Gauss同余递推4 第二章 工程实现优化技术 2.1 内存压缩的革新方法 滚动窗口策略 分块存储技术 2.2 异构计算加速方案 GPU并行递推 量子计…...

WDM_OTN_基础知识_波分站点与组网类型

为了便于理解&#xff0c;我们用高铁来打个比方&#xff0c;这是郑州与武汉的高铁&#xff0c;中间经过了许昌孝感等很多个站点&#xff0c;郑州武汉作为始发站和终点站&#xff0c;所有人员都是上车或下车&#xff0c;而许昌等中间站点&#xff0c;既有人员上下车&#xff0c;…...

机器视觉--索贝尔滤波

引言 在图像处理领域&#xff0c;边缘检测是一项至关重要的任务&#xff0c;它能够帮助我们识别图像中不同区域的边界&#xff0c;为后续的目标识别、图像分割等操作奠定基础。索贝尔滤波&#xff08;Sobel Filter&#xff09;作为一种经典的边缘检测算法&#xff0c;因其简单…...

网络分析仪E5071C的回波损耗测量

回波损耗&#xff08;Return Loss&#xff09;是评估射频/微波元件&#xff08;如滤波器、天线、电缆等&#xff09;信号反射特性的关键参数&#xff0c;反映端口阻抗匹配性能。E5071C矢量网络分析仪&#xff08;VNA&#xff09;通过以下步骤实现高精度回波损耗测量&#xff1a…...

力扣-二叉树-98 验证二叉搜索树

思路 第一个特性&#xff0c;二叉搜索树的中序遍历是有序的&#xff0c;第二个特性&#xff0c;利用两个指针判断大小关系 代码 class Solution { public:TreeNode* pre NULL;bool isValidBST(TreeNode* root) {if(root NULL) return true;bool left isValidBST(root->…...

【动态规划】详解 0-1背包问题

文章目录 1. 问题引入2. 从 dfs 到动态规划3. 动态规划过程分析4. 二维 dp 的遍历顺序5. 从二维数组到一维数组6. 一维数组的遍历次序7. 背包的遍历顺序8. 代码总结9. 总结 1. 问题引入 0-1 背包是比较经典的动态规划问题&#xff0c;这里以代码随想录里面的例子来介绍下。总的…...

【Java线程池与线程状态】线程池分类与最佳实践

解析Java线程池与线程状态变化&#xff0c;结合运行机制与业务场景对照&#xff0c;帮助形成系统性知识。 一、线程池核心要素&#xff08;五维模型&#xff09; 采用「参数配置→处理流程→工作模式」三层递进结构 核心参数&#xff08;线程池DNA&#xff09; corePoolSiz…...

【小白学AI系列】NLP 核心知识点(八)多头自注意力机制

文章目录 **多头自注意力机制&#xff08;Multi-Head Self-Attention&#xff09;****核心概念** **1. 自注意力机制&#xff08;Self-Attention&#xff09;****2. 多头机制&#xff08;Multi-Head Attention&#xff09;****3. 为什么要用多头注意力机制&#xff1f;****4. 公…...

学习笔记——word中图目录、表目录 标题引用

目标1&#xff1a; 建立——图1-1 引用——图1-1 1在word文档中的引用——>插入题注 新建标签&#xff0c;然后命名为“图1-“。 点击确认&#xff0c;即可插入如图所示 图1- 1 春天 需要把图1-和后面那个1中间的空格删除&#xff0c;即 图1-1 春天 2怎么去引用这个“…...

业务系统对接大模型的基础方案:架构设计与关键步骤

业务系统对接大模型&#xff1a;架构设计与关键步骤 在当今数字化转型的浪潮中&#xff0c;大语言模型&#xff08;LLM&#xff09;已成为企业提升业务效率和创新能力的关键技术之一。将大模型集成到业务系统中&#xff0c;不仅可以优化用户体验&#xff0c;还能为业务决策提供…...

前端导出带有合并单元格的列表

// 导出async function exportExcel(fileName "共识调整.xlsx") {// 所有数据const exportData await getAllMainData();// 表头内容let fitstTitleList [];const secondTitleList [];allColumns.value.forEach(column > {if (!column.children) {fitstTitleL…...

spring:实例工厂方法获取bean

spring处理使用静态工厂方法获取bean实例&#xff0c;也可以通过实例工厂方法获取bean实例。 实例工厂方法步骤如下&#xff1a; 定义实例工厂类&#xff08;Java代码&#xff09;&#xff0c;定义实例工厂&#xff08;xml&#xff09;&#xff0c;定义调用实例工厂&#xff…...

Hive 存储格式深度解析:从 TextFile 到 ORC,如何选对数据存储方案?

在大数据处理领域&#xff0c;Hive 作为 Hadoop 生态中重要的数据仓库工具&#xff0c;其存储格式的选择直接影响数据存储成本、查询效率和计算资源消耗。面对 TextFile、SequenceFile、Parquet、RCFile、ORC 等多种存储格式&#xff0c;很多开发者常常陷入选择困境。本文将从底…...

C++.OpenGL (14/64)多光源(Multiple Lights)

多光源(Multiple Lights) 多光源渲染技术概览 #mermaid-svg-3L5e5gGn76TNh7Lq {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-3L5e5gGn76TNh7Lq .error-icon{fill:#552222;}#mermaid-svg-3L5e5gGn76TNh7Lq .erro…...

Docker 本地安装 mysql 数据库

Docker: Accelerated Container Application Development 下载对应操作系统版本的 docker &#xff1b;并安装。 基础操作不再赘述。 打开 macOS 终端&#xff0c;开始 docker 安装mysql之旅 第一步 docker search mysql 》〉docker search mysql NAME DE…...

PostgreSQL——环境搭建

一、Linux # 安装 PostgreSQL 15 仓库 sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{rhel})-x86_64/pgdg-redhat-repo-latest.noarch.rpm# 安装之前先确认是否已经存在PostgreSQL rpm -qa | grep postgres# 如果存在&#xff0…...

WebRTC从入门到实践 - 零基础教程

WebRTC从入门到实践 - 零基础教程 目录 WebRTC简介 基础概念 工作原理 开发环境搭建 基础实践 三个实战案例 常见问题解答 1. WebRTC简介 1.1 什么是WebRTC&#xff1f; WebRTC&#xff08;Web Real-Time Communication&#xff09;是一个支持网页浏览器进行实时语音…...

Golang——7、包与接口详解

包与接口详解 1、Golang包详解1.1、Golang中包的定义和介绍1.2、Golang包管理工具go mod1.3、Golang中自定义包1.4、Golang中使用第三包1.5、init函数 2、接口详解2.1、接口的定义2.2、空接口2.3、类型断言2.4、结构体值接收者和指针接收者实现接口的区别2.5、一个结构体实现多…...

协议转换利器,profinet转ethercat网关的两大派系,各有千秋

随着工业以太网的发展&#xff0c;其高效、便捷、协议开放、易于冗余等诸多优点&#xff0c;被越来越多的工业现场所采用。西门子SIMATIC S7-1200/1500系列PLC集成有Profinet接口&#xff0c;具有实时性、开放性&#xff0c;使用TCP/IP和IT标准&#xff0c;符合基于工业以太网的…...