Examples of HMMState


Examples of edu.cmu.sphinx.linguist.acoustic.HMMState

     * @param indexScore the current index into the TrainerScore
     * @param score      the score information
     * @param nextScore  the score information for the next frame
     */
    private void accumulateStateTransition(int indexScore, TrainerScore[] score, TrainerScore[] nextScore) {
        HMMState state = score[indexScore].getState();
        if (state == null) {
            // Non-emitting state
            return;
        }
        int indexState = state.getState();
        SenoneHMM hmm = (SenoneHMM) state.getHMM();
        float[][] matrix = hmm.getTransitionMatrix();

        // Find the index for current matrix in the transition matrix pool
        // int indexMatrix = matrixPool.indexOf(matrix);
        int indexMatrix = indexMap.get(matrix);
View Full Code Here

Examples of edu.cmu.sphinx.linguist.acoustic.HMMState

                // Certainly non-emitting, if it's not in an HMM.
                probCurrentFrame[index] = 0.0f;
            } else {
                // See if it's the last state in the HMM, i.e., if
                // it's non-emitting.
                HMMState state = (HMMState) node.getObject();
                if (!state.isEmitting()) {
                    probCurrentFrame[index] = 0.0f;
                }
                assert false;
            }
        }

        // If getFeature() is true, curFeature contains a valid
        // Feature. If not, a problem or EOF was encountered.
        lastFeatureIndex = 0;
        while (getFeature()) {
            forwardPass(score);
            scoreList.add(score);
            lastFeatureIndex++;
        }
        logger.info("Feature frames read: " + lastFeatureIndex);
        // Prepare for beta computation
        for (int i = 0; i < probCurrentFrame.length; i++) {
            probCurrentFrame[i] = LogMath.LOG_ZERO;
        }
        Node finalNode = graph.getFinalNode();
        int indexFinalNode = graph.indexOf(finalNode);
        // Overwrite in the right position
        probCurrentFrame[indexFinalNode] = 0.0f;
        for (finalNode.startIncomingEdgeIterator();
             finalNode.hasMoreIncomingEdges();) {
            Edge edge = finalNode.nextIncomingEdge();
            Node node = edge.getSource();
            int index = graph.indexOf(node);
            if (!node.isType("STATE")) {
                // Certainly non-emitting, if it's not in an HMM.
                probCurrentFrame[index] = 0.0f;
                assert false;
            } else {
                // See if it's the last state in the HMM, i.e., if
                // it's non-emitting.
                HMMState state = (HMMState) node.getObject();
                if (!state.isEmitting()) {
                    probCurrentFrame[index] = 0.0f;
                }
            }
        }
View Full Code Here

Examples of edu.cmu.sphinx.linguist.acoustic.HMMState

            for (node.startIncomingEdgeIterator();
                 node.hasMoreIncomingEdges();) {
                // Finds out what the previous node and previous state are
                Node previousNode = node.nextIncomingEdge().getSource();
                int indexPreviousNode = graph.indexOf(previousNode);
                HMMState previousState = (HMMState) previousNode.getObject();
                float logTransitionProbability;
                // previous state could be have an associated hmm state...
                if (previousState != null) {
                    // Make sure that the transition happened from a state
                    // that either is in the same model, or was a
                    // non-emitting state
                    assert ((!previousState.isEmitting()) ||
                            (previousState.getHMM() == hmm));
                    if (!previousState.isEmitting()) {
                        logTransitionProbability = 0.0f;
                    } else {
                        logTransitionProbability =
                                hmm.getTransitionProbability(
                                        previousState.getState(),
                                        state.getState());
                    }
                } else {
                    // Previous state is a dummy state or beginning of
                    // utterance.
                    logTransitionProbability = 0.0f;
                }
                // Adds the alpha and transition from the previous
                // state into the current alpha
                probCurrentFrame[indexNode] =
                        logMath.addAsLinear(probCurrentFrame[indexNode],
                                probPreviousFrame[indexPreviousNode] +
                                        logTransitionProbability);
                // System.out.println("State= " + indexNode + " curr "
                // + probCurrentFrame[indexNode] + " prev " +
                // probPreviousFrame[indexNode] + " trans " +
                // logTransitionProbability);
            }
            // Finally, multiply by this state's output probability for the
            // current Feature (add in log scale)
            probCurrentFrame[indexNode] += outputProbs[indexNode];
            // System.out.println("State= " + indexNode + " alpha= " +
            // probCurrentFrame[indexNode]);
            score[indexNode].setAlpha(probCurrentFrame[indexNode]);
        }

        // Finally, the non-emitting states
        for (int indexNode = 0; indexNode < graph.size(); indexNode++) {
            Node node = graph.getNode(indexNode);
            HMMState state = null;
            SenoneHMM hmm = null;
            if (node.isType("STATE")) {
                state = (HMMState) node.getObject();
                hmm = (SenoneHMM) state.getHMM();
                if (state.isEmitting()) {
                    continue;
                }
            } else if (graph.isInitialNode(node)) {
                score[indexNode].setAlpha(LogMath.LOG_ZERO);
                probCurrentFrame[indexNode] = LogMath.LOG_ZERO;
                continue;
            }
            // Initialize the current frame probability 0.0f, log scale
            probCurrentFrame[indexNode] = LogMath.LOG_ZERO;
            for (node.startIncomingEdgeIterator();
                 node.hasMoreIncomingEdges();) {
                float logTransitionProbability;
                // Finds out what the previous node and previous state are
                Node previousNode = node.nextIncomingEdge().getSource();
                int indexPreviousNode = graph.indexOf(previousNode);
                if (previousNode.isType("STATE")) {
                    HMMState previousState =
                            (HMMState) previousNode.getObject();
                    // Make sure that the transition happened from a
                    // state that either is in the same model, or was
                    // a non-emitting state
                    assert ((!previousState.isEmitting()) ||
                            (previousState.getHMM() == hmm));
                    if (!previousState.isEmitting()) {
                        logTransitionProbability = 0.0f;
                    } else {
                        // previousState == state
                        logTransitionProbability =
                                hmm.getTransitionProbability(
                                        previousState.getState(),
                                        state.getState());
                    }
                } else {
                    logTransitionProbability = 0.0f;
                }
View Full Code Here

Examples of edu.cmu.sphinx.linguist.acoustic.HMMState

            // Treat dummy node (and initial and final nodes) the same
            // as non-emitting
            if (!node.isType("STATE")) {
                continue;
            }
            HMMState state = (HMMState) node.getObject();
            SenoneHMM hmm = (SenoneHMM) state.getHMM();
            if (!state.isEmitting()) {
                continue;
            }
            // Initialize the current frame probability with log
            // probability of log(0f)
            probCurrentFrame[indexNode] = LogMath.LOG_ZERO;
            for (node.startOutgoingEdgeIterator();
                 node.hasMoreOutgoingEdges();) {
                float logTransitionProbability;
                // Finds out what the next node and next state are
                Node nextNode = node.nextOutgoingEdge().getDestination();
                int indexNextNode = graph.indexOf(nextNode);
                HMMState nextState = (HMMState) nextNode.getObject();
                if (nextState != null) {
                    // Make sure that the transition happened to a
                    // non-emitting state, or to the same model
                    assert ((!nextState.isEmitting()) ||
                            (nextState.getHMM() == hmm));
                    if (nextState.getHMM() != hmm) {
                        logTransitionProbability = 0.0f;
                    } else {
                        logTransitionProbability =
                                hmm.getTransitionProbability(state.getState(),
                                        nextState.getState());
                    }
                } else {
                    // Next state is a dummy state or beginning of
                    // utterance.
                    logTransitionProbability = 0.0f;
                }
                // Adds the beta, the output prob, and the transition
                // from the next state into the current beta
                probCurrentFrame[indexNode] =
                        logMath.addAsLinear(probCurrentFrame[indexNode],
                                probNextFrame[indexNextNode] +
                                        logTransitionProbability +
                                        outputProbs[indexNextNode]);
            }
            // System.out.println("State= " + indexNode + " beta= " + probCurrentFrame[indexNode]);
            score[indexNode].setBeta(probCurrentFrame[indexNode]);
        }

        // Now, the non-emitting states

        // We have to go backwards because for non-emitting states we
        // use the current frame probability, and we need to refer to
        // states that are downstream in the graph
        for (int indexNode = graph.size() - 1; indexNode >= 0; indexNode--) {
            Node node = graph.getNode(indexNode);
            HMMState state = null;
            if (node.isType("STATE")) {
                state = (HMMState) node.getObject();
                if (state.isEmitting()) {
                    continue;
                }
            } else if (graph.isFinalNode(node)) {
                score[indexNode].setBeta(LogMath.LOG_ZERO);
                probCurrentFrame[indexNode] = LogMath.LOG_ZERO;
                continue;
            }
            // Initialize the current frame probability with log(0f)
            probCurrentFrame[indexNode] = LogMath.LOG_ZERO;
            for (node.startOutgoingEdgeIterator();
                 node.hasMoreOutgoingEdges();) {
                float logTransitionProbability;
                // Finds out what the next node and next state are
                Node nextNode = node.nextOutgoingEdge().getDestination();
                int indexNextNode = graph.indexOf(nextNode);
                if (nextNode.isType("STATE")) {
                    HMMState nextState = (HMMState) nextNode.getObject();
                    // Make sure that the transition happened to a
                    // state that either is the same, or is emitting
                    assert ((nextState.isEmitting()) || (nextState == state));
                    // In any case, the transition (at this point) is
                    // assumed to be 1.0f, or 0.0f in log scale.
                    logTransitionProbability = 0.0f;
                    /*
                 if (!nextState.isEmitting()) {
View Full Code Here

Examples of edu.cmu.sphinx.linguist.acoustic.tiedstate.HTK.HMMState

                // stid contains the number of senone as it in senone pool
                int j = 0;
                for (int ii = 0; ii < numStatePerHMM; ii++) {
                    if (hmm.isEmitting(ii)) {
                        HMMState s = hmm.getState(ii);
                        // we use the index of HMM in MMF file
                        stid[j] = htkModels.hmmsHTK.getStateIdx(s);
                        j++;
                        // assert stid[j] >= 0 && stid[j] <
                        // numContextIndependentTiedState;
                    }
                }
                // assert tmat < numTiedTransitionMatrices;

                Unit unit = unitManager.getUnit(name, attribute.equals(FILLER));
                contextIndependentUnits.put(unit.getName(), unit);

                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Loaded " + unit);
                }

                // The first filler
                if (unit.isFiller() && unit.getName().equals(SILENCE_CIPHONE)) {
                    unit = UnitManager.SILENCE;
                }

                float[][] transitionMatrix = matrixPool.get(tmat);
                SenoneSequence ss = getSenoneSequence(stid);

                HMM hmm2 = new SenoneHMM(unit, ss, transitionMatrix,
                        HMMPosition.lookup("-"));
                hmmManager.put(hmm2);
            }
        } else {
            // build the 1ph by tying to the first 3ph
            for (int i = 0; i < htkModels.hmmsHTK.getNhmms(); i++) {
                SingleHMM hmm = htkModels.hmmsHTK.getHMM(i);
                if (hmm == null)
                    break;
                String name = hmm.getBaseName();
                if (!contextIndependentUnits.containsKey(name)) {
                    String attribute;
                   
                    if (name.equals("SIL") || name.equals("SP")
                            || name.equals("BB") || name.equals("XX")
                            || name.equals("HH"))
                        attribute = FILLER;
                    else
                        attribute = "nofiller";
                    // get the transition index
                    int tmat = hmm.trIdx;

                    // warning ! this includes non-emitting states !
                    numStatePerHMM = hmm.getNstates();
                    int[] stid = new int[hmm.getNbEmittingStates()];

                    // stid contains the identifier of senone used during
                    // creation of senone pool
                    int j = 0;
                    for (int ii = 0; ii < numStatePerHMM; ii++) {
                        if (hmm.isEmitting(ii)) {
                            HMMState s = hmm.getState(ii);
                            // We get an index of HMM in MMF file
                            stid[j] = htkModels.hmmsHTK.getStateIdx(s);
                            j++;
                            // assert stid[j] >= 0 && stid[j] <
                            // numContextIndependentTiedState;
                        }
                    }
                    // assert tmat < numTiedTransitionMatrices;

                    Unit unit = unitManager.getUnit(name, attribute
                            .equals(FILLER));
                    contextIndependentUnits.put(unit.getName(), unit);

                    if (logger.isLoggable(Level.FINE)) {
                        logger.fine("Loaded " + unit);
                    }

                    // The first filler
                    if (unit.isFiller()
                            && unit.getName().equals(SILENCE_CIPHONE)) {
                        unit = UnitManager.SILENCE;
                    }

                    float[][] transitionMatrix = matrixPool.get(tmat);
                    SenoneSequence ss = getSenoneSequence(stid);

                    HMM hmm2 = new SenoneHMM(unit, ss, transitionMatrix,
                            HMMPosition.lookup("-"));
                    hmmManager.put(hmm2);
                }
            }
        }
        // Load the context dependent phones. If the useCDUnits
        // property is false, the CD phones will not be created, but
        // the values still need to be read in from the file.

        String lastUnitName = "";
        Unit lastUnit = null;
        int[] lastStid = null;
        SenoneSequence lastSenoneSequence = null;

        List<String> HMMdejavu = new ArrayList<String>();
        for (Iterator<SingleHMM> triPhones = htkModels.hmmsHTK.get3phIt(); triPhones
                .hasNext();) {
            SingleHMM hmm = triPhones.next();
            if (hmm == null)
                break;
            String name = hmm.getBaseName();
            String left = hmm.getLeft();
            String right = hmm.getRight();

            {
                // diphones are transformed into triphones with SIL context, as
                // it looks
                // like S4 do not support diphones
                if (left.equals("-"))
                    left = "SIL";
                if (right.equals("-"))
                    right = "SIL";
                String s = left + ' ' + name + ' ' + right;
                if (HMMdejavu.contains(s)) {
                    // this may happen when a diphone is transformed into a
                    // triphone with SIL
                    continue;
                }
                HMMdejavu.add(s);
            }

            // TODO: For this moment we don't know if the HMMS are in the end or
            // not
            String position = "i";
            int tmat = hmm.trIdx;

            numStatePerHMM = hmm.getNstates();
            int[] stid = new int[hmm.getNbEmittingStates()];

            int j = 0;
            for (int ii = 0; ii < numStatePerHMM; ii++) {
                if (hmm.isEmitting(ii)) {
                    HMMState s = hmm.getState(ii);
                    stid[j] = htkModels.hmmsHTK.getStateIdx(s);
                    j++;
                    // assert stid[j] >= 0 && stid[j] <
                    // numContextIndependentTiedState;
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.