2016-07-14 156 views
0

StanfordNPP(以及德国模块)相当成功的开始之后,我尝试对数字数据进行分类。这也退出了良好的结果。使用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获得的单词/标记。这可能吗?

感谢您的任何答案!

回答

0

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

修改您的属性被应用到文本如下列:

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

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

+0

非常感谢,我会尝试无论是在接下来的日子里。 – Christian

+0

对不起,但是使用第2列而不是1会导致异常:“java.lang.RuntimeException:错误:行对于指定属性需要3列的制表符分隔列(2)太少:abc def [... ]“看起来我应该读你链接手册。 – Christian

+0

查看http://grepcode.com/file/repo1.maven.org/maven2/edu.stanford.nlp/stanford-corenlp/3.5中引发此异常的源代码。2/edu/stanford/nlp/classify/ColumnDataClassifier.java,输入内容可能有误。你有只有两列,由标签分隔?数据本身没有标签?我真的建议通过维基工作,它展示了如何逐步使用斯坦福NLP分类器。 – tkja

0

编号是正确的,您不必将2放在行首,就像其他答案所述。 1代表第一个数据列,不适用于您的培训文件(这是类别)中一般的第一列。 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