GithubHelp home page GithubHelp logo

romanshen / weibo-preprocess-toolkit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wansho/weibo-preprocess-toolkit

0.0 1.0 0.0 192 KB

Weibo Preprocess Toolkit

License: MIT License

Python 100.00%

weibo-preprocess-toolkit's Introduction

weibo-preprocess-toolkit

Weibo Preprocess Toolkit

Getting Started

Installation

pip install weibo-preprocess-toolkit

Tutorial

from weibo_preprocess_toolkit import WeiboPreprocess

preprocess = WeiboPreprocess()

test_weibo = "所以我都不喝蒙牛 #南京·大行宫[地点]#,一直不喜欢蒙牛。謝駿毅 赞[122]转发[11] [超话] 收藏09月11日 18:57 "

# traditional2simplified
print(preprocess.traditional2simplified(test_weibo))
# 所以我都不喝蒙牛 #南京·大行宫[地点]#,一直不喜欢蒙牛。谢骏毅 赞[122]转发[11] [超话] 收藏09月11日 18:57

# clean weibo with simplified Chinese
print(preprocess.clean(test_weibo))
# 所以我都不喝蒙牛 一直不喜欢蒙牛 谢骏毅

# clean weibo 
print(preprocess.clean(test_weibo, simplified=False))
# 所以我都不喝蒙牛 一直不喜欢蒙牛 謝駿毅

# seg weibo, keep stop words
print(preprocess.cut(test_weibo))
# ['所以', '我', '都', '不喝', '蒙牛', '#', '南京', '·', '大行宫', '[', '地点', ']', '#', ',', '一直', '不喜欢', '蒙牛', '。', '謝駿毅', '赞', '[', '122', ']', '转发', '[', '11', ']', '[', '超话', ']', '收藏', '09', '月', '11', '日', '18', ':', '57', '\xa0']

# seg weibo, don't keep stop words
print(preprocess.cut(test_weibo, keep_stop_word=False))
# ['都', '不喝', '蒙牛', '#', '南京', '·', '大行宫', '[', '地点', ']', '#', ',', '不喜欢', '蒙牛', '。', '謝駿毅', '赞', '[', '122', ']', '转发', '[', '11', ']', '[', '超话', ']', '收藏', '09', '月', '11', '日', '18', ':', '57', '\xa0']

# clean and cut weibo, keep_stop_words, simplified Chinese
print(preprocess.preprocess(test_weibo))
# 所以 我 都 不喝 蒙牛 一直 不喜欢 蒙牛 谢骏毅
print(preprocess.preprocess(test_weibo, simplified=False, keep_stop_word=False))
# 都 不喝 蒙牛 不喜欢 蒙牛 謝駿毅

Introduction

该工具用于微博文本的预处理:清洗 + 分词。

Inspiration

在中文 NLP 领域,文本清洗和分词对于模型的性能有着很大的影响,如果语料库和测试集/线上环境的文本清洗规则和分词工具不同,就会导致在语料库上训练出来的模型在测试集上效果很差。举例来说,语料库采用了清洗规则 Clean-A 和 分词工具 Seg-A 来清洗和分词微博,而用户在线上环境采用了另一种清洗规则 Clean-B 和另一种分词工具 Seg-B,那么线上环境就会产生很多不在语料库词典中的未登陆词(Unknown Words),这些未登陆词会导致预先训练好的模型,面对线上环境的另一种规则时,性能变差。

本人在对微博进行情感分析的过程中,总结了较多的微博清洗技巧和分词规则,并总结了一份微博情感分析词典用于优化 jieba 分词。所以我在这里尝试对微博的清洗和分词规则进行整理,同时也是为了保持语料库和线上环境的规则同步,为其他研究者和使用我的模型的人,提供一个和语料库匹配的清洗和分词规则。

Weibo Cleaning

本人对微博文本的清洗规则进行了整理,主要涉及到如下的规则:

  1. 中文繁体转简体
  2. 微博停用词规则1(正则表达式),包括 url, email, @某人, 地点,…… 等停用词规则
  3. 微博停用词规则2(正则表达式),包括 时间,数字和微博中常出现的无意义的词等停用词规则
  4. 微博特殊字符
  5. 其他细节处理

注意:考虑到停用词在词向量训练中衔接上下文的作用,本工具并没有对微博的停用词进行清洗

Weibo Seg

基于 jieba 分词对微博文本进行分词优化,优化的地方主要有两点:

  1. 扩种 jieba 分词词典,构建情感词典,优化情感分析的分词结果
  2. 对否定前缀词进行特殊处理

Dependencies

pip install jieba

Acknowledgment

jieba 结巴中文分词

nstools 中文繁体转简体

NTUSD 情感词典

哈工大停用词表

License

MIT

weibo-preprocess-toolkit's People

Contributors

wansho avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.