private static ACRFEvaluator createEvaluator (LinkedList toks) { String type = (String) toks.removeFirst (); if (type.equalsIgnoreCase ("SEGMENT")) { int slice = Integer.parseInt ((String) toks.removeFirst ()); if (toks.size() % 2 != 0) throw new RuntimeException ("Error in --eval "+evalOption.value+": Every start tag must have a continue."); int numTags = toks.size () / 2; String[] startTags = new String [numTags]; String[] continueTags = new String [numTags]; for (int i = 0; i < numTags; i++) { startTags[i] = (String) toks.removeFirst (); continueTags[i] = (String) toks.removeFirst (); } return new MultiSegmentationEvaluatorACRF (startTags, continueTags, slice); } else if (type.equalsIgnoreCase ("LOG")) { return new DefaultAcrfTrainer.LogEvaluator (); } else if (type.equalsIgnoreCase ("SERIAL")) { List evals = new ArrayList (); while (!toks.isEmpty ()) { evals.add (createEvaluator (toks)); } return new AcrfSerialEvaluator (evals); } else { throw new RuntimeException ("Error in --eval "+evalOption.value+": illegal evaluator "+type); } }
public static TestResults computeTestResults (InstanceList testList, List returnedList) { TestResults results = new TestResults (testList); Iterator it1 = testList.iterator (); Iterator it2 = returnedList.iterator (); while (it1.hasNext ()) { Instance inst = (Instance) it1.next (); // System.out.println ("\n\nInstance"); LabelsAssignment lblseq = (LabelsAssignment) inst.getTarget (); LabelsSequence target = lblseq.getLabelsSequence (); LabelsSequence returned = (LabelsSequence) it2.next (); // System.out.println (target); compareLabelings (results, returned, target); } results.computeStatistics (); return results; }
public void test (InstanceList testList, List returnedList, String description) { logger.info ("Number of testing instances = " + testList.size ()); TestResults results = LogEvaluator.computeTestResults (testList, returnedList); try { PrintWriter writer = new PrintWriter (new FileWriter (file, true)); results.print (description, writer); writer.close (); } catch (Exception e) { e.printStackTrace (); } // results.printConfusion (); } }
private static ACRFEvaluator createEvaluator (LinkedList toks) { String type = (String) toks.removeFirst (); if (type.equalsIgnoreCase ("SEGMENT")) { int slice = Integer.parseInt ((String) toks.removeFirst ()); if (toks.size() % 2 != 0) throw new RuntimeException ("Error in --eval "+evalOption.value+": Every start tag must have a continue."); int numTags = toks.size () / 2; String[] startTags = new String [numTags]; String[] continueTags = new String [numTags]; for (int i = 0; i < numTags; i++) { startTags[i] = (String) toks.removeFirst (); continueTags[i] = (String) toks.removeFirst (); } return new MultiSegmentationEvaluatorACRF (startTags, continueTags, slice); } else if (type.equalsIgnoreCase ("LOG")) { return new DefaultAcrfTrainer.LogEvaluator (); } else if (type.equalsIgnoreCase ("SERIAL")) { List evals = new ArrayList (); while (!toks.isEmpty ()) { evals.add (createEvaluator (toks)); } return new AcrfSerialEvaluator (evals); } else { throw new RuntimeException ("Error in --eval "+evalOption.value+": illegal evaluator "+type); } }
private static ACRFEvaluator createEvaluator (LinkedList toks) { String type = (String) toks.removeFirst (); if (type.equalsIgnoreCase ("SEGMENT")) { int slice = Integer.parseInt ((String) toks.removeFirst ()); if (toks.size() % 2 != 0) throw new RuntimeException ("Error in --eval "+evalOption.value+": Every start tag must have a continue."); int numTags = toks.size () / 2; String[] startTags = new String [numTags]; String[] continueTags = new String [numTags]; for (int i = 0; i < numTags; i++) { startTags[i] = (String) toks.removeFirst (); continueTags[i] = (String) toks.removeFirst (); } return new MultiSegmentationEvaluatorACRF (startTags, continueTags, slice); } else if (type.equalsIgnoreCase ("LOG")) { return new DefaultAcrfTrainer.LogEvaluator (); } else if (type.equalsIgnoreCase ("SERIAL")) { List evals = new ArrayList (); while (!toks.isEmpty ()) { evals.add (createEvaluator (toks)); } return new AcrfSerialEvaluator (evals); } else { throw new RuntimeException ("Error in --eval "+evalOption.value+": illegal evaluator "+type); } }
private static ACRFEvaluator createEvaluator (LinkedList toks) { String type = (String) toks.removeFirst (); if (type.equalsIgnoreCase ("SEGMENT")) { int slice = Integer.parseInt ((String) toks.removeFirst ()); if (toks.size() % 2 != 0) throw new RuntimeException ("Error in --eval "+evalOption.value+": Every start tag must have a continue."); int numTags = toks.size () / 2; String[] startTags = new String [numTags]; String[] continueTags = new String [numTags]; for (int i = 0; i < numTags; i++) { startTags[i] = (String) toks.removeFirst (); continueTags[i] = (String) toks.removeFirst (); } return new MultiSegmentationEvaluatorACRF (startTags, continueTags, slice); } else if (type.equalsIgnoreCase ("LOG")) { return new DefaultAcrfTrainer.LogEvaluator (); } else if (type.equalsIgnoreCase ("SERIAL")) { List evals = new ArrayList (); while (!toks.isEmpty ()) { evals.add (createEvaluator (toks)); } return new AcrfSerialEvaluator (evals); } else { throw new RuntimeException ("Error in --eval "+evalOption.value+": illegal evaluator "+type); } }
private static ACRFEvaluator createEvaluator (LinkedList toks) { String type = (String) toks.removeFirst (); if (type.equalsIgnoreCase ("SEGMENT")) { int slice = Integer.parseInt ((String) toks.removeFirst ()); if (toks.size() % 2 != 0) throw new RuntimeException ("Error in --eval "+evalOption.value+": Every start tag must have a continue."); int numTags = toks.size () / 2; String[] startTags = new String [numTags]; String[] continueTags = new String [numTags]; for (int i = 0; i < numTags; i++) { startTags[i] = (String) toks.removeFirst (); continueTags[i] = (String) toks.removeFirst (); } return new MultiSegmentationEvaluatorACRF (startTags, continueTags, slice); } else if (type.equalsIgnoreCase ("LOG")) { return new DefaultAcrfTrainer.LogEvaluator (); } else if (type.equalsIgnoreCase ("SERIAL")) { List evals = new ArrayList (); while (!toks.isEmpty ()) { evals.add (createEvaluator (toks)); } return new AcrfSerialEvaluator (evals); } else { throw new RuntimeException ("Error in --eval "+evalOption.value+": illegal evaluator "+type); } }
private static ACRFEvaluator createEvaluator (LinkedList toks) { String type = (String) toks.removeFirst (); if (type.equalsIgnoreCase ("SEGMENT")) { int slice = Integer.parseInt ((String) toks.removeFirst ()); if (toks.size() % 2 != 0) throw new RuntimeException ("Error in --eval "+evalOption.value+": Every start tag must have a continue."); int numTags = toks.size () / 2; String[] startTags = new String [numTags]; String[] continueTags = new String [numTags]; for (int i = 0; i < numTags; i++) { startTags[i] = (String) toks.removeFirst (); continueTags[i] = (String) toks.removeFirst (); } return new MultiSegmentationEvaluatorACRF (startTags, continueTags, slice); } else if (type.equalsIgnoreCase ("LOG")) { return new DefaultAcrfTrainer.LogEvaluator (); } else if (type.equalsIgnoreCase ("SERIAL")) { List evals = new ArrayList (); while (!toks.isEmpty ()) { evals.add (createEvaluator (toks)); } return new AcrfSerialEvaluator (evals); } else { throw new RuntimeException ("Error in --eval "+evalOption.value+": illegal evaluator "+type); } }
public static TestResults computeTestResults (InstanceList testList, List returnedList) { TestResults results = new TestResults (testList); Iterator it1 = testList.iterator (); Iterator it2 = returnedList.iterator (); while (it1.hasNext ()) { Instance inst = (Instance) it1.next (); // System.out.println ("\n\nInstance"); LabelsAssignment lblseq = (LabelsAssignment) inst.getTarget (); LabelsSequence target = lblseq.getLabelsSequence (); LabelsSequence returned = (LabelsSequence) it2.next (); // System.out.println (target); compareLabelings (results, returned, target); } results.computeStatistics (); return results; }
public static TestResults computeTestResults (InstanceList testList, List returnedList) { TestResults results = new TestResults (testList); Iterator it1 = testList.iterator (); Iterator it2 = returnedList.iterator (); while (it1.hasNext ()) { Instance inst = (Instance) it1.next (); // System.out.println ("\n\nInstance"); LabelsAssignment lblseq = (LabelsAssignment) inst.getTarget (); LabelsSequence target = lblseq.getLabelsSequence (); LabelsSequence returned = (LabelsSequence) it2.next (); // System.out.println (target); compareLabelings (results, returned, target); } results.computeStatistics (); return results; }
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 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 void test (InstanceList testList, List returnedList, String description) { logger.info ("Number of testing instances = " + testList.size ()); TestResults results = LogEvaluator.computeTestResults (testList, returnedList); try { PrintWriter writer = new PrintWriter (new FileWriter (file, true)); results.print (description, writer); writer.close (); } catch (Exception e) { e.printStackTrace (); } // results.printConfusion (); } }
public void test (InstanceList testList, List returnedList, String description) { logger.info ("Number of testing instances = " + testList.size ()); TestResults results = LogEvaluator.computeTestResults (testList, returnedList); try { PrintWriter writer = new PrintWriter (new FileWriter (file, true)); results.print (description, writer); writer.close (); } catch (Exception e) { e.printStackTrace (); } // results.printConfusion (); } }
public boolean incrementalTrain (ACRF acrf, InstanceList training, InstanceList validation, InstanceList testing, int numIter) { return incrementalTrain (acrf, training, validation, testing, new LogEvaluator (), numIter); }
public boolean train (ACRF acrf, InstanceList training, InstanceList validation, InstanceList testing, int numIter) { return train (acrf, training, validation, testing, new LogEvaluator (), numIter); }
public boolean train (ACRF acrf, InstanceList training) { return train (acrf, training, null, null, new LogEvaluator (), 1); }
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; }
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; }
public boolean train (ACRF acrf, InstanceList training) { return train (acrf, training, null, null, new LogEvaluator (), 1); }