构建停用词表

构建停用词表是数据预处理的必要步骤,可以减小不必要的开销。

哈工大、百度、川大等停用词表见GitHub链接:https://github.com/goto456/stopwords

经实验和观察证明,’cn_stopwords.txt‘文件的停用词大多是否定词:不、不是、不得,转折词:就算、即使、但是等,这些词如果作为停用词去除的话,会改变原意。
比如:

  1. 我 不 喜欢 你 => 我 喜欢 你
  2. 就算他很坏,我也喜欢他 => 他 很坏 我 喜欢 他
  3. 他很坏,但是我喜欢他 => 他 很坏 我 喜欢 他

对于2,3,DL会认为前面是negative,后面是positive,实际上整句是positive,这样会影响网络的学习,尤其是CNN,只能提取短距离特征,‘他很坏’很大概率会被误认为是positive,进而影响后续的学习;如果保留‘就算’,那么‘就算他很坏’会被认为是positive,这是合理的,因为重点在于后半句。
因此,不考虑’cn_stopwords.txt‘作为停用词。
用python将三个词表合并、去重、写入txt:

import os

# 输入你要读取的目录
path='.\stopwords-master'
files = os.listdir(path)
print(files)
stopwords = []
for file in files:
    if file[-3:] == 'txt': # 也可以是md,xsl等
        # 逐行读取,然后再数组拼接;这里不能用append,append会将数组当成一个对象接在stopwords之后:[1,2,3,[1,2,3]]
        stopwords += ( [line.strip() for line in open(path+'\\'+file,encoding='UTF-8').readlines()] )
# 去重
stopwords = list(set(stopwords))
print(len(stopwords))
# 保存在Stopwords.txt
with open(path+'\\'+'StopWords.txt', 'w',encoding='utf-8') as f:
    for stopword in stopwords:
        f.write(stopword+"\n")
        

在这里插入图片描述

此外,人工筛选了一些我认为会影响分类结果的停用词,剩余1545个停用词。
百度云:https://pan.baidu.com/s/1M7gcSs_MGFlevMB8wRhUlw
提取码:qg4p

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐