(done) NLP “bag-of-words“ 方法 (带有二元分类和多元分类两个例子)词袋模型、BoW

news/2025/2/18 11:30:03/

一个视频:https://www.bilibili.com/video/BV1mb4y1y7EB/?spm_id_from=333.337.search-card.all.click&vd_source=7a1a0bc74158c6993c7355c5490fc600

这里有个视频,讲解得更加生动形象一些

总得来说,词袋模型(Bow, bag-of-words) 是最简单的 “文本 —> 矢量”(把文本转为矢量) 模型

二元分类和多元分类的两个例子放在末尾


以下是 Claude3 的解释,我们慢慢看


The bag-of-words model is a simplifying representation used in natural language processing (NLP). In this representation, a text (such as a sentence or a document) is represented as an unordered collection of words, disregarding grammar and word order.

bag-of-words 模型是 NLP领域 里的一个简化表示方法。在这种表示方法里,一个文本(比如一个句子或者是一个文档) 会被表示成一个乱序的单词集合,无视里面的语法和单词顺序。


Here’s how it works:

  1. A vocabulary of known words is created from the corpus of texts.
  2. Each text is represented as a vector, with one dimension for each word in the vocabulary.
  3. If a word appears in the text, its value in the vector is non-zero (typically 1 or a number representing frequency); otherwise, it is zero.

For example, if the vocabulary is [“hello”, “goodbye”, “computer”], then the sentence “hello hello computer” would be represented by the vector [2, 0, 1].

如下,是 bag-of-words 的工作方法:

  1. 一堆已知单词的词汇表是从语料库里创建出来的
  2. 每一个文本都可以使用一个向量表示,词汇表中的每一个单词都可以使用一个一维向量来表示
  3. 如果一个单词在文本中出现,它在矢量中的值是 non-zero,否则就是 0。

举个例子,如果词汇表是 [“hello”, “goodbye”, “computer”],那么这句 “hello hello computer” 就可以用矢量 [2, 0, 1] 表示


The advantages of this model are its simplicity and the fact that it allows for straightforward application of techniques from fields like machine learning and information retrieval.

However, the bag-of-words model has several shortcomings:

  1. It disregards word order and grammar, which can be very important in natural language.
  2. It assumes that all words are equally important, ignoring semantics.
  3. For large vocabularies, the resulting vector can be very high-dimensional and sparse.

Despite these limitations, the bag-of-words model can serve as a baseline for more advanced NLP techniques and may still have some uses in simple applications.

这个模型的优点是:很简单,并且它允许直接应用来自机器学习和信息检索等领域的技术。

然而,bag-of-words 模型也有几个缺点:

  1. 它忽略了单词的顺序和语法结构,而这在自然语言中是非常重要的。 (单词向量无法展示单词顺序和语法结构)
  2. 它假设所有单词同等重要,忽视了词义语义信息。 (假设所有单词同等重要)
  3. 对于大型词汇表,生成的向量往往是非常高维且稀疏的。 (大型词汇表中,向量高维且稀疏)

尽管有这些限制,bag-of-words 模型仍然可以作为一些先进的 NLP技术的 baseline,并且在一些简单的应用中都是有用例的


In modern NLP systems, more advanced techniques like word embeddings (e.g., Word2Vec, GloVe, BERT) are commonly used to capture richer semantic and syntactic information.

在现代NLP系统中,通常采用更先进的技术,如词嵌入(例如Word2Vec、GloVe、BERT)来捕获更丰富的语义和语法信息。


二元分类和多元分类的两个例子放在末尾

二元分类:
在这里插入图片描述

多元分类:
在这里插入图片描述


http://www.ppmy.cn/news/1386045.html

相关文章

Acwing-基础算法课笔记之动态规划(区间DP)

Acwing-基础算法课笔记之动态规划(区间DP) 一、石子合并1、定义2、闫氏DP分析法3、模拟过程4、代码示例 一、石子合并 1、定义 设有 N N N堆石子排成一排,其编号为 1 1 1, 2 2 2, 3 3 3,…, N…

【.net/.net core】使用System.Web.HttpUtility.UrlDecode处理web请求编码问题

问题场景:将数据已JSON字符串写入请求内容后,在接收端接收数据时,数据内容为URL编码后的内容,需要先将接收的字符串数据URL解码后才可转换为数据对象 解决办法:使用System.Web.HttpUtility.UrlDecode(string s)方法对…

Rust的async和await支持多线程运行吗?

Rust的async和await的异步机制并不是仅在单线程下实现的,它们可以在多线程环境中工作,从而利用多核CPU的并行计算优势。然而,异步编程的主要目标之一是避免不必要的线程切换开销,因此,在单线程上下文中,asy…

D. Tandem Repeats?

思路&#xff1a;首先我们要枚举长度&#xff0c;然后从前往后遍历&#xff0c;判断是否存在改长度的重复串。 代码&#xff1a; void solve(){string s;cin >> s;int n s.size();int ans 0;for(int len n / 2;len > 1;len --){int t 0;for(int i 0;i len <…

Elasticsearch:调整搜索速度

在我之前的文章 “Elasticsearch&#xff1a;如何提高查询性能” 及 “Elasticsearch&#xff1a;提升 Elasticsearch 性能” 里&#xff0c;我详细描述了如何提高搜索的性能。在今天的文章里&#xff0c;我从另外一个视角来描述如何调整搜索的速度。希望对大家有所帮助&#x…

SAP Activate项目管理方法论路线图

SAP Activate 是 SAP 推出的一种基于敏捷方法论的灵活、快速且引导式的实施方法论&#xff0c;专为加速SAP S/4HANA和其他SAP解决方案的部署而设计。这个方法论结合了最佳实践、引导配置和方法论本身的强大能力&#xff0c;以确保项目的快速实施和成功部署。SAP Activate的核心…

模型、算法、数据模型、模型结构是什么?它们之间有什么关联和区别?

模型、算法、数据模型、模型结构是什么&#xff1f;它们之间有什么关联和区别&#xff1f; 导读一、算法1、算法定义2、机器学习算法定义 二、模型1、模型定义2、数据模型定义3、机器学习模型定义 三、模型结构1、线性模型2、基于实例的模型3、决策树模型4、支持向量机5、集成方…

后端配置拦截器的一个问题【问题】

后端配置拦截器的一个问题【问题】 前言版权后端配置拦截器的一个问题问题解决 最后 前言 2024-3-14 00:07:28 以下内容源自《【问题】》 仅供学习交流使用 版权 禁止其他平台发布时删除以下此话 本文首次发布于CSDN平台 作者是CSDN日星月云 博客主页是https://jsss-1.blog…