当前位置: 首页>>代码示例>>Java>>正文


Java Labels类代码示例

本文整理汇总了Java中cc.mallet.types.Labels的典型用法代码示例。如果您正苦于以下问题:Java Labels类的具体用法?Java Labels怎么用?Java Labels使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Labels类属于cc.mallet.types包,在下文中一共展示了Labels类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupLabel2Var

import cc.mallet.types.Labels; //导入依赖的package包/类
private void setupLabel2Var ()
{
  idx2var = new Variable [lblseq.size ()][];
  var2label = new THashMap ();
  for (int t = 0; t < lblseq.size (); t++) {
    Labels lbls = lblseq.getLabels (t);
    idx2var[t] = new Variable [lbls.size ()];
    for (int j = 0; j < lbls.size (); j++) {
      Label lbl = lbls.get (j);
      Variable var = new Variable (lbl.getLabelAlphabet ());
      var.setLabel ("I"+id+"_VAR[f=" + j + "][tm=" + t + "]");
      idx2var[t][j] = var;
      var2label.put (var, lbl);
    }
  }
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:17,代码来源:LabelsAssignment.java

示例2: toLabelsSequence

import cc.mallet.types.Labels; //导入依赖的package包/类
public LabelsSequence toLabelsSequence (Assignment assn)
{
  int numFactors = numSlices ();
  int maxTime = maxTime ();
  Labels[] lbls = new Labels [maxTime];
  for (int t = 0; t < maxTime; t++) {
    Label[] theseLabels = new Label [numFactors];
    for (int i = 0; i < numFactors; i++) {
      Variable var = varOfIndex (t, i);
      int maxidx;

      if (var != null) {
        maxidx = assn.get (var);
      } else {
        maxidx = 0;
      }

      LabelAlphabet dict = labelOfVar (var).getLabelAlphabet ();
      theseLabels[i] = dict.lookupLabel (maxidx);
    }

    lbls[t] = new Labels (theseLabels);
  }

  return new LabelsSequence (lbls);
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:27,代码来源:LabelsAssignment.java

示例3: testSerializable

import cc.mallet.types.Labels; //导入依赖的package包/类
public void testSerializable () throws IOException, ClassNotFoundException
{
  LabelAlphabet dict = new LabelAlphabet ();
  Labels lbls1 = new Labels (new Label[] {
    dict.lookupLabel ("A"),
    dict.lookupLabel ("B"),
  });
  Labels lbls2 = new Labels (new Label[] {
    dict.lookupLabel ("C"),
    dict.lookupLabel ("A"),
  });
  LabelsSequence lblseq  = new LabelsSequence (new Labels[] { lbls1, lbls2 });
  LabelsSequence lblseq2 = (LabelsSequence) TestSerializable.cloneViaSerialization (lblseq);
  assertEquals (lblseq.size(), lblseq2.size());
  assertEquals (lblseq.getLabels(0).toString(), lblseq2.getLabels(0).toString ());
  assertEquals (lblseq.getLabels(1).toString(), lblseq2.getLabels(1).toString ());
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:18,代码来源:TestLabelsSequence.java

示例4: setupLabel2Var

import cc.mallet.types.Labels; //导入依赖的package包/类
private void setupLabel2Var ()
{
  idx2var = new Variable [lblseq.size ()][];
  var2label = new THashMap();
  for (int t = 0; t < lblseq.size (); t++) {
    Labels lbls = lblseq.getLabels (t);
    idx2var[t] = new Variable [lbls.size ()];
    for (int j = 0; j < lbls.size (); j++) {
      Label lbl = lbls.get (j);
      Variable var = new Variable (lbl.getLabelAlphabet ());
      var.setLabel ("I"+id+"_VAR[f=" + j + "][tm=" + t + "]");
      idx2var[t][j] = var;
      var2label.put (var, lbl);
    }
  }
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:17,代码来源:LabelsAssignment.java

示例5: pipe

import cc.mallet.types.Labels; //导入依赖的package包/类
@Override
public Instance pipe(Instance inst) {
  List<String> source = (List<String>) inst.getData();
  List<String[]> target = (List<String[]>) inst.getTarget();

  inst.setData(makeTokenSeq(source));
  if (target != null) {
    Preconditions.checkState(target.size() == source.size(), "target %s source %s", target, source);
    Labels[] labels = new Labels[target.size()];
    for (int i = 0; i < target.size(); i++) {
      String[] labelStrings = target.get(i);
      labels[i] = new Labels(new Label[] {
          alignDict.lookupLabel(labelStrings[0]),
          phoneDict.lookupLabel(labelStrings[1])
      });
    }
    inst.setTarget(new LabelsAssignment(new LabelsSequence(labels)));
  }
  return inst;
}
 
开发者ID:steveash,项目名称:jg2p,代码行数:21,代码来源:JointInputToTokenSequence.java

示例6: setupLabel2Var

import cc.mallet.types.Labels; //导入依赖的package包/类
private void setupLabel2Var ()
{
  idx2var = new Variable [lblseq.size ()][];
  var2label = new HashMap();
  for (int t = 0; t < lblseq.size (); t++) {
    Labels lbls = lblseq.getLabels (t);
    idx2var[t] = new Variable [lbls.size ()];
    for (int j = 0; j < lbls.size (); j++) {
      Label lbl = lbls.get (j);
      Variable var = new Variable (lbl.getLabelAlphabet ());
      var.setLabel ("I"+id+"_VAR[f=" + j + "][tm=" + t + "]");
      idx2var[t][j] = var;
      var2label.put (var, lbl);
    }
  }
}
 
开发者ID:cmoen,项目名称:mallet,代码行数:17,代码来源:LabelsAssignment.java

示例7: toValueArray

import cc.mallet.types.Labels; //导入依赖的package包/类
private int[] toValueArray ()
{
  TIntArrayList vals = new TIntArrayList (maxTime () * numSlices ());
  for (int t = 0; t < lblseq.size (); t++) {
    Labels lbls = lblseq.getLabels (t);
    for (int j = 0; j < lbls.size (); j++) {
      Label lbl = lbls.get (j);
      vals.add (lbl.getIndex ());
    }
  }
  return vals.toNativeArray ();
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:13,代码来源:LabelsAssignment.java

示例8: classify

import cc.mallet.types.Labels; //导入依赖的package包/类
/**
 * This method classifies several instances at once
 * 
 * @param features
 *          a list of lists of features - each list in the list represents one instance to be
 *          classified. The list should correspond to some logical sequence of instances to be
 *          classified (e.g. tokens in a sentence or lines in a document) that corresponds to the
 *          model that has been built for this classifier.
 */
public List<String[]> classify(final List<List<Feature>> features)
    throws CleartkProcessingException {
  // generate format that is appropriate for the acrf input pipe:
  String data = "";
  {
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    for (List<Feature> f : features) {
      List<NameNumber> nameNumbers = this.featuresEncoder.encodeAll(f);
      GrmmDataWriter.writeEncoded(nameNumbers, this.outcomeExample.split(" "), printWriter);
    }
    data = out.toString();
  }
  // classify:
  Pipe pipe = acrf.getInputPipe();
  Instance unprocessedInstance = new Instance(data, null, "", null);
  Instance instance = pipe.newIteratorFrom(Arrays.asList(unprocessedInstance).iterator()).next();
  LabelsSequence bestLabels = acrf.getBestLabels(instance);
  List<String[]> returnValues = new ArrayList<String[]>(features.size());
  for (int i = 0; i < bestLabels.size(); i++) {
    Labels labels = bestLabels.getLabels(i);
    String[] outcomes = new String[labels.size()];
    for (int j = 0; j < labels.size(); j++) {
      outcomes[j] = labels.get(j).getBestLabel().toString();
    }
    returnValues.add(outcomes);
  }
  return returnValues;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:39,代码来源:GrmmClassifier.java

示例9: toValueArray

import cc.mallet.types.Labels; //导入依赖的package包/类
private int[] toValueArray ()
{
  TIntArrayList vals = new TIntArrayList (maxTime () * numSlices ());
  for (int t = 0; t < lblseq.size (); t++) {
    Labels lbls = lblseq.getLabels (t);
    for (int j = 0; j < lbls.size (); j++) {
      Label lbl = lbls.get (j);
      vals.add (lbl.getIndex ());
    }
  }
  return vals.toArray();
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:13,代码来源:LabelsAssignment.java

示例10: pipe

import cc.mallet.types.Labels; //导入依赖的package包/类
@Override
public Instance pipe(Instance inst) {
  Object maybeTarget = inst.getTarget();
  // if null then we are in test mode not train mode
  if (maybeTarget == null) {
    return inst;
  }
  List<RerankExample> entries = (List<RerankExample>) inst.getData();
  List<Integer> goodIndexes = Lists.newArrayListWithExpectedSize(1);
  for (int i = 0; i < entries.size(); i++) {
    if (entries.get(i).isRelevant()) {
      goodIndexes.add(i);
    }
  }
  if (goodIndexes.isEmpty()) {
    inst.setTarget(targetDict.lookupLabel("-1"));
  } else if (goodIndexes.size() == 1) {
    inst.setTarget(targetDict.lookupLabel(Integer.toString(goodIndexes.get(0))));
  } else {
    // there are multiple labels
    Label[] labels = new Label[goodIndexes.size()];
    for (int i = 0; i < goodIndexes.size(); i++) {
      labels[i] = targetDict.lookupLabel(Integer.toString(goodIndexes.get(i)));
    }
    inst.setTarget(new Labels(labels));
  }
  return inst;
}
 
开发者ID:steveash,项目名称:jg2p,代码行数:29,代码来源:LoadTargetPipe.java

示例11: toValueArray

import cc.mallet.types.Labels; //导入依赖的package包/类
private int[] toValueArray ()
{
  IntArrayList vals = new IntArrayList (maxTime () * numSlices ());
  for (int t = 0; t < lblseq.size (); t++) {
    Labels lbls = lblseq.getLabels (t);
    for (int j = 0; j < lbls.size (); j++) {
      Label lbl = lbls.get (j);
      vals.add (lbl.getIndex ());
    }
  }
  return vals.toArray();
}
 
开发者ID:cmoen,项目名称:mallet,代码行数:13,代码来源:LabelsAssignment.java


注:本文中的cc.mallet.types.Labels类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。