【问题标题】:Stanford Classifier producing wrong results斯坦福分类器产生错误的结果
【发布时间】:2021-10-04 10:35:51
【问题描述】:

我正在尝试使用Stanford Classifier 执行基本的文本分类。我的示例数据集基于Ham or Spam。

这是我的代码:

Properties props = new Properties();
ColumnDataClassifier cdc = new ColumnDataClassifier(props);

Classifier<String, String> cl = cdc.makeClassifier(cdc.readTrainingExamples("data.train"));

for (String line : ObjectBank.getLineIterator("data.test", "utf-8")) {
    Datum<String, String> d = cdc.makeDatumFromLine(line);
    System.out.println(line + "  ==>  " + cl.classOf(d));
}

但是,无论我尝试分类什么文本,它总是将其分类为 Ham。下面这句话明明是Spam,还是归类为Ham:

免费消息通过回复此消息并使用“免费”一词激活您的 500 条免费短信。有关条款和条件,请访问www.example.com

我的错误在哪里?

【问题讨论】:

  • 存在一些错误这一事实并不奇怪,但还有一个更严重的问题,因为它预测了带有多数标签的每个实例。首先,您可以检查训练数据是否被正确解释,即每个实例都有它应该在readTrainingExamples 之后具有的标签。我的猜测是那里出了点问题,也许格式不是函数所期望的。还有训练集大小的问题:如果太小,分类器可能会一直默认为多数类。

标签: java machine-learning stanford-nlp text-classification


【解决方案1】:

我的错误是我没有提供任何属性:

Properties props = new Properties();
ColumnDataClassifier cdc = new ColumnDataClassifier(props);

您可以直接在代码中指定属性:

// set up pipeline properties
Properties props = new Properties();
// set the list of annotators to run
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,depparse,coref,kbp,quote");
// set a property for an annotator, in this case the coref annotator is being set to use the neural algorithm
props.setProperty("coref.algorithm", "neural");

或者你可以提供一个属性文件:

ColumnDataClassifier cdc = new ColumnDataClassifier(propFile);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-04
    • 2015-11-12
    • 1970-01-01
    • 2015-03-10
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多