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


Java Datum.asFeatures方法代码示例

本文整理汇总了Java中edu.stanford.nlp.ling.Datum.asFeatures方法的典型用法代码示例。如果您正苦于以下问题:Java Datum.asFeatures方法的具体用法?Java Datum.asFeatures怎么用?Java Datum.asFeatures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.stanford.nlp.ling.Datum的用法示例。


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

示例1: updateDerivative

import edu.stanford.nlp.ling.Datum; //导入方法依赖的package包/类
private void updateDerivative(Datum<L,F> datum, double[] probs,Counter<Triple<Integer,Integer,Integer>> feature2classPairDerivatives){
  for (F feature : datum.asFeatures()) {
    int fID = labeledDataset.featureIndex.indexOf(feature);
    if (fID >= 0) {
      for (int c = 0; c < numClasses; c++) {
        for (int cPrime = 0; cPrime < numClasses; cPrime++) {
          if (cPrime == c) {
            feature2classPairDerivatives.incrementCount(new Triple<Integer,Integer,Integer>(fID,c,cPrime), - probs[c]*(1-probs[c])*valueOfFeature(feature,datum));
          } else {
            feature2classPairDerivatives.incrementCount(new Triple<Integer,Integer,Integer>(fID,c,cPrime), probs[c]*probs[cPrime]*valueOfFeature(feature,datum));
          }
        }
      }
    }
  }
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:17,代码来源:GeneralizedExpectationObjectiveFunction.java

示例2: scoresOf

import edu.stanford.nlp.ling.Datum; //导入方法依赖的package包/类
/** Construct a counter with keys the labels of the classifier and
 *  values the score (unnormalized log probability) of each class.
 */
@Override
public Counter<L> scoresOf(Datum<L, F> example) {
  if(example instanceof RVFDatum<?, ?>)return scoresOfRVFDatum((RVFDatum<L,F>)example);
  Collection<F> feats = example.asFeatures();
  int[] features = new int[feats.size()];
  int i = 0;
  for (F f : feats) {
    int index = featureIndex.indexOf(f);
    if (index >= 0) {
      features[i++] = index;
    } else {
      //System.err.println("FEATURE LESS THAN ZERO: " + f);
    }
  }
  int[] activeFeatures = new int[i];
  System.arraycopy(features, 0, activeFeatures, 0, i);
  Counter<L> scores = new ClassicCounter<L>();
  for (L lab : labels()) {
    scores.setCount(lab, scoreOf(activeFeatures, lab));
  }
  return scores;
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:26,代码来源:LinearClassifier.java

示例3: scoresOf

import edu.stanford.nlp.ling.Datum; //导入方法依赖的package包/类
/** Construct a counter with keys the labels of the classifier and
 *  values the score (unnormalized log probability) of each class.
 */
public Counter<L> scoresOf(Datum<L, F> example) {
  if(example instanceof RVFDatum<?, ?>)return scoresOfRVFDatum((RVFDatum<L,F>)example);
  Collection<F> feats = example.asFeatures();
  int[] features = new int[feats.size()];
  int i = 0;
  for (F f : feats) {
    int index = featureIndex.indexOf(f);
    if (index >= 0) {
      features[i++] = index;
    } else {
      //System.err.println("FEATURE LESS THAN ZERO: " + f);
    }
  }
  int[] activeFeatures = new int[i];
  System.arraycopy(features, 0, activeFeatures, 0, i);
  Counter<L> scores = new ClassicCounter<L>();
  for (L lab : labels()) {
    scores.setCount(lab, scoreOf(activeFeatures, lab));
  }
  return scores;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:25,代码来源:LinearClassifier.java

示例4: mapDatum

import edu.stanford.nlp.ling.Datum; //导入方法依赖的package包/类
public static <L,L2,F> Datum<L2,F> mapDatum(Datum<L,F> d, Map<L,L2> labelMapping, L2 defaultLabel) {
  // TODO: How to copy datum?
  L2 newLabel = labelMapping.get(d.label());
  if (newLabel == null) {
    newLabel = defaultLabel;
  }

  if (d instanceof RVFDatum) {
    return new RVFDatum<L2,F>( ((RVFDatum<L,F>) d).asFeaturesCounter(), newLabel );
  } else {
    return new BasicDatum<L2,F>( d.asFeatures(), newLabel );
  }
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:14,代码来源:GeneralDataset.java

示例5: scoreOf

import edu.stanford.nlp.ling.Datum; //导入方法依赖的package包/类
/** Returns of the score of the Datum for the specified label.
 *  Ignores the true label of the Datum.
 */
public double scoreOf(Datum<L, F> example, L label) {
  if(example instanceof RVFDatum<?, ?>)return scoreOfRVFDatum((RVFDatum<L,F>)example, label);
  int iLabel = labelIndex.indexOf(label);
  double score = 0.0;
  for (F f : example.asFeatures()) {
    score += weight(f, iLabel);
  }
  return score + thresholds[iLabel];
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:13,代码来源:LinearClassifier.java

示例6: experimentalClassOf

import edu.stanford.nlp.ling.Datum; //导入方法依赖的package包/类
public L experimentalClassOf(Datum<L,F> example) {
 if(example instanceof RVFDatum<?, ?>) {
  throw new UnsupportedOperationException();
 }

 int labelCount = weights[0].length;
 //System.out.printf("labelCount: %d\n", labelCount);
 Collection<F> features = example.asFeatures();

 int[] featureInts = new int[features.size()];
 int fI = 0;
 for (F feature : features) {
  featureInts[fI++] = featureIndex.indexOf(feature);
 }
 //System.out.println("Features: "+features);
 double bestScore = Double.NEGATIVE_INFINITY;
 int bestI = 0;
 for (int i = 0; i < labelCount; i++) {
  double score = 0;
  for (int j = 0; j < featureInts.length; j++) {
	  if (featureInts[j] < 0) continue;
	  score += weights[featureInts[j]][i];
  }
  if (score > bestScore) {
	  bestI = i;
	  bestScore = score;
  }
  //System.out.printf("Score: %s(%d): %e\n", labelIndex.get(i), i, score);
 }
 //System.out.printf("label(%d): %s\n", bestI, labelIndex.get(bestI));;
 return labelIndex.get(bestI);
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:33,代码来源:LinearClassifier.java

示例7: scoresOf

import edu.stanford.nlp.ling.Datum; //导入方法依赖的package包/类
/**
 * returns the scores for both the classes
 */
public Counter<L> scoresOf(Datum<L, F> datum) {
  if(datum instanceof RVFDatum<?,?>)return scoresOfRVFDatum((RVFDatum<L,F>)datum);
  Collection<F> features = datum.asFeatures();
  double sum = scoreOf(features);
  Counter<L> c = new ClassicCounter<L>();
  c.setCount(classes[0], -sum);
  c.setCount(classes[1], sum);
  return c;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:13,代码来源:LogisticClassifier.java


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