本文整理汇总了Java中cc.mallet.types.Labeling类的典型用法代码示例。如果您正苦于以下问题:Java Labeling类的具体用法?Java Labeling怎么用?Java Labeling使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Labeling类属于cc.mallet.types包,在下文中一共展示了Labeling类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ConfusionMatrix
import cc.mallet.types.Labeling; //导入依赖的package包/类
/**
* Constructs matrix and calculates values
* @param t the trial to build matrix from
*/
public ConfusionMatrix(Trial t)
{
this.trial = t;
this.classifications = t;
Labeling tempLabeling =
((Classification)classifications.get(0)).getLabeling();
this.numClasses = tempLabeling.getLabelAlphabet().size();
values = new int[numClasses][numClasses];
for(int i=0; i < classifications.size(); i++)
{
LabelVector lv =
((Classification)classifications.get(i)).getLabelVector();
Instance inst = ((Classification)classifications.get(i)).getInstance();
int bestIndex = lv.getBestIndex();
int correctIndex = inst.getLabeling().getBestIndex();
assert(correctIndex != -1);
//System.out.println("Best index="+bestIndex+". Correct="+correctIndex);
values[correctIndex][bestIndex]++;
}
}
示例2: incorporateOneInstance
import cc.mallet.types.Labeling; //导入依赖的package包/类
private void incorporateOneInstance (Instance instance, double instanceWeight)
{
Labeling labeling = instance.getLabeling ();
if (labeling == null) return; // Handle unlabeled instances by skipping them
FeatureVector fv = (FeatureVector) instance.getData ();
double oneNorm = fv.oneNorm();
if (oneNorm <= 0) return; // Skip instances that have no features present
if (docLengthNormalization > 0)
// Make the document have counts that sum to docLengthNormalization
// I.e., if 20, it would be as if the document had 20 words.
instanceWeight *= docLengthNormalization / oneNorm;
assert (instanceWeight > 0 && !Double.isInfinite(instanceWeight));
for (int lpos = 0; lpos < labeling.numLocations(); lpos++) {
int li = labeling.indexAtLocation (lpos);
double labelWeight = labeling.valueAtLocation (lpos);
if (labelWeight == 0) continue;
//System.out.println ("NaiveBayesTrainer me.increment "+ labelWeight * instanceWeight);
me[li].increment (fv, labelWeight * instanceWeight);
// This relies on labelWeight summing to 1 over all labels
pe.increment (li, labelWeight * instanceWeight);
}
}
示例3: ConfusionMatrix
import cc.mallet.types.Labeling; //导入依赖的package包/类
/**
* Constructs matrix and calculates values
* @param t the trial to build matrix from
*/
public ConfusionMatrix(Trial t) {
this.trial = t;
this.classifications = t;
Labeling tempLabeling =
((Classification) classifications.get(0)).getLabeling();
this.numClasses = tempLabeling.getLabelAlphabet().size();
values = new int[numClasses][numClasses];
for (int i=0; i < classifications.size(); i++) {
LabelVector lv =
((Classification)classifications.get(i)).getLabelVector();
Instance inst = ((Classification)classifications.get(i)).getInstance();
int bestIndex = lv.getBestIndex();
int correctIndex = inst.getLabeling().getBestIndex();
assert(correctIndex != -1);
//System.out.println("Best index="+bestIndex+". Correct="+correctIndex);
values[correctIndex][bestIndex]++;
}
}
示例4: getAverageRank
import cc.mallet.types.Labeling; //导入依赖的package包/类
/** Return the average rank of the correct class label as returned by Labeling.getRank(correctLabel) on the predicted Labeling. */
public double getAverageRank ()
{
double rsum = 0;
Labeling tmpL;
Classification tmpC;
Instance tmpI;
Label tmpLbl, tmpLbl2;
int tmpInt;
for(int i = 0; i < this.size(); i++) {
tmpC = this.get(i);
tmpI = tmpC.getInstance();
tmpL = tmpC.getLabeling();
tmpLbl = (Label)tmpI.getTarget();
tmpInt = tmpL.getRank(tmpLbl);
tmpLbl2 = tmpL.getLabelAtRank(0);
rsum = rsum + tmpInt;
}
return rsum/this.size();
}
示例5: applyModel
import cc.mallet.types.Labeling; //导入依赖的package包/类
@Override
public List<ModelApplication> applyModel(
AnnotationSet instanceAS, AnnotationSet inputAS, AnnotationSet sequenceAS, String parms) {
// NOTE: the crm should be of type CorpusRepresentationMalletClass for this to work!
if(!(corpusRepresentation instanceof CorpusRepresentationMalletTarget)) {
throw new GateRuntimeException("Cannot perform classification with data from "+corpusRepresentation.getClass());
}
CorpusRepresentationMalletTarget data = (CorpusRepresentationMalletTarget)corpusRepresentation;
data.stopGrowth();
List<ModelApplication> gcs = new ArrayList<ModelApplication>();
LFPipe pipe = (LFPipe)data.getRepresentationMallet().getPipe();
Classifier classifier = (Classifier)model;
// iterate over the instance annotations and create mallet instances
for(Annotation instAnn : instanceAS.inDocumentOrder()) {
Instance inst = data.extractIndependentFeatures(instAnn, inputAS);
inst = pipe.instanceFrom(inst);
Classification classification = classifier.classify(inst);
Labeling labeling = classification.getLabeling();
LabelVector labelvec = labeling.toLabelVector();
List<String> classes = new ArrayList<String>(labelvec.numLocations());
List<Double> confidences = new ArrayList<Double>(labelvec.numLocations());
for(int i=0; i<labelvec.numLocations(); i++) {
classes.add(labelvec.getLabelAtRank(i).toString());
confidences.add(labelvec.getValueAtRank(i));
}
ModelApplication gc = new ModelApplication(instAnn, labeling.getBestLabel().toString(),
labeling.getBestValue(), classes, confidences);
//System.err.println("ADDING GC "+gc);
// now save the class in our special class feature on the instance as well
instAnn.getFeatures().put("gate.LF.target",labeling.getBestLabel().toString());
gcs.add(gc);
}
data.startGrowth();
return gcs;
}
示例6: labelsToString
import cc.mallet.types.Labeling; //导入依赖的package包/类
public String labelsToString(Labeling lab) {
StringBuilder sb = new StringBuilder();
int num_labs = lab.numLocations();
for (int i = 0; i < num_labs; i++) {
sb.append(lab.labelAtLocation(i)).append(":").append(lab.valueAtLocation(i));
if (i + 1 < num_labs) {
sb.append(",");
}
}
return sb.toString();
}
示例7: convert
import cc.mallet.types.Labeling; //导入依赖的package包/类
/**
*
* @param inst input instance, with FeatureVectorSequence as data.
* @param alphabetsPipe a Noop pipe containing the data and target alphabets for
* the resulting InstanceList and AugmentableFeatureVectors
* @return list of instances, each with one AugmentableFeatureVector as data
*/
public static InstanceList convert(Instance inst, Noop alphabetsPipe)
{
InstanceList ret = new InstanceList(alphabetsPipe);
Object obj = inst.getData();
assert(obj instanceof FeatureVectorSequence);
FeatureVectorSequence fvs = (FeatureVectorSequence) obj;
LabelSequence ls = (LabelSequence) inst.getTarget();
assert(fvs.size() == ls.size());
Object instName = (inst.getName() == null ? "NONAME" : inst.getName());
for (int j = 0; j < fvs.size(); j++) {
FeatureVector fv = fvs.getFeatureVector(j);
int[] indices = fv.getIndices();
FeatureVector data = new AugmentableFeatureVector (alphabetsPipe.getDataAlphabet(),
indices, fv.getValues(), indices.length);
Labeling target = ls.getLabelAtPosition(j);
String name = instName.toString() + "[email protected]_POS_" + (j + 1);
Object source = inst.getSource();
Instance toAdd = alphabetsPipe.pipe(new Instance(data, target, name, source));
ret.add(toAdd);
}
return ret;
}
示例8: Classification
import cc.mallet.types.Labeling; //导入依赖的package包/类
public Classification (Instance instance, Classifier classifier,
Labeling labeling)
{
this.instance = instance;
this.classifier = classifier;
this.labeling = labeling;
}
示例9: bestLabelIsCorrect
import cc.mallet.types.Labeling; //导入依赖的package包/类
public boolean bestLabelIsCorrect ()
{
Labeling correctLabeling = instance.getLabeling();
if (correctLabeling == null)
throw new IllegalStateException ("Instance has no label.");
return (labeling.getBestLabel().equals (correctLabeling.getBestLabel()));
}
示例10: getPrecision
import cc.mallet.types.Labeling; //导入依赖的package包/类
/** Calculate the precision of the classifier on an instance list for a
particular target entry */
public double getPrecision (Object labelEntry)
{
int index;
if (labelEntry instanceof Labeling)
index = ((Labeling)labelEntry).getBestIndex();
else
index = classifier.getLabelAlphabet().lookupIndex(labelEntry, false);
if (index == -1) throw new IllegalArgumentException ("Label "+labelEntry.toString()+" is not a valid label.");
return getPrecision (index);
}
示例11: getRecall
import cc.mallet.types.Labeling; //导入依赖的package包/类
/** Calculate the recall of the classifier on an instance list for a
particular target entry */
public double getRecall (Object labelEntry)
{
int index;
if (labelEntry instanceof Labeling)
index = ((Labeling)labelEntry).getBestIndex();
else
index = classifier.getLabelAlphabet().lookupIndex(labelEntry, false);
if (index == -1) throw new IllegalArgumentException ("Label "+labelEntry.toString()+" is not a valid label.");
return getRecall (index);
}
示例12: getF1
import cc.mallet.types.Labeling; //导入依赖的package包/类
/** Calculate the F1-measure of the classifier on an instance list for a
particular target entry */
public double getF1 (Object labelEntry)
{
int index;
if (labelEntry instanceof Labeling)
index = ((Labeling)labelEntry).getBestIndex();
else
index = classifier.getLabelAlphabet().lookupIndex(labelEntry, false);
if (index == -1) throw new IllegalArgumentException ("Label "+labelEntry.toString()+" is not a valid label.");
return getF1 (index);
}