parallelsimplelinguist.java
来自「It is the Speech recognition software. 」· Java 代码 · 共 544 行 · 第 1/2 页
JAVA
544 行
HMM hmm = model.lookupNearestHMM (unitState.getUnit(), unitState.getPosition(), false); ParallelHMMStateState firstHMMState = new ParallelHMMStateState(unitState, stream, hmm.getInitialState(), tokenStackCapacity); // Color.GREEN indicates an in-feature-stream state firstHMMState.setColor(Color.GREEN); // attach first HMMStateState to the splitState attachState(unitState, firstHMMState, getLogMath().getLogOne(), getLogMath().getLogOne(), getLogMath().getLogOne()); // expand the HMM and connect the lastState w/ the combineState Map hmmStates = new HashMap(); hmmStates.put(firstHMMState.getHMMState(), firstHMMState); SentenceHMMState lastState = expandParallelHMMTree(firstHMMState, stream, hmmStates); attachState(lastState, combineState, getLogMath().getLogOne(), getLogMath().getLogOne(), getLogMath().getLogOne()); } return combineState; } /** * Expands the given HMM tree into the full set of HMMStateStates. * * @param hmmStateState the first state of the HMM tree * @param stream the FeatureStream of the relevant acoustic model * @param expandedStates the map of HMMStateStates * * @return the last state of the expanded tree */ private SentenceHMMState expandParallelHMMTree (ParallelHMMStateState hmmStateState, FeatureStream stream, Map expandedStates) { SentenceHMMState lastState = hmmStateState; HMMState hmmState = hmmStateState.getHMMState(); HMMStateArc[] arcs = hmmState.getSuccessors(); for (int i = 0; i < arcs.length; i++) { HMMState nextHmmState = arcs[i].getHMMState(); if (nextHmmState == hmmState) { // this is a self-transition attachState(hmmStateState, hmmStateState, arcs[i].getLogProbability(), getLogMath().getLogOne(), getLogMath().getLogOne()); lastState = hmmStateState; } else { // transition to the next state ParallelHMMStateState nextState = null; if (expandedStates.containsKey(nextHmmState)) { nextState = (ParallelHMMStateState) expandedStates.get(nextHmmState); } else { nextState = new ParallelHMMStateState (hmmStateState.getParent(), stream, nextHmmState, tokenStackCapacity); expandedStates.put(nextHmmState, nextState); } // Color.GREEN indicates an in-feature-stream state nextState.setColor(Color.GREEN); attachState(hmmStateState, nextState, arcs[i].getLogProbability(), getLogMath().getLogOne(), getLogMath().getLogOne()); lastState = expandParallelHMMTree (nextState, stream, expandedStates); } } return lastState; } /** * Expands the given UnitState into the set of associated * HMMStateStates that tie at the state level. * * @param unitState the UnitState to expand * * @return the last SentenceHMMState from the expansion */ private SentenceHMMState getTiedHMMStates(UnitState unitState) { SentenceHMMState combineState = new CombineState (unitState.getParent(), unitState.getWhich()); HMM[] hmms = new HMM[featureStreams.size()]; SentenceHMMState lastState = unitState; int s = 0; // create an HMM branch for each feature stream for (Iterator i = featureStreams.iterator(); i.hasNext(); s++) { FeatureStream stream = (FeatureStream) i.next(); hmms[s] = stream.getAcousticModel().lookupNearestHMM (unitState.getUnit(), unitState.getPosition(), false); } lastState = getHMMTiedStates(hmms, unitState); return lastState; } /** * Converts the given HMMs into a network of SentenceHMMStates * tied at the state level. * * @param hmms the HMMs to convert * @param unitState the UnitState that corresponds to these HMMs * * @return the last SentenceHMMState from the expansion */ private SentenceHMMState getHMMTiedStates(HMM[] hmms, UnitState unitState) { SentenceHMMState lastState = new CombineState(unitState, 0); HMMStateArc[] arcs = new HMMStateArc[featureStreams.size()]; // // In this for loop, we connect the unitState to the // ParallelHMMState created from the first HMMState of each of // the HMMs. We then connect each of the ParallelHMMStates // to a combining state. Lastly, if the HMMState has a // self-transition, we create a transition from the combining // state to the ParallelHMMState, using the self-transition // probability. // for (int i = 0; i < hmms.length; i++) { HMMState hmmState = hmms[i].getInitialState(); FeatureStream stream = (FeatureStream) featureStreams.get(i); ParallelHMMStateState firstHMMState = new ParallelHMMStateState (unitState, stream, hmmState, tokenStackCapacity); // Color.GREEN indicates an in-feature-stream state firstHMMState.setColor(Color.GREEN); // connect previous last state to this HMMState attachState(unitState, firstHMMState, getLogMath().getLogOne(), getLogMath().getLogOne(), getLogMath().getLogOne()); // connect this HMMState to the next combining state attachState(firstHMMState, lastState, getLogMath().getLogOne(), getLogMath().getLogOne(), getLogMath().getLogOne()); HMMStateArc selfTransition = getSelfTransition(hmmState); if (selfTransition != null) { // connect the next combining state to this HMMState attachState(lastState, firstHMMState, selfTransition.getLogProbability(), getLogMath().getLogOne(), getLogMath().getLogOne()); } arcs[i] = getTransitionToNextState(hmmState); } // // We then start with the second HMMState of each HMM, and do // the same thing as the previous for loop: connect each // ParallelHMMState (created from the HMMState) to a combining // state, and if that HMMState has a self transition, connect // that combining state to the ParallelHMMState using the // self transition probability // for (int i = 1; i <= hmms[0].getOrder(); i++) { SentenceHMMState combineState = new CombineState(unitState, i); for (int a = 0; a < arcs.length; a++) { HMMStateArc arc = arcs[a]; HMMState hmmState = arc.getHMMState(); FeatureStream stream = (FeatureStream)featureStreams.get(a); ParallelHMMStateState hmmStateState = new ParallelHMMStateState (unitState, stream, hmmState, tokenStackCapacity); // Color.GREEN indicates an in-feature-stream state hmmStateState.setColor(Color.GREEN); // connect lastState and this HMMStateState attachState(lastState, hmmStateState, arc.getLogProbability(), getLogMath().getLogOne(), getLogMath().getLogOne()); // connect this HMMStateState and the combineState attachState(hmmStateState, combineState, getLogMath().getLogOne(), getLogMath().getLogOne(), getLogMath().getLogOne()); // connect the self-transition HMMStateArc selfTransition = getSelfTransition(hmmState); if (selfTransition != null) { // connect the next combining state to this HMMState attachState(combineState, hmmStateState, selfTransition.getLogProbability(), getLogMath().getLogOne(), getLogMath().getLogOne()); } arcs[a] = getTransitionToNextState(hmmState); } lastState = combineState; } return lastState; } /** * Returns the self-transitioning HMMStateArc of the given HMMState. */ private HMMStateArc getSelfTransition(HMMState hmmState) { HMMStateArc[] arcs = hmmState.getSuccessors(); for (int i = 0; i < arcs.length; i++) { HMMState nextHmmState = arcs[i].getHMMState(); if (nextHmmState == hmmState) { return arcs[i]; } } return null; } /** * Returns the HMMStateArc that transitioin to the next HMMState. */ private HMMStateArc getTransitionToNextState(HMMState hmmState) { HMMStateArc[] arcs = hmmState.getSuccessors(); for (int i = 0; i < arcs.length; i++) { HMMState nextHmmState = arcs[i].getHMMState(); if (nextHmmState != hmmState) { return arcs[i]; } } return null; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?