我很难从Mallet开发人员列表中获得帮助,所以我在这里尝试。
我有一个目标字母表为{A,B,C}的InstancesList,我需要将另一个分析的目标字母表更改为{A,NOT_A}。
到目前为止,我有以下代码(改编自其他Mallet源代码),但我不断得到:
字母表不匹配:实例: 5976,null,InstanceList: 5976,2
...
InstanceList iListCopy = (InstanceList) instances.clone();
Alphabet blank = new Alphabet();
Alphabet newAlpha = new Alphabet();
//A and NOT_A cannot be found in alphabet, so add them.
newAlpha.lookupIndex("A", true);
newAlpha.lookupIndex("NOT_A", true);
Noop pipe = new Noop(blank, newAlpha);
InstanceList newIList = new InstanceList(pipe);
//iterate through each instance and change the target based on the
original value.
for (int i = 0; i < iListCopy.size(); i++) {
Instance inst = iListCopy.get(i);
FeatureVector original = (FeatureVector) inst.getData();
Instance newInst = pipe.instanceFrom(new Instance(original,
newAlpha, inst.getName(), inst.getSource()));
if (inst.getLabeling().toString().equals("A") {
newInst.setTarget("A");
} else {
newInst.setTarget("NOT_A");
}
newIList.add(newInst); //FAILS with "Alphabets do not match."
}
...有没有人对如何将目标字母表从{A,B,C}更改为{A,NOT_A}有什么建议?
发布于 2012-09-26 22:25:54
目标应为标签。试试这个:
..
newInst.setTarget(((LabelAlphabet) newList.getTargetAlphabet()).lookupLabel("A"));
..
newInst.setTarget(((LabelAlphabet) newList.getTargetAlphabet()).lookupLabel("NOT_A"));https://stackoverflow.com/questions/11091043
复制相似问题