使用机器学习并设计为客户端-服务器架构的文本分类引擎
项目描述
OpenTC 是一个使用机器学习的文本分类引擎。它被设计为客户端-服务器架构,并使用 python 库 scikit-learn 和 tensorflow 进行机器学习算法。目前支持以下算法:
朴素贝叶斯
支持向量机
卷积神经网络
未来它还将支持来自 Facebookresearch 的 FastText。
引擎作为服务器运行,侦听要分类的命令和文本。默认情况下,它侦听 localhost 端口 3333,但可以在 yaml 配置文件中更改它。
例如,OpenTC 可用于文本分类(为此目的的演示网站可在线获得 OpenTC 演示),或用于其他目的,例如数据泄漏预防 (DLP)。DLP 的实施示例已创建为 ICAP 服务器: opentc-icap
要求
Python 3.x
麻木的
解析
PyYAML
scikit-学习
scipy
张量流 1.x
如何使用
安装
使用 pip 安装模块:
$ pip install opentc
或克隆存储库
$ git clone https://github.com/cahya-wirawan/opentc.git $ cd opentc $ python setup.py install
开放式
概要
开放式
描述
根据配置文件中定义的数据集训练应用程序的命令行。训练结果(预训练数据)可用于 opentcd 服务器。
用法
$ python opentc -h
usage: opentc [-h] [-c CLASSIFIER] [-C CONFIGURATION_FILE] [-d DATASET]
[-l LOG_CONFIGURATION_FILE]
optional arguments:
-h, --help show this help message and exit
-c CLASSIFIER, --classifier CLASSIFIER
set classifier to use for the training (support
currently bayesian, svm or cnn)
-C CONFIGURATION_FILE, --configuration_file CONFIGURATION_FILE
set the configuration file
-d DATASET, --dataset DATASET
set dataset to use for the training
-l LOG_CONFIGURATION_FILE, --log_configuration_file LOG_CONFIGURATION_FILE
set the log configuration file
opentcd
概要
opentcd
描述
守护程序在 TCP 端口(默认为 3333)上侦听传入连接,并根据需要对文件或文本字符串进行分类。它按以下顺序读取配置文件:./opentc.yml、~/.opentc/opentc.yml 或 /etc/opentc/opentc.yml。
用法
Opentcd 使用配置文件 opentc.yml 来定义所有可能的配置。在命令行选项中只能覆盖少数设置。
参数列表:
$ python opentcd -h
usage: opentcd [-h] [-a ADDRESS] [-C CONFIGURATION_FILE]
[-l LOG_CONFIGURATION_FILE] [-p PORT] [-t TIMEOUT]
optional arguments:
-h, --help show this help message and exit
-a ADDRESS, --address ADDRESS
define the address for the server
-C CONFIGURATION_FILE, --configuration_file CONFIGURATION_FILE
set the configuration file
-l LOG_CONFIGURATION_FILE, --log_configuration_file LOG_CONFIGURATION_FILE
set the log configuration file
-p PORT, --port PORT define the port number which the server uses to listen
-t TIMEOUT, --timeout TIMEOUT
define the time out
将其作为后台应用程序运行:
$ python opentcd& 2017-05-02 13:33:22,276 - opentc.core.classifier.cnn_text - DEBUG - Load the checkpoint: data/input/cnn_twenty_newsgroup_20170301_090000-all/checkpoints/model-2210 INFO:tensorflow:Restoring parameters from data/input/cnn_twenty_newsgroup_20170301_090000-all/checkpoints/model-2210 2017-05-02 13:33:23,899 - tensorflow - INFO - Restoring parameters from data/input/cnn_twenty_newsgroup_20170301_090000-all/checkpoints/model-2210 2017-05-02 13:33:27,375 - __main__ - INFO - Server start 2017-05-02 13:33:28,019 - opentc.core.server - INFO - Server loop running in thread: Thread-1
数据集和预训练数据
配置文件定义了数据集和预训练数据的路径。可以从data下载一个用于测试目的的预训练数据 ,大约 1.4GB。只需解压缩并相应地更改 opentc.yml 文件中预训练数据的路径即可。
命令
该命令使用换行符作为分隔符。如果 opentcd 无法识别该命令,或者该命令不符合下面指定的要求,它将回复错误消息,但仍等待下一个命令(此行为将来可以更改)。
平
检查服务器的状态。它应该回复“PONG”。
版本
打印程序版本
重新加载
重新加载引擎
LIST_CLASSIFIER
列出支持的分类器(目前支持三种分类器:贝叶斯、支持向量机和卷积神经网络)。它还显示分类器的状态,True(启用)或 False(禁用)。
SET_CLASSIFIER
启用或禁用特定分类器
PREDICT_STREAM
对文本流进行分类。它使用换行符作为每个句子的分隔符。
PREDICT_FILE
分类文件。它使用换行符作为每个句子的分隔符
关
关闭连接
去做
多标签分类
包括来自 Facebookresearch 的 FastText
将使用 pyzmq 和 google 的 protobuf 来改进协议和网络通信