【问题标题】:Text classifier with word splitting using StanfordNLP classifier使用 StanfordNLP 分类器进行分词的文本分类器
【发布时间】:2016-11-17 11:45:20
【问题描述】:

在相当成功地开始使用 StanfordNLP(以及德语模块)之后,我尝试对数值数据进行分类。这也以良好的结果退出。

至少我尝试设置一个分类器来对文本文档(邮件和扫描文档)进行分类,但这很令人沮丧。我想要做的是使用基于单词的分类器,而不是使用 n-gram。我的培训文件有两列:第一列是文本的类别,第二列是文本本身,没有制表符或换行符。

属性文件有以下内容:

1.splitWordsWithPTBTokenizer=true
1.splitWordsRegexp=false
1.splitWordsTokenizerRegexp=false
1.useSplitWords=true

但是当我开始像这样训练分类器时......

    ColumnDataClassifier cdc = new ColumnDataClassifier("classifier.properties");
    Classifier<String, String> classifier =
        cdc.makeClassifier(cdc.readTrainingExamples("data.train"));

...然后我得到许多以以下提示开头的行:

[main] INFO edu.stanford.nlp.classify.ColumnDataClassifier - Warning: regexpTokenize pattern false didn't match on 

我的问题是:

1) 知道我的属性有什么问题吗?我想,我的训练文件还可以。

2) 我想将我从 CoreNLP 获得的单词/标记与德语模型一起使用。这可能吗?

感谢您的任何回答!

【问题讨论】:

    标签: java classification stanford-nlp text-classification


    【解决方案1】:

    编号是正确的,您不必将 2 放在行首,正如另一个答案所述。 1 代表第一个 data 列,而不是训练文件中的第一列(即类别)。开头带有 2. 的选项将用于第二个数据列,或者训练文件中的第三列 - 您没有。

    我不知道如何使用您从 CoreNLP 获得的单词/标记,但我也花了一些时间来了解如何使用单词 n-gram,所以也许这对某些人会有所帮助:

    # regex for splitting on whitespaces
    1.splitWordsRegexp=\\s+
    
    # enable word n-grams, just like character n-grams are used
    1.useSplitWordNGrams=true
    
    # range of values of n for your n-grams. (1-grams to 4-grams in this example)
    1.minWordNGramLeng=1
    1.maxWordNGramLeng=4
    
    # use word 1-grams (just single words as features), obsolete if you're using
    # useSplitWordNGrams with minWordNGramLeng=1
    1.useSplitWords=true
    
    # use adjacent word 2-grams, obsolete if you're using
    # useSplitWordNGrams with minWordNGramLeng<=2 and maxWordNGramLeng>=2
    1.useSplitWordPairs=true
    
    # use word 2-grams in every possible combination, not just adjacent words
    1.useAllSplitWordPairs=true
    
    # same as the pairs but 3-grams, also not just adjacent words
    1.useAllSplitWordTriples=true
    

    更多信息请查看http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/classify/ColumnDataClassifier.html

    【讨论】:

      【解决方案2】:

      你是说你的训练文件有两列,第一列是文本的类别,第二列是文本本身。基于此,您的属性文件不正确,因为您将规则添加到那里的第一列。

      修改你的属性以应用于文本如下的列:

      2.splitWordsWithPTBTokenizer=true
      2.splitWordsRegexp=false
      2.splitWordsTokenizerRegexp=false
      2.useSplitWords=true
      

      此外,我建议通过Software/Classifier/20 Newsgroups wiki 工作,这显示了一些有关如何使用斯坦福分类器以及如何通过属性文件设置选项的实际示例。

      【讨论】:

      • 非常感谢,我会在接下来的几天里尝试一下。
      • 抱歉,但是使用列号 2 而不是 1 会导致异常:“java.lang.RuntimeException: 错误:对于指定属性所需的 3 列,行的制表符分隔列 (2) 太少:abc def [...]" 看起来我应该阅读你链接的手册。
      • 查看grepcode.com/file/repo1.maven.org/maven2/edu.stanford.nlp/… 引发此异常的源代码,您的输入可能有问题。你只有两列,用制表符分隔吗?数据本身没有标签?我真的建议通过 wiki 工作,它展示了如何逐步使用斯坦福 NLP 分类器。
      猜你喜欢
      • 2016-09-25
      • 1970-01-01
      • 2020-01-19
      • 2013-02-22
      • 2014-05-12
      • 2012-04-02
      • 2017-07-10
      • 1970-01-01
      相关资源
      最近更新 更多