首页 > 其他 > 详细

Mallet的基本使用

时间:2015-01-05 02:09:13      阅读:313      评论:0      收藏:0      [点我收藏+]
【官网下载】

MALLET is a Java-based package for statistical natural language processing, document classification, clustering, topic modeling, information extraction, and other machine learning applications to text.

下载mallet包,注意里面已经含有了训练数据集
bubuko.com,布布扣
【准备测试】
(1)在bin\mallet.bat里面第33行左右的位置加入
if "%CMD%"=="classify-file" set CLASS=cc.mallet.classify.tui.Csv2Classify
if "%CMD%"=="classify-dir" set CLASS=cc.mallet.classify.tui.Text2Classify
?CMD命令行进入解压目录,如 C:\mallet-2.0.7
(2)文本分类

1.?将源文件格式转换为mallet自己的处理格式

C:\mallet-2.0.7 >bin\mallet import-dir --input D:\testfile --output D:\classify-input.mallet

?

2.使用mallet算法库中的NaiveBayes算法训练获得分类器

C:/mallet>bin\mallet train-classifier --input D:\classify-input.mallet --trainer NaiveBayes --training-portion 0.8 --output-classifier D:\classifier1.classifier  

--input参数的值classify-input.mallet?是第 一步中生成的特征向量

--trainer参数的值NaiveBayes?是指训练分类器的算法,可以指定其他算法,例如?MaxEnt等?

--training-portion?参数的值这里是0.8?, 可以根据需要设定,0.8?的意思是随机抽取classify-input.mallet?数据中的80%?当训练数据,剩下的当测试数据,用于测试已训练好的分类器的准确性等等性能指标。

--output-classifier?参数的值classifier1.classifier?是所存已训练好的分类器的名称。

?

3.使用分类器测试新数据集

C:/mallet>bin\mallet classify-file --input D:\text.txt --output - --classifier D:\classifier1.classifier

--output?后面参数值“-?”意思是直接在命令行中输出所属各个类别的概率,也可以是”D:\result_file.txt“。

--classifier?参数的值是指使用的分类器名称(即,训练好的分类器)。

?

(3)主题建模

1. 将训练集转换为mallet专用格式

C:/mallet>bin\mallet import-dir --input D:\sample-data\topic-input --output D:\topic-input.mallet --keep-sequence --remove-stopwords

?--keep-sequence?参数必须有,否则会出错,因为主题建模时所用数据源就是特征序列,而不是特征向量,所以必须用--keep-sequence?此参数 来限制转换数据的格式。

--remove-stopwords?的意思是移除停用词。

?

2. 训练主题

C:/mallet>bin\mallet train-topics --input D:\topic-input.mallet --num-topics 2 --output-doc-topics D:\docstopics.txt --inferencer -filename D:\infer1.inferencer

--num-topics?的值2?意思是限定主题个数为2,默认的主题数为10

--output-doc-topics?参数的意思是输出文档-?主题矩阵,存到docstopics文件中

--inferencer?-filename?参数的意思是对将训练好的主题模型进行存储,此主题模型存到参数值infer1.inferencer

?

3.测试集

C:/mallet>bin\mallet import-dir --input D:\sample-data\data --output D:\topic-test.mallet --keep-sequence  --remove-stopwords

?

4.获得测试集的主题类别

C:/mallet>bin\mallet infer-topics --input D:\topic-test.mallet --inferencer D:\infer1.inferencer --output-doc-topics D:\testdocstopics.txt

?

【参考博客】

Mallet 使用说明
mallet使用笔记(学topic model、做文本分类等)

Mallet的基本使用

原文:http://java--hhf.iteye.com/blog/2172535

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!