/** * Samples the sequence repeatedly, making numSamples passes over the entire sequence. */ public double sampleSequenceRepeatedly(SequenceModel model, int[] sequence, int numSamples) { sequence = copy(sequence); // so we don't change the initial, or the one we just stored listener.setInitialSequence(sequence); double returnScore = Double.NEGATIVE_INFINITY; for (int iter=0; iter<numSamples; iter++) { returnScore = sampleSequenceForward(model, sequence); } return returnScore; }
public void extendWith(int tag, SequenceModel ts, int s) { extendWith(tag); int[] tags = tmpTags(ts.leftWindow() + 1 + ts.rightWindow(), s); score += ts.scoreOf(tags, size() - ts.rightWindow() - 1); //for (int i=0; i<tags.length; i++) //System.out.print(tags[i]+" "); //System.out.println("\nWith "+tag+" score was "+score); }
/** * Initialize this object using values in Properties object. The properties * are printed to stderr as it works. * * @param props The properties object used for initialization */ public final void setProperties(Properties props) { setProperties(props, true); }
public List<IN> processDocument(List<IN> doc) { if (flags.mergeTags) { mergeTags(doc); } if (flags.iobTags) { iobTags(doc); } doBasicStuff(doc); return doc; }
/** * Construct a SeqClassifierFlags object based on the passed in properties, * and then call the other constructor. * * @param props See SeqClassifierFlags for known properties. */ public AbstractSequenceClassifier(Properties props) { this(new SeqClassifierFlags(props)); }
/** * Samples the sequence repeatedly, making numSamples passes over the entire sequence. * Destructively modifies the sequence in place. */ public double sampleSequenceRepeatedly(SequenceModel model, int numSamples) { int[] sequence = getRandomSequence(model); return sampleSequenceRepeatedly(model, sequence, numSamples); }
/** * Finds the best sequence by collecting numSamples samples, scoring them, and then choosing * the highest scoring sample. * @return the array of type int representing the highest scoring sequence */ public int[] bestSequence(SequenceModel model) { int[] initialSequence = getRandomSequence(model); return findBestUsingSampling(model, numSamples, sampleInterval, initialSequence); }
/** {@inheritDoc} */ @Override public int rightWindow() { if(models != null) return models[0].rightWindow(); return model1.rightWindow(); }
public static Clique valueOf(int maxLeft, int maxRight) { int[] ri = new int[-maxLeft+maxRight+1]; int j = maxLeft; for (int i = 0; i < ri.length; i++) { ri[i] = j++; } return valueOfHelper(ri); }
/** * Samples the complete sequence once in the backward direction * Destructively modifies the sequence in place. * @param sequence the sequence to start with. */ public double sampleSequenceBackward(SequenceModel model, int[] sequence, double temperature) { double returnScore = Double.NEGATIVE_INFINITY; for (int pos=sequence.length-1; pos>=0; pos--) { returnScore = samplePosition(model, sequence, pos, temperature); } return returnScore; }
/** * Informs this sequence model that the value of the whole sequence is initialized to sequence * */ public void setInitialSequence(int[] sequence) { if(models != null){ for (SequenceListener model : models) model.setInitialSequence(sequence); return; } model1.setInitialSequence(sequence); model2.setInitialSequence(sequence); }
public void extendWith(int tag) { TagList last = info; info = new TagList(); info.tag = tag; info.last = last; size++; }
/** * Samples the complete sequence once in the forward direction * Destructively modifies the sequence in place. * @param sequence the sequence to start with. */ public double sampleSequenceForward(SequenceModel model, int[] sequence) { return sampleSequenceForward(model, sequence, 1.0, null); } /**
/** * Samples the complete sequence once in the backward direction * Destructively modifies the sequence in place. * @param sequence the sequence to start with. */ public double sampleSequenceBackward(SequenceModel model, int[] sequence) { return sampleSequenceBackward(model, sequence, 1.0); } /**
/** {@inheritDoc} */ @Override public double scoreOf(int[] sequence) { if(models != null){ double score = 0; for(int i = 0; i < models.length; i++) score+= wts[i]*models[i].scoreOf(sequence); return score; } //return model1.scoreOf(sequence); return model1Wt*model1.scoreOf(sequence) + model2Wt*model2.scoreOf(sequence); }
public Iterator<List<IN>> getIterator(Reader r) { BufferedReader br; if (r instanceof BufferedReader) { br = (BufferedReader) r; } else { br = new BufferedReader(r); } return new BufferedReaderIterator<>(new ColumnDocBufferedGetNextTokens(br)); }
public Clique shift(int shiftAmount) { if (shiftAmount == 0) { return this; } int[] ri = new int[relativeIndices.length]; for (int i = 0; i < ri.length; i++) { ri[i] = relativeIndices[i]+shiftAmount; } return valueOfHelper(ri); }
/** * Samples a single position in the sequence. * Destructively modifies the sequence in place. * returns the score of the new sequence * @param sequence the sequence to start with * @param pos the position to sample. */ public double samplePosition(SequenceModel model, int[] sequence, int pos) { return samplePosition(model, sequence, pos, 1.0); }