本文整理汇总了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);
}
}
}
示例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);
}
示例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 ());
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
}
示例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 ();
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}