TextGrocery短文本分类使用
来源:互联网 发布:英语朗读软件 编辑:程序博客网 时间:2024/04/28 20:23
TextGrocery是一个基于LibLinear和结巴分词的短文本分类工具,特点是高效易用,同时支持中文和英文语料。
GitHub项目链接
具体的使用可以参考:文档
1、安装
通过GitHub(最新版本)git clone https://github.com/2shou/TextGrocery.git --depth=1cd TextGrocerymake
2、通过pip(更稳定)
pip install tgrocery -i http://pypi.douban.com/simple (这是国内的镜像源)
3、样本数据: train_ch.txt
music:你想干什么music:星火燎原music:日出(live版)music:给我感觉(live版)music:High High High(live版)music:姊妹(live版)music:站在高岗上(live版)music:感应(live版)music:了不起(live版)poem:中秋夜poem:上堂开示颂poem:从军行poem:丹阳送韦参军poem:乌衣巷poem:出塞poem:别董大poem:剑客poem:兰溪棹歌why:大飞机为什么怕小鸟why:臭鼬怎么保护自己why:冬天_嘴里为什么冒白气why:春季天空中飘的小白花是什么why:冬天为什么会冻伤呢why:飞机驾驶员怎样知道飞机的飞行高度why:冬暖夏凉的井水qa:你老家在哪?qa:你从哪里来?qa:你爸爸呢?qa:你妈妈呢?qa:你爸爸对你好吗?qa:你妈妈对你好吗?
4、 部署一个server.py脚本
#-*- coding:utf-8 -*-import BaseHTTPServerimport urllibfrom tgrocery import Grocerygrocery = Grocery('hello')grocery.train('train_ch.txt',':')grocery.save()new_grocery = Grocery('hello')new_grocery.load()class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): '''处理请求并返回页面''' # 页面模板 Page = '''cccccc ''' # 处理一个GET请求 def do_GET(self): #print self.path.split('/')[-1] retText = classify(self.path.split('/')[-1]) print retText self.send_response(200) #self.send_header("Content-Type", "text/html") self.send_header('Content-Type', 'application/json') self.send_header("Content-Length", str(len(retText))) self.end_headers() self.wfile.write(retText)#----------------------------------------------------------------------def classify(text): input_txt = urllib.unquote(text) predict_result = new_grocery.predict(input_txt) output_txt = predict_result.predicted_y dict = predict_result.dec_values if dict[predict_result.predicted_y] < 0.15 : output_txt = '' return output_txt#----------------------------------------------------------------------if __name__ == '__main__':#启动: nohup python server.py > server.log 2>&1 & try: serverAddress = ('', 8181) server = BaseHTTPServer.HTTPServer(serverAddress, RequestHandler) server.serve_forever() except KeyboardInterrupt: print '^C received ,shutting down server'
5、访问:http://ip:8181/上堂开示颂
0 0
- TextGrocery短文本分类使用
- 短文本分类工具 TextGrocery
- 短文本Python库TextGrocery
- 短文本分类
- 短文本分类
- 短文本分类记录
- 短文本/Query分类算法特征选择
- 短文本/Query分类算法特征选择
- 短文本分类遇到的bug
- 用TextGrocery做文本分类
- 使用zlib库进行短文本压缩
- 基于CNN的短文本分类实验 PPT
- 常用消息短文本
- 短文本情感分析
- 最长&最短文本
- 短文本情感分析
- 短文本分类或lda的分析(ZZ)(转载pennyliang (pennyliang),)
- 深度学习Attention机制在短文本分类上的应用——qjzcy的博客
- 构图之法(二)
- [又值奥运季] 2016年里约奥运会--8月8日赛事
- 【杭电oj1869】六度分离
- 单链表实现
- 多线程下用Socket实现客户群聊的问题
- TextGrocery短文本分类使用
- 显式Intent和隐式Intent
- Android在MediaMuxer和MediaCodec录制视频示例 - audio+video
- web设计最佳实践核对清单
- Camera使用setPreviewCallbackWithBuffer优化内存
- iOS中几种设计模式
- JMeter学习(五)检查点
- Python 装饰器,@property 以及 Pycaffe.py
- [Golang]Map的一个绝妙特性