本文整理汇总了C++中Vocab::Find方法的典型用法代码示例。如果您正苦于以下问题:C++ Vocab::Find方法的具体用法?C++ Vocab::Find怎么用?C++ Vocab::Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vocab
的用法示例。
在下文中一共展示了Vocab::Find方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: v
// Returns a vector of LiveGuessResults
// warning: words is mutated temporarily
std::auto_ptr< std::vector<LiveGuessResult> >
forwardish(std::vector<const char *> & words, // the current words can be empty
const double currentProb, // log prob
const int size, // how many to grab
const int depthLeft,
const NgramLM & _lm,
const int _order,
const Vocab & vocab ) {
// Index contains the last ngram word
//Logger::Log(0, "Forwardish [%d] [%d]\n", depthLeft, index);
VocabIndex vwords[ _order ];
//int n = (words.size() < (_order - 1))?words.size():_order;
//for (int i = words.size() - _order - 1; i < words.size(); i++) {
// if ( i >= 0) {
// Logger::Log(0,"Word: %d %s\n",i,words[i]);
// }
//}
//vwords[0] to _order -1 are filled in
// if it's small EndOfSentence starts it..
for (int i = 1; i < _order; i++) {
int j = words.size() - _order + i;
if (j < 0) {
vwords[i - 1] = Vocab::Invalid; // probably should be end of sentence
} else {
vwords[i - 1] = vocab.Find( words[ j ] );
}
}
vector<VocabProb> heap(0);
mkHeap(heap);
const ProbVector & probabilities = _lm.probs( _order ) ;// _order - 2 );
const CountVector & counts = _lm.counts( _order );
int count = 0;
//Logger::Log(0, "Find probabilities %d\n",vocab.size());
for (int j = 0; j < vocab.size(); j++) {
VocabIndex vWordI = j;//vocab[j];
vwords[ _order - 1 ] = j;
NgramIndex newIndex = _lm.model()._Find( vwords, _order );
if (newIndex == -1) { // not legit :(
continue;
}
Prob probRaw = probabilities[ newIndex ];
if (probRaw == 0.0) {
continue;
}
Prob prob = -1 * log( probRaw ); //biggest is smallest
//Prob prob = (probRaw == 0.0)?10000:(-1 * log( probRaw )); //biggest is smallest
//Prob probRaw = (counts[newIndex]==0)?1.0:counts[newIndex]/vocab.size()
//Prob prob = -1 * log(probRaw);
//Prob prob = -1 * counts[newIndex];
//Logger::Log(0, "Prob %e\n",prob);
const VocabProb v( prob,j, newIndex);
if ( count < size ) {
heap.push_back( v );
count++;
if (count == size) {
mkHeap( heap );
}
// this is irritating, basically it means the highest rank stuff
// will be in the list and we only kick out the lowest ranked stuff
// (which will be the GREATEST of what is already there)
//
} else if ( heap.front().prob > prob ) {
// this is dumb
// remove the least element
popHeap( heap );
pushHeap( heap, v );
// should we update?
}
}
sortHeap( heap );
std::vector<LiveGuessResult> * resVector = new std::vector<LiveGuessResult>();
for( int j = 0; j < heap.size(); j++) {
VocabProb v = heap[ j ];
Prob prob = v.prob;
prob += currentProb;
const char * word = vocab[ v.index ];
vector<const char *> ourWords(words);
ourWords.push_back( word ); // add
char * str = joinVectorOfCStrings( ourWords ); // Remember to deallocate later :(
//.........这里部分代码省略.........