本文整理汇总了Java中cc.mallet.fst.Transducer.State方法的典型用法代码示例。如果您正苦于以下问题:Java Transducer.State方法的具体用法?Java Transducer.State怎么用?Java Transducer.State使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.fst.Transducer
的用法示例。
在下文中一共展示了Transducer.State方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: outputLatticeRows
import cc.mallet.fst.Transducer; //导入方法依赖的package包/类
private static void outputLatticeRows (PrintWriter out, MaxLattice lattice, int start, int end)
{
DecimalFormat f = new DecimalFormat ("0.##");
Transducer ducer = lattice.getTransducer ();
int max = Math.min (numMaxViterbi, ducer.numStates());
List<Sequence<Transducer.State>> stateSequences = lattice.bestStateSequences(max);
for (int k = 0; k < max; k++) {
out.println (" <tr class=\"delta\">");
out.println (" <td class=\"label\">δ rank "+k+"</td>");
for (int ip = start; ip < end; ip++) {
Transducer.State state = stateSequences.get(k).get(ip+1);
if (state.getName().equals (lattice.bestOutputSequence().get(ip))) {
out.print ("<td class=\"viterbi\">");
} else {
out.print ("<td>");
}
out.print (state.getName()+"<br />"+f.format (-lattice.getDelta (ip+1, state.getIndex ()))+"</td>");
}
out.println ("</tr>");
}
}
示例2: nextState
import cc.mallet.fst.Transducer; //导入方法依赖的package包/类
public Transducer.State nextState() {
assert (nextIndex < source.numDestinations());
index = nextIndex;
nextIndex++;
while (nextIndex < source.numDestinations()
&& weights[nextIndex] == Transducer.IMPOSSIBLE_WEIGHT)
nextIndex++;
return source.getDestinationState(index);
}
示例3: testXis
import cc.mallet.fst.Transducer; //导入方法依赖的package包/类
public void testXis() {
Pipe p = makeSpacePredictionPipe();
InstanceList instances = new InstanceList(p);
instances.addThruPipe(new ArrayIterator(data));
CRF crf1 = new CRF(p, null);
crf1.addFullyConnectedStatesForLabels();
CRFTrainerByLabelLikelihood crft1 = new CRFTrainerByLabelLikelihood(
crf1);
crft1.train(instances, 10); // Let's get some parameters
Instance inst = instances.get(0);
Sequence input = (Sequence) inst.getData();
SumLatticeDefault lattice = new SumLatticeDefault(crf1, input,
(Sequence) inst.getTarget(), null, true);
for (int ip = 0; ip < lattice.length() - 1; ip++) {
for (int i = 0; i < crf1.numStates(); i++) {
Transducer.State state = crf1.getState(i);
Transducer.TransitionIterator it = state.transitionIterator(
input, ip);
double gamma = lattice.getGammaProbability(ip, state);
double xiSum = 0;
while (it.hasNext()) {
Transducer.State dest = it.nextState();
double xi = lattice.getXiProbability(ip, state, dest);
xiSum += xi;
}
assertEquals(gamma, xiSum, 1e-5);
}
}
}
示例4: LatticeNode
import cc.mallet.fst.Transducer; //导入方法依赖的package包/类
LatticeNode(int ip, Transducer.State state) {
this.ip = ip;
this.state = state;
this.alpha = 0.0;
this.beta = 0.0;
}
示例5: getSourceState
import cc.mallet.fst.Transducer; //导入方法依赖的package包/类
public final Transducer.State getSourceState() {
return source;
}
示例6: getDestinationState
import cc.mallet.fst.Transducer; //导入方法依赖的package包/类
public final Transducer.State getDestinationState() {
return source.getDestinationState(index);
}
示例7: testMaxLattice
import cc.mallet.fst.Transducer; //导入方法依赖的package包/类
public void testMaxLattice() {
int inputVocabSize = 1;
int numStates = 2;
Alphabet inputAlphabet = new Alphabet();
for (int i = 0; i < inputVocabSize; i++)
inputAlphabet.lookupIndex("feature" + i);
Alphabet outputAlphabet = new Alphabet();
CRF crf = new CRF(inputAlphabet, outputAlphabet);
String[] stateNames = new String[numStates];
for (int i = 0; i < numStates; i++)
stateNames[i] = "state" + i;
crf.addFullyConnectedStates(stateNames);
crf.setWeightsDimensionDensely();
crf.getState(0).setInitialWeight(1.0);
crf.getState(1).setInitialWeight(Transducer.IMPOSSIBLE_WEIGHT);
crf.getState(0).setFinalWeight(0.0);
crf.getState(1).setFinalWeight(0.0);
crf.setParameter(0, 0, 0, Transducer.IMPOSSIBLE_WEIGHT); // state0
// self-transition
crf.setParameter(0, 1, 0, 1.0); // state0->state1
crf.setParameter(1, 1, 0, 1.0); // state1 self-transition
crf.setParameter(1, 0, 0, Transducer.IMPOSSIBLE_WEIGHT); // state1->state0
FeatureVectorSequence fvs = new FeatureVectorSequence(
new FeatureVector[] {
new FeatureVector((Alphabet) crf.getInputAlphabet(),
new double[] { 1 }),
new FeatureVector((Alphabet) crf.getInputAlphabet(),
new double[] { 1 }),
new FeatureVector((Alphabet) crf.getInputAlphabet(),
new double[] { 1 }), });
MaxLattice lattice = new MaxLatticeDefault(crf, fvs);
Sequence<Transducer.State> viterbiPath = lattice.bestStateSequence();
// We start in state0
assertTrue(viterbiPath.get(0) == crf.getState(0));
// We go to state1
assertTrue(viterbiPath.get(1) == crf.getState(1));
// And on through a self-transition to state1 again
assertTrue(viterbiPath.get(2) == crf.getState(1));
}