首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改Mallet中的目标字母表:字母表不匹配

更改Mallet中的目标字母表:字母表不匹配
EN

Stack Overflow用户
提问于 2012-06-19 05:06:22
回答 1查看 1.2K关注 0票数 0

我很难从Mallet开发人员列表中获得帮助,所以我在这里尝试。

我有一个目标字母表为{A,B,C}的InstancesList,我需要将另一个分析的目标字母表更改为{A,NOT_A}。

到目前为止,我有以下代码(改编自其他Mallet源代码),但我不断得到:

字母表不匹配:实例: 5976,null,InstanceList: 5976,2

代码语言:javascript
复制
...
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}有什么建议?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-26 22:25:54

目标应为标签。试试这个:

代码语言:javascript
复制
..
newInst.setTarget(((LabelAlphabet) newList.getTargetAlphabet()).lookupLabel("A"));
..
newInst.setTarget(((LabelAlphabet) newList.getTargetAlphabet()).lookupLabel("NOT_A"));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11091043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档