本文整理汇总了Java中cc.mallet.grmm.learning.ACRF类的典型用法代码示例。如果您正苦于以下问题:Java ACRF类的具体用法?Java ACRF怎么用?Java ACRF使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ACRF类属于cc.mallet.grmm.learning包,在下文中一共展示了ACRF类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: incrementalTrain
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
public boolean incrementalTrain (ACRF acrf,
InstanceList training,
InstanceList validation,
InstanceList testing,
ACRFEvaluator eval,
int numIter)
{
long stime = new Date ().getTime ();
for (int i = 0; i < SIZE.length; i++) {
InstanceList subset = training.split (new double[]
{SIZE[i], 1 - SIZE[i]})[0];
logger.info ("Training on subset of size " + subset.size ());
Optimizable.ByGradientValue subset_macrf = createOptimizable (acrf, subset);
train (acrf, training, validation, null, eval,
SUBSET_ITER, subset_macrf);
logger.info ("Subset training " + i + " finished...");
}
long etime = new Date ().getTime ();
logger.info ("All subset training finished. Time = " + (etime - stime) + " ms.");
return train (acrf, training, validation, testing, eval, numIter);
}
示例2: callEvaluator
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
/**
* @return true means stop, false means keep going (opposite of evaluators... ugh!)
*/
protected boolean callEvaluator (ACRF acrf, InstanceList trainingList, InstanceList validationList,
InstanceList testSet, int iter, ACRFEvaluator eval)
{
if (eval == null) return false; // If no evaluator specified, keep going blindly
eval.setOutputPrefix (outputPrefix);
// don't cache test set
boolean wasCached = acrf.isCacheUnrolledGraphs ();
acrf.setCacheUnrolledGraphs (false);
Timing timing = new Timing ();
if (!eval.evaluate (acrf, iter+1, trainingList, validationList, testSet)) {
logger.info ("ACRF trainer: evaluator returned false. Quitting.");
timing.tick ("Evaluation time (iteration "+iter+")");
return true;
}
timing.tick ("Evaluation time (iteration "+iter+")");
// set test set caching back to normal
acrf.setCacheUnrolledGraphs (wasCached);
return false;
}
示例3: someUnsupportedTrain
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
public boolean someUnsupportedTrain (ACRF acrf,
InstanceList trainingList,
InstanceList validationList,
InstanceList testSet,
ACRFEvaluator eval,
int numIter)
{
Optimizable.ByGradientValue macrf = createOptimizable (acrf, trainingList);
train (acrf, trainingList, validationList, testSet, eval, 5, macrf);
ACRF.Template[] tmpls = acrf.getTemplates ();
for (int ti = 0; ti < tmpls.length; ti++)
tmpls[ti].addSomeUnsupportedWeights (trainingList);
logger.info ("Some unsupporetd weights initialized. Training...");
return train (acrf, trainingList, validationList, testSet, eval, numIter, macrf);
}
示例4: train
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
public void train(Collection<Alignment> examples) {
Pipe pipe = makePipe();
InstanceList instances = makeExamplesFromAligns(examples, pipe);
ACRF.Template[] tmpls = new ACRF.Template[]{
new ACRF.BigramTemplate(0)
// new ACRF.BigramTemplate (1),
// new ACRF.PairwiseFactorTemplate (0,1),
// new CrossTemplate1(0,1)
};
ACRF acrf = new ACRF(pipe, tmpls);
ACRFTrainer trainer = new DefaultAcrfTrainer();
acrf.setSupportedOnly(true);
acrf.setGaussianPriorVariance(2.0);
DefaultAcrfTrainer.LogEvaluator eval = new DefaultAcrfTrainer.LogEvaluator();
eval.setNumIterToSkip(2);
trainer.train(acrf, instances, null, null, eval, 9999);
}
示例5: train
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
public void train(Collection<Alignment> examples) {
Pipe pipe = makePipe();
InstanceList instances = makeExamplesFromAligns(examples, pipe);
ACRF.Template[] tmpls = new ACRF.Template[]{
new ACRF.BigramTemplate(0),
new ACRF.BigramTemplate (1),
new ACRF.PairwiseFactorTemplate (0,1),
new CrossTemplate1(0,1)
};
ACRF acrf = new ACRF(pipe, tmpls);
ACRFTrainer trainer = new DefaultAcrfTrainer();
acrf.setSupportedOnly(true);
acrf.setGaussianPriorVariance(2.0);
DefaultAcrfTrainer.LogEvaluator eval = new DefaultAcrfTrainer.LogEvaluator();
eval.setNumIterToSkip(2);
trainer.train(acrf, instances, null, null, eval, 9999);
}
示例6: addInstantiatedCliques
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
protected void addInstantiatedCliques (ACRF.UnrolledGraph graph, FeatureVectorSequence fvs, LabelsAssignment lblseq)
{
for (int t = 0; t < lblseq.size() - 1; t++) {
Variable var1 = lblseq.varOfIndex (t, lvl1);
Variable var2 = lblseq.varOfIndex (t + 1, lvl2);
assert var1 != null : "Couldn't get label factor "+lvl1+" time "+t;
assert var2 != null : "Couldn't get label factor "+lvl2+" time "+(t+1);
Variable[] vars = new Variable[] { var1, var2 };
FeatureVector fv = fvs.getFeatureVector (t);
ACRF.UnrolledVarSet vs = new ACRF.UnrolledVarSet (graph, this, vars, fv);
graph.addClique (vs);
}
}
示例7: main
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
public static void main (String[] args) throws FileNotFoundException
{
File trainFile = new File (args[0]);
File testFile = new File (args[1]);
File crfFile = new File (args[2]);
Pipe pipe = new SerialPipes (new Pipe[] {
new GenericAcrfData2TokenSequence (2),
new TokenSequence2FeatureVectorSequence (true, true),
});
InstanceList training = new InstanceList (pipe);
training.addThruPipe (new LineGroupIterator (new FileReader (trainFile),
Pattern.compile ("\\s*"),
true));
InstanceList testing = new InstanceList (pipe);
testing.addThruPipe (new LineGroupIterator (new FileReader (testFile),
Pattern.compile ("\\s*"),
true));
ACRF.Template[] tmpls = new ACRF.Template[] {
new ACRF.BigramTemplate (0),
new ACRF.BigramTemplate (1),
new ACRF.PairwiseFactorTemplate (0,1),
new CrossTemplate1 (0,1)
};
ACRF acrf = new ACRF (pipe, tmpls);
ACRFTrainer trainer = new DefaultAcrfTrainer ();
trainer.train (acrf, training, null, testing, 99999);
FileUtils.writeGzippedObject (crfFile, acrf);
}
示例8: ACRFExtractor
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
public ACRFExtractor (ACRF acrf, Pipe tokPipe, Pipe featurePipe)
{
this.acrf = acrf;
this.tokPipe = tokPipe;
this.featurePipe = featurePipe;
this.filter = new BIOTokenizationFilter ();
}
示例9: train
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
public boolean train (ACRF acrf,
InstanceList training,
InstanceList validation,
InstanceList testing,
int numIter)
{
return train (acrf, training, validation, testing,
new LogEvaluator (), numIter);
}
示例10: test
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
public void test (ACRF acrf, InstanceList testing, ACRFEvaluator[] evals)
{
List pred = acrf.getBestLabels (testing);
for (int i = 0; i < evals.length; i++) {
evals[i].setOutputPrefix (outputPrefix);
evals[i].test (testing, pred, "Testing");
}
}
示例11: evaluate
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
public boolean evaluate (ACRF acrf, int iter,
InstanceList training,
InstanceList validation,
InstanceList testing)
{
if (shouldDoEvaluate (iter)) {
if (training != null) { test (acrf, training, "Training"); }
if (testing != null) { test (acrf, testing, "Testing"); }
}
return true;
}
示例12: evaluate
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
public boolean evaluate (ACRF acrf, int iter, InstanceList training, InstanceList validation, InstanceList testing)
{
boolean ret = true;
for (Iterator it = evals.iterator (); it.hasNext ();) {
ACRFEvaluator evaluator = (ACRFEvaluator) it.next ();
// Return false (i.e., stop training) if any sub-evaluator does.
ret = ret && evaluator.evaluate (acrf, iter, training, validation, testing);
}
return ret;
}
示例13: main
import cc.mallet.grmm.learning.ACRF; //导入依赖的package包/类
public static void main (String[] args) throws FileNotFoundException
{
File trainFile = new File (args[0]);
File testFile = new File (args[1]);
File crfFile = new File (args[2]);
Pipe pipe = new SerialPipes (new Pipe[] {
new GenericAcrfData2TokenSequence (2),
new TokenSequence2FeatureVectorSequence (true, true),
});
InstanceList training = new InstanceList (pipe);
training.addThruPipe (new LineGroupIterator (new FileReader (trainFile),
Pattern.compile ("\\s*"),
true));
InstanceList testing = new InstanceList (pipe);
training.addThruPipe (new LineGroupIterator (new FileReader (testFile),
Pattern.compile ("\\s*"),
true));
ACRF.Template[] tmpls = new ACRF.Template[] {
new ACRF.BigramTemplate (0),
new ACRF.BigramTemplate (1),
new ACRF.PairwiseFactorTemplate (0,1),
new CrossTemplate1 (0,1)
};
ACRF acrf = new ACRF (pipe, tmpls);
ACRFTrainer trainer = new DefaultAcrfTrainer ();
trainer.train (acrf, training, null, testing, 99999);
FileUtils.writeGzippedObject (crfFile, acrf);
}