1
我有一百万个标记句子的数据集,并用它通过最大熵来寻找情感。我使用斯坦福分类方法是相同的: -用java保存并加载训练过的斯坦福分类器
public class MaximumEntropy {
static ColumnDataClassifier cdc;
public static float calMaxEntropySentiment(String text) {
initializeProperties();
float sentiment = (getMaxEntropySentiment(text));
return sentiment;
}
public static void initializeProperties() {
cdc = new ColumnDataClassifier(
"\\stanford-classifier-2016-10-31\\properties.prop");
}
public static int getMaxEntropySentiment(String tweet) {
String filteredTweet = TwitterUtils.filterTweet(tweet);
System.out.println("Reading training file");
Classifier<String, String> cl = cdc.makeClassifier(cdc.readTrainingExamples(
"\\stanford-classifier-2016-10-31\\labelled_sentences.txt"));
Datum<String, String> d = cdc.makeDatumFromLine(filteredTweet);
System.out.println(filteredTweet + " ==> " + cl.classOf(d) + " " + cl.scoresOf(d));
// System.out.println("Class score is: " +
// cl.scoresOf(d).getCount(cl.classOf(d)));
if (cl.classOf(d) == "0") {
return 0;
} else {
return 4;
}
}
}
我的数据被标记为0或1。现在,每一个鸣叫整个数据集被读取,并正在采取了很多时间考虑数据集的大小。 我的查询是,有什么方法可以首先训练分类器,然后在推特的情绪被发现时加载它。我认为这种方法将花费更少的时间。纠正我,如果我错了。 以下链接提供了此功能,但JAVA API没有任何内容。 Saving and Loading Classifier 任何帮助,将不胜感激。
太谢谢你了 –