0

我正在使用 Cleartk (V. 2.0) 简单管道为 CAS 中的单个句子开发二进制分类器。然而,即使生成了训练数据,分类器也不会在训练期间拾取它,见下文。

我正在处理这个例子,特别是这个代码片段:

AnalysisEngineFactory.createPrimitiveDescription(
    <name-of-your-cleartk-annotator>.class,
    CleartkAnnotator.PARAM_IS_TRAINING, true,
    DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY,
    <your-output-directory-file>,
    DefaultSequenceDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME,
    <name-of-your-selected-classifier's-data-writer>.class);

所以我的初始化代码如下所示:

AnalysisEngine trainClassifier = AnalysisEngineFactory.createPrimitive(MyClassifier.class, 
        CleartkAnnotator.PARAM_IS_TRAINING, true,
        DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY, "target/classifier-data/",
        DefaultSequenceDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME, MalletCrfStringOutcomeDataWriter.class.getName());

当我运行我的管道时,数据被创建并存储到target/classifier-data/training-data.malletcrf中,其中每一行都是一个特征向量,其中各个条目的格式<featurename>_<value>和我的布尔目标属性。我可以在文本编辑器中打开它并查看它。

我正在使用字符串结果分类器,因为我的目标变量注释器继承自CleartkSequenceAnnotator并且,正如我从对 Cleartk 列表的先前答案所了解的那样,似乎没有一个布尔分类器能够处理每个 CAS 的多个分类任务。

我粗略的分类器代码:

public class MyClassifier extends CleartkSequenceAnnotator<String> {

@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {

    // retrieve sentences in the cas
    for (Sentence sentence : sentences) {
        // apply feature extractors here to add features
        // add target variable
    }

    if (this.isTraining()) {

        // write the features and outcomes as training instances
        this.dataWriter.write(Instances.toInstances(targets, featureLists));

        try {
            System.out.println("training the classifier ... ");
            Train.main("target/classifier-data/");
            System.out.println("done training classifier");
        } catch (Exception e) {
            System.out.println("ERROR while training the classifier.");
            e.printStackTrace();
        }

    } else /* Classification */ {...}
}

这是管道代码:

SimplePipeline.runPipeline(reader,
        trainClassifier,
        XmiWriter);

当我运行管道时,即使已经写入了训练数据,我也会得到以下控制台输出:

... reader initialization ...
Couldn't open cc.mallet.util.MalletLogger resources/logging.properties file.
Perhaps the 'resources' directories weren't copied into the 'class' directory.
Continuing.
starting pipeline
training the classifier ... 
Okt 02, 2014 11:19:48 PM cc.mallet.fst.SimpleTagger main
INFORMATION: Number of features in training data: 0
Okt 02, 2014 11:19:48 PM cc.mallet.fst.SimpleTagger main
INFORMATION: Number of predicates: 0
Okt 02, 2014 11:19:48 PM cc.mallet.fst.SimpleTagger main
INFORMATION: Labels: O
Okt 02, 2014 11:19:48 PM cc.mallet.fst.CRF addOrderNStates
INFORMATION: Preparing O
Okt 02, 2014 11:19:48 PM cc.mallet.fst.CRF addOrderNStates
INFORMATION: O->O(O) O,O
State #0 "O"
initialWeight=0.0, finalWeight=0.0
#destinations=1
-> O
Okt 02, 2014 11:19:48 PM cc.mallet.fst.SimpleTagger train
INFORMATION: Training on 0 instances
Okt 02, 2014 11:19:48 PM cc.mallet.fst.CRF setWeightsDimensionAsIn
INFORMATION: CRF weights[O,O] num features = 0
Okt 02, 2014 11:19:48 PM cc.mallet.fst.CRF setWeightsDimensionAsIn
INFORMATION: Number of weights = 1
Okt 02, 2014 11:19:48 PM cc.mallet.fst.CRFTrainerByLabelLikelihood train
INFORMATION: CRF about to train with 1 iterations
Okt 02, 2014 11:19:48 PM cc.mallet.fst.CRFOptimizableByLabelLikelihood getValue
INFORMATION: getValue() (loglikelihood, optimizable by label likelihood) = 0.0
Okt 02, 2014 11:19:48 PM cc.mallet.optimize.LimitedMemoryBFGS optimize
INFORMATION: L-BFGS initial gradient is zero; saying converged
Okt 02, 2014 11:19:48 PM cc.mallet.fst.CRFTrainerByLabelLikelihood train
INFORMATION: CRF finished one iteration of maximizer, i=0
Okt 02, 2014 11:19:48 PM cc.mallet.fst.CRFTrainerByLabelLikelihood train
INFORMATION: CRF training has converged, i=0
done training classifier

...这向我表明,分类器以某种方式没有从文件中提取训练数据。

我究竟做错了什么?提前致谢!

4

1 回答 1

0

我的猜测是您导入了错误的 Sentence 类。您可以通过在MyClassifier的process方法中调试 for 循环来轻松确定我是否正确

于 2015-02-04T12:06:47.970 回答