BoW - Bag of Words - 词袋模型

前言

BoW,全称Bag of Words,中文名称为词袋模型,最初被用在NLP的文本分类任务中,将文档表示成特征向量。

步骤

  1. 提取出文本独特的word,然后给每个word赋予一个one hot vector(只有一个维度为1,其他为0)即建立了一个词库。
  2. 根据词库,得到每个句子对应的特征向量。

优点

简单,方便。
新增一个词也比较方便。

不足

只关注了词出现的次数,并没有考虑其顺序。
当词库较大时,特征向量比较稀疏。

示例

文档1:John likes to watch movies. Mary likes too.
文档2:John also likes to watch football games.

Vocabulary = {“John”: 1, “likes”: 2,“to”: 3, “watch”: 4, “movies”: 5,“also”: 6, “football”: 7, “games”: 8,“Mary”: 9, “too”: 10}

特征向量:
文档1: [1, 2, 1, 1, 1, 0, 0, 0, 1, 1]
文档2: [1, 1,1, 1, 0, 1, 1, 1, 0, 0]

猜你喜欢

转载自blog.csdn.net/NSJim/article/details/125417685