6

我已经使用 训练了一个 CRF GenericAcrfTui,它将一个写入ACRF文件。我不太确定如何加载和使用训练有素的 CRF,但是

import cc.mallet.grmm.learning.ACRF;
import cc.mallet.util.FileUtils;
ACRF c = (ACRF) FileUtils.readObject(Paths.get("acrf.ser.gz").toFile());

似乎工作。但是,标签似乎不正确,并且似乎依赖于我作为输入传递的标签。 如何使用加载的 ACRF 进行标记?

这是我做标签的方式:

GenericAcrfData2TokenSequence instanceMaker = new GenericAcrfData2TokenSequence();
instanceMaker.setDataAlphabet(c.getInputAlphabet());
instanceMaker.setIncludeTokenText(true);
instanceMaker.setFeaturesIncludeToken(true);
instanceMaker.setLabelsAtEnd(false);
Pipe pipe = new SerialPipes(new Pipe[] {
        instanceMaker,
        new TokenSequence2FeatureVectorSequence(c.getInputAlphabet(),
                true, false),
});
InstanceList testing = new InstanceList(pipe);
Iterator<Instance> testSource = new LineGroupIterator(
    // initialize the labels to O
        new StringReader("O O ---- what W=the@1 W=hell@2\n"
                    + "O O ---- the W=what@-1 W=hell@1\n"
                    + "O O ---- hell W=what@-2 W=the@-1"),
        Pattern.compile("^\\s*$"), true);
testing.addThruPipe(testSource);
System.out.println(c.getBestLabels(testing.get(0)));

我看了一下就知道了GenericAcrfTui。我尝试过的一些事情:

  • 当我尝试给出不同的初始标签(“O”除外)时,结果标签发生了变化,但这无济于事,因为我无法猜测最初要给出什么标签,否则我不需要标注器。
  • 我试图根本不给出任何初始标签,但这只会导致异常,看来 Mallet 真的想要这些标签。

我注意到还有SimpleTagger可以用来训练CRF但我认为使用它来标记新输入我仍然会遇到同样的问题。

SimpleTagger使用来自或的 CRF 进行标记的任何帮助GenericAcrfTui都会有所帮助。

顺便说一句,我通常使用 CRF++,但对于这项任务,我想构建自己的图表,因为我正在使用依赖项解析功能。

4

1 回答 1

5

我想到了!

问题是管道不知道目标字母表。解决方案是使用 CRF's Pipe,如下所示:

Pipe pipe = crf.getInputPipe();

而不是为了自己做那种疯狂的事Pipe

现在,如果有人知道使用查询创建新的更好的方法Instance,那也很好,我只是复制了培训师的做法。

于 2014-03-21T18:49:24.373 回答