Git Product home page Git Product logo

carrychang / c-cnn-for-chinese-sentiment-analysis Goto Github PK

View Code? Open in Web Editor NEW
40.0 1.0 14.0 21.4 MB

基于字符级卷积神经网络的细粒度的中文情感分析以及具体的应用,将顾客打分和评论情感进行两极映射,使用数据自动标注和基于弱监督预训练的数据增强方式自动扩充和优化数据集,实验证实了在情感分类中,使用本文的字符级卷积神经网络(C-CNN-SA)可以在不依赖分词的情况下,达到的精度和 F 值均高于词级粒度。并将模型上线使用,利用tensoflow+flask restful做出的后端服务化,具体的项目细节和讲解看右面的ppt

Home Page: https://carrychang.github.io/C-CNN-for-Chinese-Sentiment-Analysis/

Python 0.63% HTML 99.35% Shell 0.02%
chinese-sentiment-analysis nlp-machine-learning flask-api-rest tensorflow-models backend

c-cnn-for-chinese-sentiment-analysis's Introduction

996.icu

C-CNN-for-Chinese-Sentiment-Analysis

一个简单的NLP项目(文本情感分析)的flask后端API,修改了全局model load的方式,增加了模型推理的速度,使用nginx搭配Gunicorn启动Flask,使用虚拟环境搭配sh的启动方式,可以直接对model进行一键重启,并有错误日志监控

支持一键sh部署,flask配置见gun.py,情感分析属于毕业项目整理的一部分(整个项目为顾客意见挖掘)

使用方法

  1. 首先在服务器上部署虚拟环境 ,假设虚拟环境在/home,cd /home 进入home
  2. 在hoem文件夹中使用python3 -m venv v1创建虚拟环境,v1就是虚拟环境的名字,然后使用souce v1/bin/activate加载虚拟环境
  3. 在虚拟环境下使用pip install -r requirement.txt 安装所需要的库,然后使用chmod +777 restart.sh部署模型的后端
  4. 使用ip:8000/predict是post的地址,使用python C-CNN-SA-client.py即可模拟请求,注意模型第一次初始化的时间因为需要加载预训练模型,推理速度有些慢,目前单机单线曾运行的正常推理速度在100ms之内,多进程部署会继续提速

代码结构:使用前后分离的结构,完全使用Python实现

  1. C-CNN-SA-server.py表示后端的model api,直接通过get传参的形式进行,直接搭配nginx+Gunicorn部署即可
  2. C-CNN-SA-client.py表示模型前端的调用,传入用户的UGC内容,然后使用TextCNN的模型进行识别,模型第一次初始化的时间因为需要加载预训练模型,推理速度有些慢,目前单机单线曾运行的正常推理速度在100ms之内,多进程部署会继续提速

后端启动打印的log

前端启动打印的结果

Jupyter notebook 打印的结果

本地Pycharm输出的结果

基于字符级卷积神经的中文情感分析:

  1. 将顾客打分和评论情感进行两极映射,使用数据自动标注和基于弱监督预训练的数据增强方式自动扩充和优化数据集,实验证实了在情感分类中,使用本文的字符级卷积神经网络(C-CNN-SA)可以在不依赖分词的情况下,达到的精度和 F 值均高于词级粒度
  2. 在字符级向量化分类模型中,结果显示卷积神经网络在短文本情感分类中效果最好,字符级卷积神经网络在训练速度和效果上优势明显
  3. 模型的最后一层改写输出为积极标签的概率,这种输出方式符合情感强度的表达,即输出0.9位这段文字的情感强度,一般大于0.5即视为积极,数字越大,强度越强烈,反则反之,文本分数为0.1的则为消极情感,极性较强

c-cnn-for-chinese-sentiment-analysis's People

Contributors

carrychang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.