public static ACRF makeFactorial (Pipe p, int numLevels) { ArrayList t = new ArrayList (); for (int i = 0; i < numLevels; i++) { t.add (new BigramTemplate (i)); if (i+1 < numLevels) t.add (new PairwiseFactorTemplate (i, i+1)); } Template[] tmpls = (Template[]) t.toArray (new Template [t.size()]); return new ACRF (p, tmpls); }
public void test (ACRF acrf, InstanceList data, String description) { List ret = acrf.getBestLabels (data); test (data, ret, description); }
public LabelAlphabet getTargetAlphabet () { return (LabelAlphabet) acrf.getInputPipe ().getTargetAlphabet (); }
public void dumpUnrolledGraphs (InstanceList lst) { for (int i = 0; i < lst.size(); i++) { Instance inst = lst.get (i); System.out.println("INSTANCE "+i+" : "+inst.getName ()); UnrolledGraph unrolled = unroll (inst); dumpOneGraph (unrolled); } }
SparseVector defW = readSparseVector (defWElt.getText (), null); Element wElt = (Element) it2.next (); int wi = Integer.parseInt (wElt.getAttributeValue ("IDX")); w[wi] = readSparseVector (wElt.getText (), getInputAlphabet ());
public static void reportTrainingLikelihood (ACRF acrf, InstanceList trainingList) { double total = 0; Inferencer inf = acrf.getInferencer (); for (int i = 0; i < trainingList.size (); i++) { Instance inst = trainingList.get (i); ACRF.UnrolledGraph unrolled = acrf.unroll (inst); inf.computeMarginals (unrolled); double lik = inf.lookupLogJoint (unrolled.getAssignment ()); total += lik; logger.info ("...instance "+i+" likelihood = "+lik); } logger.info ("Unregularized joint likelihood = "+total); }
Inferencer maxInf = createInferencer (maxInferencerOption.value); ACRF acrf = new ACRF (pipe, tmpls); acrf.setInferencer (inf); acrf.setViterbiInferencer (maxInf);
templates = acrf.getTemplates (); fixedTmpls = acrf.getFixedTemplates ();
public Alphabet getInputAlphabet () { return acrf.getInputAlphabet (); }
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++) {
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); }
public List bestAssignment (InstanceList lst) { List ret = new ArrayList (lst.size()); for (int i = 0; i < lst.size(); i++) { ret.add (bestAssignment (lst.get (i))); } return ret; }
protected Maxable (ACRF acrf, InstanceList ilist) { PwplACRFTrainer.logger.finest ("Initializing OptimizableACRF."); this.acrf = acrf; templates = acrf.getTemplates (); /* allocate for weights, constraints and expectations */ this.trainData = ilist; initWeights (trainData); initConstraintsExpectations (); int numInstances = trainData.size (); cachedValueStale = cachedGradientStale = true; /* if (cacheUnrolledGraphs) { unrolledGraphs = new UnrolledGraph [numInstances]; } */ PwplACRFTrainer.logger.info ("Number of training instances = " + numInstances); PwplACRFTrainer.logger.info ("Number of parameters = " + numParameters); describePrior (); PwplACRFTrainer.logger.fine ("Computing constraints"); collectConstraints (trainData); }
protected Optimizable.ByGradientValue createOptimizable (ACRF acrf, InstanceList trainingList) { return acrf.getMaximizable (trainingList); }
Inferencer maxInf = createInferencer (maxInferencerOption.value); ACRF acrf = new ACRF (pipe, tmpls); acrf.setInferencer (inf); acrf.setViterbiInferencer (maxInf);
public static void reportTrainingLikelihood (ACRF acrf, InstanceList trainingList) { double total = 0; Inferencer inf = acrf.getInferencer (); for (int i = 0; i < trainingList.size (); i++) { Instance inst = trainingList.get (i); ACRF.UnrolledGraph unrolled = acrf.unroll (inst); inf.computeMarginals (unrolled); double lik = inf.lookupLogJoint (unrolled.getAssignment ()); total += lik; logger.info ("...instance "+i+" likelihood = "+lik); } logger.info ("Unregularized joint likelihood = "+total); }
templates = acrf.getTemplates (); fixedTmpls = acrf.getFixedTemplates ();
public Alphabet getInputAlphabet () { return acrf.getInputAlphabet (); }
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++) {
public void dumpUnrolledGraphs (InstanceList lst) { for (int i = 0; i < lst.size(); i++) { Instance inst = lst.get (i); System.out.println("INSTANCE "+i+" : "+inst.getName ()); UnrolledGraph unrolled = unroll (inst); dumpOneGraph (unrolled); } }