本文整理汇总了Java中edu.berkeley.nlp.util.Counter.keySet方法的典型用法代码示例。如果您正苦于以下问题:Java Counter.keySet方法的具体用法?Java Counter.keySet怎么用?Java Counter.keySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.berkeley.nlp.util.Counter
的用法示例。
在下文中一共展示了Counter.keySet方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPunctuations
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
private void initPunctuations(StateSetTreeList trainTrees) {
punctuationSignatures = new Indexer<String>();
isPunctuation = new boolean[nWords];
Counter<String> punctSigCounter = new Counter<String>();
for (int word = 0; word < nWords; word++) {
isPunctuation[word] = isPunctuation(wordIndexer.get(word));
}
for (Tree<StateSet> tree : trainTrees) {
getPunctuationSignatures(tree.getYield(), true, punctSigCounter);
}
Indexer<String> newPunctuationSignatures = new Indexer<String>();
for (String sig : punctSigCounter.keySet()) {
if (punctSigCounter.getCount(sig) >= minFeatureFrequency)
newPunctuationSignatures.add(sig);
}
punctuationSignatures = newPunctuationSignatures;
punctuationScores = new double[punctuationSignatures.size()][nClasses];
ArrayUtil.fill(punctuationScores, 1);
nFeatures += nClasses * punctuationScores.length;
}
示例2: trainClassifier
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
public ProbabilisticClassifier<I, L> trainClassifier(
List<LabeledInstance<I, L>> trainingData) {
CounterMap<L, F> featureProbs = new CounterMap<L, F>();
Counter<F> backoffProbs = new Counter<F>();
Counter<L> labelProbs = new Counter<L>();
for (LabeledInstance<I, L> instance : trainingData) {
L label = instance.getLabel();
labelProbs.incrementCount(label, 1.0);
I inst = instance.getInput();
Counter<F> featCounts = featureExtractor.extractFeatures(inst);
for (F feat : featCounts.keySet()) {
double count = featCounts.getCount(feat);
backoffProbs.incrementCount(feat, count);
featureProbs.incrementCount(label, feat, count);
}
}
featureProbs.normalize();
labelProbs.normalize();
backoffProbs.normalize();
return new NaiveBayesClassifier<I, F, L>(featureProbs,
backoffProbs, labelProbs, featureExtractor);
}
示例3: calculate
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
@Override
protected Pair<Double, double[]> calculate(double[] x) {
weights = x;
double objective = 0.0;
double[] gradient = new double[dimension()];
for (Pair<I, Double> datum : trainingData) {
I input = datum.getFirst();
Counter<Feature> featCounts = getFeatures(input);
double guessResponse = getScore(featCounts);
double goldResponse = datum.getSecond();
double diff = (guessResponse - goldResponse);
objective += 0.5 * diff * diff;
for (Feature feat : featCounts.keySet()) {
double count = featCounts.getCount(feat);
gradient[feat.getIndex()] += count * diff;
}
}
// TODO Auto-generated method stub
return Pair.newPair(objective, gradient);
}
示例4: dotProduct
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
private double dotProduct(Counter<F> features, int labelIndex, double[] w) {
double val = 0.0;
for (F feature : features.keySet()) {
if (encoding.hasFeature(feature)) {
int featureIndex = encoding.getFeatureIndex(feature);
int linearIndex = il.getLinearIndex(featureIndex, labelIndex);
val += features.getCount(feature) * w[linearIndex];
}
}
return val;
}
示例5: getFeatures
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
private Counter<Feature> getFeatures(I input) {
Counter<String> strCounts = featureExtractor.extractFeatures(input);
Counter<Feature> featCounts = new Counter<Feature>();
for (String f : strCounts.keySet()) {
double count = strCounts.getCount(f);
Feature feat = featureManager.getFeature(f);
featCounts.setCount(feat, count);
}
return featCounts;
}
示例6: getScore
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
private double getScore(Counter<Feature> featureCounts) {
double score = 0.0;
for (Feature feat : featureCounts.keySet()) {
double count = featureCounts.getCount(feat);
score += count * weights[feat.getIndex()];
}
return score;
}
示例7: extractAllFeatures
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
private void extractAllFeatures() {
for (Pair<I, Double> datum : trainingData) {
Counter<String> counts = featureExtractor.extractFeatures(datum
.getFirst());
for (String f : counts.keySet()) {
featureManager.getFeature(f);
}
}
featureManager.lock();
}
示例8: getResponse
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
public double getResponse(I input) {
Counter<String> featCounts = featureExtractor.extractFeatures(input);
double score = 0.0;
for (String f : featCounts.keySet()) {
double count = featCounts.getCount(f);
Feature feat = featureManager.getFeature(f);
score += count * weights[feat.getIndex()];
}
return score;
}