📄 searchlevel.h
字号:
// file: $isip/class/search/SearchLevel/SearchLevel.h// version: $Id: SearchLevel.h,v 1.50 2003/03/21 16:40:00 huang Exp $//// make sure definitions are only made once//#ifndef ISIP_SEARCH_LEVEL#define ISIP_SEARCH_LEVEL// isip include files://#ifndef ISIP_SEARCH_SYMBOL#include <SearchSymbol.h>#endif#ifndef ISIP_STATISTICAL_MODEL#include <StatisticalModel.h>#endif#ifndef ISIP_MIXTURE_MODEL#include <MixtureModel.h>#endif#ifndef ISIP_GAUSSIAN_MODEL#include <GaussianModel.h>#endif#ifndef ISIP_NGRAM_MODEL#include <NGramModel.h>#endif#ifndef ISIP_DI_GRAPH#include <DiGraph.h>#endif#ifndef ISIP_NAME_MAP#include <NameMap.h>#endif#ifndef ISIP_CONTEXT_MAP#include <ContextMap.h>#endif#ifndef ISIP_HASHTABLE#include <HashTable.h>#endif#ifndef ISIP_FILENAME#include <Filename.h>#endif#ifndef ISIP_SDB#include <Sdb.h>#endif#ifndef ISIP_STRING#include <String.h>#endif#ifndef ISIP_BOOLEAN#include <Boolean.h>#endif#ifndef ISIP_FLOAT#include <Float.h>#endif#ifndef ISIP_LONG#include <Long.h>#endif// forward class definitions//class SearchNode;class Context;// SearchLevel: this class represents a particular level in the search// hierarchy for a hierarchical search engine. each level has the following// characteristics://// a) a beam pruning threshold// b) an instance pruning threshold// c) ability to hold context-dependent models with arbitrary left and right// contexts// d) ability to hold N-symbol context probabilities with arbitrary left// contexts + backoffs// e) maintain or discard old search tokens. for instance, once a higher// level symbol is completed, it may no longer be necessary to maintain// the lower level units that generated that symbol.//class SearchLevel { //--------------------------------------------------------------------------- // // public constants // //---------------------------------------------------------------------------public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String PARAM_DELIM1; static const String PARAM_DELIM2; static const String PARAM_DELIM3; static const String PARAM_LEVEL_TAG; static const String PARAM_SYMBOL; static const String PARAM_NONSPEECH_SYMBOL; static const String PARAM_DUMMY_SYMBOL; static const String PARAM_EXCLUDE_SYMBOL; static const String PARAM_CONTEXTLESS_SYMBOL; static const String PARAM_SKIP_SYMBOL; static const String PARAM_MODEL; static const String PARAM_STAT_HASH; static const String PARAM_STAT; static const String PARAM_STAT_OCCUPANCY; static const String PARAM_USE_NSYMBOL; static const String PARAM_NSYMBOL_ORDER; static const String PARAM_LM_SCALE; static const String PARAM_TR_SCALE; static const String PARAM_SYMBOL_PENALTY; static const String PARAM_NSYMBOL_MODEL; static const String PARAM_USE_CONTEXT; static const String PARAM_CONTEXT_MAPPING; static const String PARAM_USE_LEXICAL_TREE; static const String PARAM_LEFT_CONTEXT_LENGTH; static const String PARAM_RIGHT_CONTEXT_LENGTH; static const String PARAM_USE_BEAM; static const String PARAM_BEAM_THRESHOLD; static const String PARAM_USE_INSTANCE; static const String PARAM_INSTANCE_THRESHOLD; static const String PARAM_WRITE_SYMBOL_OCCUPANCY; static const String PARAM_SYMBOL_OCCUPANCY_FILE; static const String PARAM_NUM_OF_MIXTURES; static const String PARAM_STAT_MODEL_TYPE; //---------------------------------------- // // default values and arguments // //---------------------------------------- // define default value(s) of the class data // static const long DEF_TAG = -1; static const long DEF_LEVEL_INDEX = 0; // beam pruning parameters // static const boolean DEF_BEAM_PRUNE = false; static const float DEF_BEAM_THRESHOLD = 300.0; // instance pruning parameters // static const boolean DEF_INSTANCE_PRUNE = false; static const long DEF_INSTANCE_THRESHOLD = 3000; // context modes parameters // static const boolean DEF_USE_CONTEXT = false; static const boolean DEF_USE_LEXICAL_TREE = false; static const long DEF_LEFT_CONTEXT = 0; static const long DEF_RIGHT_CONTEXT = 0; // n-symbol modes parameters // static const boolean DEF_USE_NSYMBOL = false; static const long DEF_NSYMBOL_ORDER = 0; static const float DEF_SYMBOL_PENALTY = 0.0; static const float DEF_LM_SCALE = 1.0; static const float DEF_TR_SCALE = 1.0; // symbol occupancy parameters // static const boolean DEF_WRITE_SYMBOL_OCCUPANCY = false; // num of mixtures // static const long DEF_NUM_OF_MIXTURES = 1; //--------------------------------------- // // error codes // //--------------------------------------- static const long ERR = (long)90800; //--------------------------------------------------------------------------- // // protected data // //---------------------------------------------------------------------------protected: // level number // Long level_index_d; // level tag // String level_tag_d; // num of mixtures // Long num_of_mixtures_d; // type of the statistical model // StatisticalModel::TYPE stat_model_type_d; // symbols at this level, // eg. if this is word level, symbols are all the words // if phone level, symbols are all the phones // Vector<SearchSymbol> symbol_table_d; // non-speech symbols at this level, // symbols that are inserted between each symbol in the training process // Vector<SearchSymbol> nonspeech_symbol_table_d; // dummy symbols at this level, // symbols that act as mere place holders in the decoding process // Vector<SearchSymbol> dummy_symbol_table_d; // exclude symbols at this level, // symbols that are excluded form the final hypothesis // Vector<SearchSymbol> exclude_symbol_table_d; // context less symbols at this level, // symbols that are context-independent throughout the decoding process // Vector<SearchSymbol> contextless_symbol_table_d; // skip symbols at this level, // symbols that are context-independent and cannot be a context for // any other symbol // Vector<SearchSymbol> skip_symbol_table_d; // symbol to statistical model mapping at this level, // hashtable of symbol and its index in the stat_models_d // this is for finding the index of a statistical model (value) // corresponding to a symbol (key) // HashTable<SearchSymbol, Long> symbol_hash_d; // statistical models at this level, // statistical modesl have a unique index that can be cross referenced // via the hashtable of symbol symbol_hash_d // Vector<StatisticalModel> stat_models_d; // subgraph of the symbols at this level, // if this is the word level, the sub_graphs will be the phone network(s), // if this is the phone level, the sub_graphs will be the HMM(s) // Vector<DiGraph<SearchNode> > sub_graphs_d; // variables related to evaluation of n-symbol probabilities at this level, // order 1 is equivalent to prob{Symbol(n)} // order 2 is equivalent to prob{Symbol(n) | Symbol(n-1)} // order 3 is equivalent to prob{Symbol(n) | Symbol(n-1), Symbol(n-2)} // likewise for orders 4, 5, 6, ..., N // Boolean use_nsymbol_d; Long nsymbol_order_d; // member variable that computes the n-symbol probability of a sequence // Filename nsymbol_file_d; NGramModel nsymbol_model_d; // member variables related to the scale and symbol insertion penalty // Float tr_scale_d; Float lm_scale_d; Float symbol_penalty_d; // variables related to context dependency at this level, // member variables related to generation of context-dependent expansion of // models for evaluation // Boolean use_context_d; Long left_context_d; Long right_context_d; // member variable that associates a context with a subgraph index // Vector<ContextMap> context_map_d; HashTable<Context, Ulong> context_hash_d; // member variables related to generation of lexical tree expansion of // models for evaluation // Boolean use_lexical_tree_d; // variables related to prunning at this level at this level, // member variables related to beam pruning. if the flag is set to true, // beam pruning will be employed at this level with the given beam threshold // Boolean use_beam_prune_d; Float beam_threshold_d; // member variables related to instance pruning. if the flag is set to // true, instance pruning will be employed at this level with only the // given number of instances maintained. // Boolean use_instance_prune_d; Long instance_threshold_d; // member variable related to symbol occupancies. the symbol // occupancies will be written to the file only when the flag is // true // Filename symbol_occupancy_file_d; Boolean write_symbol_occupancy_d; // define a static debug level // static Integral::DEBUG debug_level_d; // define a static memory manager // static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //---------------------------------------------------------------------------public: // method: name // static const String& name() { return CLASS_NAME; } // other static methods // static boolean diagnose(Integral::DEBUG debug_level); // debug methods // boolean debug(const unichar* message) const; // method: setDebug // static boolean setDebug(Integral::DEBUG debug_level) { debug_level_d = debug_level; return true; } // destructor/constructor(s) // ~SearchLevel(); SearchLevel(); SearchLevel(const SearchLevel& copy_level); // assign methods // boolean assign(const SearchLevel& copy_level); // sofSize methods // long sofSize() const; // method: read // boolean read(Sof& sof, long tag, const String& cname = CLASS_NAME); // method: write // boolean write(Sof& sof, long tag, const String& cname = CLASS_NAME) const; // method: readData // boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false); // method: writeData // boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const; // equality methods // boolean eq(const SearchLevel& compare_level) const; // method: new // static void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete // static void operator delete(void* ptr) { mgr_d.release(ptr); } // method: delete[] // static void operator delete[](void* ptr) { mgr_d.releaseBlock(ptr); } // method: setGrowSize // static boolean setGrowSize(long grow_size) { return mgr_d.setGrow(grow_size); } // clear methods // boolean clear(Integral::CMODE ctype = Integral::DEF_CMODE); //--------------------------------------------------------------------------- // // class-specific public methods // //---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -