BinaryTestData(int numFeatures) { LabelAlphabet labelAlphabet = new LabelAlphabet(); posLabel = labelAlphabet.lookupLabel("pos", true); negLabel = labelAlphabet.lookupLabel("neg", true); List<String> featureNames = new ArrayList<String>(); for (int i = 0; i < numFeatures; i++) { featureNames.add(Integer.toString(i)); } dataAlphabet = new Alphabet(featureNames.toArray()); iList = new InstanceList(dataAlphabet, labelAlphabet); }
public InstanceList pipeInstances (Iterator<Instance> source) { // I think that pipes should be associated neither with InstanceLists, nor // with Instances. -cas InstanceList toked = new InstanceList (tokenizationPipe); toked.addThruPipe (source); InstanceList piped = new InstanceList (getFeaturePipe ()); piped.addThruPipe (toked.iterator()); return piped; }
public InstanceList getInstances() { InstanceList ret = new InstanceList(m_ilist.getPipe()); for (int ii = 0; ii < m_instIndices.length; ii++) ret.add(m_ilist.get(m_instIndices[ii])); return ret; }
public InstanceList malletPreprocess(List<TokenSequence> data) { ArrayList<Pipe> pipeList = new ArrayList<>(); pipeList.add(new TokenSequenceRemoveStopwords(false, false)); pipeList.add(new TokenSequence2FeatureSequence()); InstanceList instances = new InstanceList(new SerialPipes(pipeList)); ArrayIterator dataListIterator = new ArrayIterator(data); instances.addThruPipe(dataListIterator); return instances; }
public Sequence pipeInput (Object input) { InstanceList all = new InstanceList (getFeaturePipe ()); all.add (input, null, null, null); return (Sequence) all.get (0).getData(); } }
public static InstanceList getInstances(String dbName) throws Exception { DBInstanceIterator dbIterator = new DBInstanceIterator(dbName); InstanceList instances = new InstanceList(dbIterator.getPipe()); instances.addThruPipe(dbIterator); dbIterator.cleanup(); return instances; }
public Sequence pipeInput (Object input) { InstanceList all = new InstanceList (getFeaturePipe ()); all.add (input, null, null, null); return (Sequence) all.get (0).getData(); } }
public void testFixedNumLabels () throws IOException, ClassNotFoundException { Pipe p = new GenericAcrfData2TokenSequence (2); InstanceList training = new InstanceList (p); training.addThruPipe (new LineGroupIterator (new StringReader (sampleFixedData), Pattern.compile ("^$"), true)); assertEquals (1, training.size ()); Instance inst1 = training.get (0); LabelsSequence ls1 = (LabelsSequence) inst1.getTarget (); assertEquals (4, ls1.size ()); }
public void testSetGetParameters () { MaxEntTrainer trainer = new MaxEntTrainer(); Alphabet fd = dictOfSize (6); String[] classNames = new String[] {"class0", "class1", "class2"}; InstanceList ilist = new InstanceList (new Randoms(1), fd, classNames, 20); Optimizable.ByGradientValue maxable = trainer.getOptimizable (ilist); TestOptimizable.testGetSetParameters (maxable); }
/** Iterates over {@link Segment}s for only one {@link Instance}. */ public SegmentIterator (Transducer model, Instance instance, Object[] segmentStartTags, Object[] segmentContinueTags) { InstanceList ilist = new InstanceList (new Noop (instance.getDataAlphabet(), instance.getTargetAlphabet())); ilist.add (instance); setSubIterator (model, ilist, segmentStartTags, segmentContinueTags); }
/** * * @param i * @param j * @return A new {@link InstanceList} containing the two argument {@link Instance}s. */ public static InstanceList makeList (Instance i, Instance j) { InstanceList list = new InstanceList(new Noop(i.getDataAlphabet(), i.getTargetAlphabet())); list.add(i); list.add(j); return list; }
public void testRandomTrained () { Pipe p = new SerialPipes (new Pipe[] { new TokenSequence2FeatureSequence (), new FeatureSequence2FeatureVector (), new Target2Label()}); double testAcc1 = testRandomTrainedOn (new InstanceList (p)); double testAcc2 = testRandomTrainedOn (new PagedInstanceList (p, 700, 200, new File("."))); assertEquals (testAcc1, testAcc2, 0.01); }
/** * * @param i * @param j * @return A new {@link InstanceList} containing the two argument {@link Instance}s. */ public static InstanceList makeList (Instance i, Instance j) { InstanceList list = new InstanceList(new Noop(i.getDataAlphabet(), i.getTargetAlphabet())); list.add(i); list.add(j); return list; }
public void testOneFromSerialized () throws IOException, ClassNotFoundException { Pipe p = createPipe (); Pipe clone = (Pipe) TestSerializable.cloneViaSerialization (p); InstanceList ilist = new InstanceList (clone); ilist.addThruPipe(new StringArrayIterator(data)); assertTrue (ilist.size() == 3); }
public void testRandomMaximizable () { MaxEntTrainer trainer = new MaxEntTrainer(); Alphabet fd = dictOfSize (6); String[] classNames = new String[] {"class0", "class1"}; InstanceList ilist = new InstanceList (new Randoms(1), fd, classNames, 20); Optimizable.ByGradientValue maxable = trainer.getOptimizable (ilist); TestOptimizable.testValueAndGradient (maxable); }
/** * * @param i * @param j * @return A new {@link InstanceList} containing the two argument {@link Instance}s. */ public static InstanceList makeList (Instance i, Instance j) { InstanceList list = new InstanceList(new Noop(i.getDataAlphabet(), i.getTargetAlphabet())); list.add(i); list.add(j); return list; }
/** Iterates over {@link Segment}s for only one {@link Instance}. */ public SegmentIterator (Transducer model, Instance instance, Object[] segmentStartTags, Object[] segmentContinueTags) { InstanceList ilist = new InstanceList (new Noop (instance.getDataAlphabet(), instance.getTargetAlphabet())); ilist.add (instance); setSubIterator (model, ilist, segmentStartTags, segmentContinueTags); }
public static void main(String[] args) { String htmldir = args[0]; Pipe pipe = new SerialPipes(new Pipe[] { new Input2CharSequence(), new CharSequenceRemoveHTML() }); InstanceList list = new InstanceList(pipe); list.addThruPipe(new FileIterator(htmldir, FileIterator.STARTING_DIRECTORIES)); for (int index = 0; index < list.size(); index++) { Instance inst = list.get(index); System.err.println(inst.getData()); } }
public void testTrainedMaximizable () { MaxEntTrainer trainer = new MaxEntTrainer(); Alphabet fd = dictOfSize (6); String[] classNames = new String[] {"class0", "class1"}; InstanceList ilist = new InstanceList (new Randoms(1), fd, classNames, 20); MaxEnt me = (MaxEnt)trainer.train(ilist); Optimizable.ByGradientValue maxable = trainer.getOptimizable (ilist, me); TestOptimizable.testValueAndGradientCurrentParameters (maxable); }
public static void main(String[] args) { String htmldir = args[0]; Pipe pipe = new SerialPipes(new Pipe[] { new Input2CharSequence(), new CharSequenceRemoveHTML() }); InstanceList list = new InstanceList(pipe); list.addThruPipe(new FileIterator(htmldir, FileIterator.STARTING_DIRECTORIES)); for (int index = 0; index < list.size(); index++) { Instance inst = list.get(index); System.err.println(inst.getData()); } }