private void addSelfLoops(List <GrammarNode> wordGrammarNodes) { /*ListIterator<GrammarNode> iter = wordGrammarNodes.listIterator(); * while (iter.hasNext()) { * GrammarNode currNode = iter.next(); * currNode.add(currNode, logMath.linearToLog(selfLoopProbability)); * }*/ foreach (var wordGrammarNode in wordGrammarNodes) { wordGrammarNode.add(wordGrammarNode, logMath.linearToLog(selfLoopProbability)); } }
/* * (non-Javadoc) * We want a very strict grammar structure like the following: * InitialNode ----> KW1 ---> KW2 .... ---> KWn ---> FinalNode * ↑________________________________________________| */ protected override GrammarNode createGrammar() { string silence = Constants.SILENCE_SPELLING; initialNode = createGrammarNode(silence); finalNode = createGrammarNode(silence); GrammarNode lastNode = createGrammarNode(silence); initialNode.add(lastNode, LogMath.getLogOne()); lastNode.add(initialNode, LogMath.getLogOne()); GrammarNode lastWordGrammarNode = initialNode; /*Iterator<string> iter = tokens.iterator(); * while(iter.hasNext()){ * GrammarNode currNode = createGrammarNode(iter.next()); * lastWordGrammarNode.add(currNode, logMath.getLogOne()); * lastWordGrammarNode = currNode; * * // Parallel keyword topology * //initialNode.add(currNode, logMath.getLogOne()); * * //currNode.add(finalNode, logMath.getLogOne()); * }*/ foreach (var token in tokens) { GrammarNode currNode = createGrammarNode(token); lastWordGrammarNode.add(currNode, LogMath.getLogOne()); lastWordGrammarNode = currNode; } lastWordGrammarNode.add(lastNode, LogMath.getLogOne()); lastNode.add(finalNode, logMath.linearToLog(0.0001)); finalNode.setFinalNode(true); return(initialNode); }
public void newProperties(PropertySheet ps) { logMath = LogMath.getLogMath(); absoluteBeamWidth = ps.getInt(PROP_ABSOLUTE_BEAM_WIDTH); double relativeBeamWidth = ps.getDouble(PROP_RELATIVE_BEAM_WIDTH); logRelativeBeamWidth = logMath.linearToLog(relativeBeamWidth); }
public AFlatLinguist(AcousticModel acousticModel, Grammar grammar, UnitManager unitManager, double wordInsertionProbability, double silenceInsertionProbability, double unitInsertionProbability, double fillerInsertionProbability, float languageWeight, bool addOutOfGrammarBranch, double outOfGrammarBranchProbability, double phoneInsertionProbability, AcousticModel phoneLoopAcousticModel) { this.runtime = Runtime.getRuntime(); this.counterForMemoryLogging = 0L; this.EMPTY_ARCS = new SearchStateArc[0]; this.successorCache = new HashMap(); this.logger = Logger.getLogger(Object.instancehelper_getClass(this).getName()); this.acousticModel = acousticModel; this.grammar = grammar; this.unitManager = unitManager; LogMath logMath = LogMath.getLogMath(); this.logWordInsertionProbability = logMath.linearToLog(wordInsertionProbability); this.logSilenceInsertionProbability = logMath.linearToLog(silenceInsertionProbability); this.logUnitInsertionProbability = logMath.linearToLog(unitInsertionProbability); this.logFillerInsertionProbability = logMath.linearToLog(fillerInsertionProbability); this.languageWeight = languageWeight; this.addOutOfGrammarBranch = addOutOfGrammarBranch; this.logOutOfGrammarBranchProbability = logMath.linearToLog(outOfGrammarBranchProbability); this.logPhoneInsertionProbability = logMath.linearToLog((double)this.logPhoneInsertionProbability); if (addOutOfGrammarBranch) { this.phoneLoopAcousticModel = phoneLoopAcousticModel; } }
/* * /// (non-Javadoc) * * /// @see edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util.props.PropertySheet) */ public override void newProperties(PropertySheet ps) { logMath = LogMath.getLogMath(); linguist = (Linguist.Linguist)ps.getComponent(PROP_LINGUIST); pruner = (IPruner)ps.getComponent(PROP_PRUNER); scorer = (IAcousticScorer)ps.getComponent(PROP_SCORER); activeListManager = (ActiveListManager)ps.getComponent(PROP_ACTIVE_LIST_MANAGER); _showTokenCount = ps.getBoolean(PROP_SHOW_TOKEN_COUNT); growSkipInterval = ps.getInt(PROP_GROW_SKIP_INTERVAL); _checkStateOrder = ps.getBoolean(PROP_CHECK_STATE_ORDER); maxLatticeEdges = ps.getInt(PROP_MAX_LATTICE_EDGES); acousticLookaheadFrames = ps.getFloat(PROP_ACOUSTIC_LOOKAHEAD_FRAMES); relativeBeamWidth = logMath.linearToLog(ps.getDouble(PROP_RELATIVE_BEAM_WIDTH)); }
/** * /// * /// @param linguist * /// @param pruner * /// @param scorer * /// @param activeListFactory * /// @param showTokenCount * /// @param relativeWordBeamWidth * /// @param growSkipInterval * /// @param wantEntryPruning */ public SimpleBreadthFirstSearchManager(Linguist.Linguist linguist, IPruner pruner, IAcousticScorer scorer, ActiveListFactory activeListFactory, Boolean showTokenCount, double relativeWordBeamWidth, int growSkipInterval, Boolean wantEntryPruning) { this.name = GetType().Name; this.logMath = LogMath.getLogMath(); this.linguist = linguist; this.pruner = pruner; this.scorer = scorer; this.activeListFactory = activeListFactory; this._showTokenCount = showTokenCount; this.growSkipInterval = growSkipInterval; this.wantEntryPruning = wantEntryPruning; this.logRelativeWordBeamWidth = logMath.linearToLog(relativeWordBeamWidth); this.keepAllTokens = true; }
override public void newProperties(PropertySheet ps) { logMath = LogMath.getLogMath(); name = ps.InstanceName; linguist = (Linguist.Linguist)ps.getComponent(PROP_LINGUIST); pruner = (IPruner)ps.getComponent(PROP_PRUNER); scorer = (IAcousticScorer)ps.getComponent(PROP_SCORER); activeListFactory = (ActiveListFactory)ps.getComponent(PROP_ACTIVE_LIST_FACTORY); _showTokenCount = ps.getBoolean(PROP_SHOW_TOKEN_COUNT); double relativeWordBeamWidth = ps.getDouble(PROP_RELATIVE_WORD_BEAM_WIDTH); growSkipInterval = ps.getInt(PROP_GROW_SKIP_INTERVAL); wantEntryPruning = ps.getBoolean(PROP_WANT_ENTRY_PRUNING); logRelativeWordBeamWidth = logMath.linearToLog(relativeWordBeamWidth); this.keepAllTokens = true; }
/** * * @param logMath * @param linguist * @param pruner * @param scorer * @param activeListFactory * @param showTokenCount * @param relativeWordBeamWidth * @param growSkipInterval * @param wantEntryPruning */ public AlignerSearchManager(LogMath logMath, edu.cmu.sphinx.linguist.Linguist linguist, Pruner pruner, AcousticScorer scorer, ActiveListFactory activeListFactory, bool showTokenCount, double relativeWordBeamWidth, int growSkipInterval, bool wantEntryPruning) { this.name = getClass().getName(); this.logger = LogManager.GetLogger(name); this.logMath = logMath; this.linguist = linguist; this.pruner = pruner; this.scorer = scorer; this.activeListFactory = activeListFactory; this.showTokenCountP = showTokenCount; this.growSkipInterval = growSkipInterval; this.wantEntryPruning = wantEntryPruning; this.logRelativeWordBeamWidth = logMath .linearToLog(relativeWordBeamWidth); this.keepAllTokens = false; this.phraseWordList = new List <String>(); }
/** * Calculate the distance between two clusters * * @param c1 the first cluster * @param c2 the second cluster * @return the inter cluster similarity, or Double.NEGATIVE_INFINITY if these clusters should never be clustered * together. */ protected double interClusterDistance(Cluster c1, Cluster c2) { if (areClustersInRelation(c1, c2)) { return(Double.NegativeInfinity); } float totalSim = LogMath.LOG_ZERO; float wordPairCount = (float)0.0; HashSet <String> wordsSeen1 = new HashSet <String>(); LogMath logMath = LogMath.getLogMath(); foreach (Node node1 in c1.getElements()) { String word1 = node1.getWord().getSpelling(); if (wordsSeen1.Contains(word1)) { continue; } wordsSeen1.Add(word1); HashSet <String> wordsSeen2 = new HashSet <String>(); foreach (Node node2 in c2.getElements()) { String word2 = node2.getWord().getSpelling(); if (wordsSeen2.Contains(word2)) { continue; } wordsSeen2.Add(word2); float sim = (float)computePhoneticSimilarity(node1, node2); sim = logMath.linearToLog(sim); sim += (float)wordSubClusterProbability(c1, word1); sim += (float)wordSubClusterProbability(c2, word2); totalSim = logMath.addAsLinear(totalSim, sim); wordPairCount++; } } return(totalSim - logMath.logToLinear(wordPairCount)); }
/** * /// * /// @param linguist * /// @param pruner * /// @param scorer * /// @param activeListManager * /// @param showTokenCount * /// @param relativeWordBeamWidth * /// @param growSkipInterval * /// @param checkStateOrder * /// @param buildWordLattice * /// @param maxLatticeEdges * /// @param acousticLookaheadFrames * /// @param keepAllTokens */ public WordPruningBreadthFirstSearchManager(Linguist.Linguist linguist, IPruner pruner, IAcousticScorer scorer, ActiveListManager activeListManager, Boolean showTokenCount, double relativeWordBeamWidth, int growSkipInterval, Boolean checkStateOrder, Boolean buildWordLattice, int maxLatticeEdges, float acousticLookaheadFrames, Boolean keepAllTokens) { this.logMath = LogMath.getLogMath(); this.linguist = linguist; this.pruner = pruner; this.scorer = scorer; this.activeListManager = activeListManager; this._showTokenCount = showTokenCount; this.growSkipInterval = growSkipInterval; this._checkStateOrder = checkStateOrder; this.buildWordLattice = buildWordLattice; this.maxLatticeEdges = maxLatticeEdges; this.acousticLookaheadFrames = acousticLookaheadFrames; this.keepAllTokens = keepAllTokens; this.relativeBeamWidth = logMath.linearToLog(relativeWordBeamWidth); }
//@Override public override void newProperties(PropertySheet ps) { base.newProperties(ps); //logger = ps.getLogger(); name = ps.getInstanceName(); logMath = (LogMath)ps.getComponent(PROP_LOG_MATH); linguist = (edu.cmu.sphinx.linguist.Linguist)ps.getComponent(PROP_LINGUIST); pruner = (Pruner)ps.getComponent(PROP_PRUNER); scorer = (AcousticScorer)ps.getComponent(PROP_SCORER); activeListFactory = (ActiveListFactory)ps .getComponent(PROP_ACTIVE_LIST_FACTORY); showTokenCountP = JavaToCs.ConvertBool(ps.getBoolean(PROP_SHOW_TOKEN_COUNT)); double relativeWordBeamWidth = ps.getDouble(PROP_RELATIVE_WORD_BEAM_WIDTH); growSkipInterval = ps.getInt(PROP_GROW_SKIP_INTERVAL); wantEntryPruning = JavaToCs.ConvertBool(ps.getBoolean(PROP_WANT_ENTRY_PRUNING)); logRelativeWordBeamWidth = logMath.linearToLog(relativeWordBeamWidth); this.keepAllTokens = true; }
public override void newProperties(PropertySheet ps) { this.logger = ps.getLogger(); this.acousticModel = (AcousticModel)ps.getComponent("acousticModel"); this.grammar = (Grammar)ps.getComponent("grammar"); this.unitManager = (UnitManager)ps.getComponent("unitManager"); LogMath logMath = LogMath.getLogMath(); this.logWordInsertionProbability = logMath.linearToLog(ps.getDouble("wordInsertionProbability")); this.logSilenceInsertionProbability = logMath.linearToLog(ps.getDouble("silenceInsertionProbability")); this.logUnitInsertionProbability = logMath.linearToLog(ps.getDouble("unitInsertionProbability")); this.logFillerInsertionProbability = logMath.linearToLog(ps.getDouble("fillerInsertionProbability")); this.languageWeight = ps.getFloat("languageWeight"); this.addOutOfGrammarBranch = ps.getBoolean("addOutOfGrammarBranch").booleanValue(); this.logOutOfGrammarBranchProbability = logMath.linearToLog(ps.getDouble("outOfGrammarProbability")); this.logPhoneInsertionProbability = logMath.linearToLog(ps.getDouble("phoneInsertionProbability")); if (this.addOutOfGrammarBranch) { this.phoneLoopAcousticModel = (AcousticModel)ps.getComponent("phoneLoopAcousticModel"); } }
public override void allocate() { this.vocabulary.clear(); this.logProbs.clear(); this.logBackoffs.clear(); HashMap hashMap = new HashMap(); HashMap hashMap2 = new HashMap(); HashMap hashMap3 = new HashMap(); int num = 0; Iterator iterator = this.sentences.iterator(); while (iterator.hasNext()) { string text = (string)iterator.next(); string[] array = String.instancehelper_split(text, "\\s+"); ArrayList arrayList = new ArrayList(); arrayList.add(this.dictionary.getSentenceStartWord()); string[] array2 = array; int num2 = array2.Length; for (int i = 0; i < num2; i++) { string text2 = array2[i]; if (String.instancehelper_length(text2) != 0) { this.vocabulary.add(text2); Word word = this.dictionary.getWord(text2); if (word == null) { arrayList.add(Word.__UNKNOWN); } else { arrayList.add(word); } } } arrayList.add(this.dictionary.getSentenceEndWord()); if (arrayList.size() > 0) { HashMap hashMap4 = hashMap; this.addSequence(hashMap4, new WordSequence(new Word[] { (Word)arrayList.get(0) })); num++; } if (arrayList.size() > 1) { num++; HashMap hashMap5 = hashMap; this.addSequence(hashMap5, new WordSequence(new Word[] { (Word)arrayList.get(1) })); HashMap hashMap6 = hashMap2; this.addSequence(hashMap6, new WordSequence(new Word[] { (Word)arrayList.get(0), (Word)arrayList.get(1) })); } for (int j = 2; j < arrayList.size(); j++) { num++; HashMap hashMap7 = hashMap; this.addSequence(hashMap7, new WordSequence(new Word[] { (Word)arrayList.get(j) })); HashMap hashMap8 = hashMap2; this.addSequence(hashMap8, new WordSequence(new Word[] { (Word)arrayList.get(j - 1), (Word)arrayList.get(j) })); HashMap hashMap9 = hashMap3; this.addSequence(hashMap9, new WordSequence(new Word[] { (Word)arrayList.get(j - 2), (Word)arrayList.get(j - 1), (Word)arrayList.get(j) })); } } float num3 = 0.5f; float num4 = 1f - num3; HashMap hashMap10 = new HashMap(); Iterator iterator2 = hashMap.entrySet().iterator(); while (iterator2.hasNext()) { Map.Entry entry = (Map.Entry)iterator2.next(); hashMap10.put(entry.getKey(), Float.valueOf((float)((Integer)entry.getValue()).intValue() * num4 / (float)num)); } LogMath logMath = LogMath.getLogMath(); float num5 = logMath.linearToLog((double)this.unigramWeight); float num6 = logMath.linearToLog((double)(1f - this.unigramWeight)); float num7 = -logMath.linearToLog((double)hashMap10.size()); TreeSet treeSet = new TreeSet(hashMap.keySet()); Iterator iterator3 = new TreeSet(hashMap2.keySet()).iterator(); WordSequence wordSequence = (!iterator3.hasNext()) ? null : ((WordSequence)iterator3.next()); Iterator iterator4 = treeSet.iterator(); while (iterator4.hasNext()) { WordSequence wordSequence2 = (WordSequence)iterator4.next(); float num8 = logMath.linearToLog((double)((Float)hashMap10.get(wordSequence2)).floatValue()); num8 += num5; num8 = logMath.addAsLinear(num8, num7 + num6); this.logProbs.put(wordSequence2, Float.valueOf(num8)); float num9 = 0f; while (wordSequence != null) { int num10 = wordSequence.getOldest().compareTo(wordSequence2); if (num10 > 0) { break; } if (num10 == 0) { num9 += ((Float)hashMap10.get(wordSequence.getNewest())).floatValue(); } wordSequence = ((!iterator3.hasNext()) ? null : ((WordSequence)iterator3.next())); } this.logBackoffs.put(wordSequence2, Float.valueOf(logMath.linearToLog((double)(num3 / (1f - num9))))); } HashMap hashMap11 = new HashMap(); Iterator iterator5 = hashMap2.entrySet().iterator(); while (iterator5.hasNext()) { Map.Entry entry2 = (Map.Entry)iterator5.next(); int num11 = ((Integer)hashMap.get(((WordSequence)entry2.getKey()).getOldest())).intValue(); hashMap11.put(entry2.getKey(), Float.valueOf((float)((Integer)entry2.getValue()).intValue() * num4 / (float)num11)); } TreeSet treeSet2 = new TreeSet(hashMap2.keySet()); iterator3 = new TreeSet(hashMap3.keySet()).iterator(); wordSequence = ((!iterator3.hasNext()) ? null : ((WordSequence)iterator3.next())); Iterator iterator6 = treeSet2.iterator(); while (iterator6.hasNext()) { WordSequence wordSequence3 = (WordSequence)iterator6.next(); this.logProbs.put(wordSequence3, Float.valueOf(logMath.linearToLog((double)((Float)hashMap11.get(wordSequence3)).floatValue()))); float num12 = 0f; while (wordSequence != null) { int num13 = wordSequence.getOldest().compareTo(wordSequence3); if (num13 > 0) { break; } if (num13 == 0) { num12 += ((Float)hashMap11.get(wordSequence.getNewest())).floatValue(); } wordSequence = ((!iterator3.hasNext()) ? null : ((WordSequence)iterator3.next())); } this.logBackoffs.put(wordSequence3, Float.valueOf(logMath.linearToLog((double)(num3 / (1f - num12))))); } iterator6 = hashMap3.entrySet().iterator(); while (iterator6.hasNext()) { Map.Entry entry3 = (Map.Entry)iterator6.next(); float num12 = (float)((Integer)entry3.getValue()).intValue() * num4; num12 /= (float)((Integer)hashMap2.get(((WordSequence)entry3.getKey()).getOldest())).intValue(); this.logProbs.put(entry3.getKey(), Float.valueOf(logMath.linearToLog((double)num12))); } }
/// <summary> /// Initializes a new instance of the <see cref="ActiveListFactory"/> class. /// </summary> /// <param name="absoluteBeamWidth">Width of the absolute beam.</param> /// <param name="relativeBeamWidth">Width of the relative beam.</param> protected ActiveListFactory(int absoluteBeamWidth, double relativeBeamWidth) { logMath = LogMath.getLogMath(); this.absoluteBeamWidth = absoluteBeamWidth; this.logRelativeBeamWidth = logMath.linearToLog(relativeBeamWidth); }