00001 #ifndef LM_CONFIG__ 00002 #define LM_CONFIG__ 00003 00004 #include "lm/lm_exception.hh" 00005 #include "util/mmap.hh" 00006 00007 #include <iosfwd> 00008 #include <string> 00009 #include <vector> 00010 00011 /* Configuration for ngram model. Separate header to reduce pollution. */ 00012 00013 namespace lm { 00014 00015 class EnumerateVocab; 00016 00017 namespace ngram { 00018 00019 struct Config { 00020 // EFFECTIVE FOR BOTH ARPA AND BINARY READS 00021 00022 // (default true) print progress bar to messages 00023 bool show_progress; 00024 00025 // Where to log messages including the progress bar. Set to NULL for 00026 // silence. 00027 std::ostream *messages; 00028 00029 std::ostream *ProgressMessages() const { 00030 return show_progress ? messages : 0; 00031 } 00032 00033 // This will be called with every string in the vocabulary. See 00034 // enumerate_vocab.hh for more detail. Config does not take ownership; you 00035 // are still responsible for deleting it (or stack allocating). 00036 EnumerateVocab *enumerate_vocab; 00037 00038 00039 // ONLY EFFECTIVE WHEN READING ARPA 00040 00041 // What to do when <unk> isn't in the provided model. 00042 WarningAction unknown_missing; 00043 // What to do when <s> or </s> is missing from the model. 00044 // If THROW_UP, the exception will be of type util::SpecialWordMissingException. 00045 WarningAction sentence_marker_missing; 00046 00047 // What to do with a positive log probability. For COMPLAIN and SILENT, map 00048 // to 0. 00049 WarningAction positive_log_probability; 00050 00051 // The probability to substitute for <unk> if it's missing from the model. 00052 // No effect if the model has <unk> or unknown_missing == THROW_UP. 00053 float unknown_missing_logprob; 00054 00055 // Size multiplier for probing hash table. Must be > 1. Space is linear in 00056 // this. Time is probing_multiplier / (probing_multiplier - 1). No effect 00057 // for sorted variant. 00058 // If you find yourself setting this to a low number, consider using the 00059 // TrieModel which has lower memory consumption. 00060 float probing_multiplier; 00061 00062 // Amount of memory to use for building. The actual memory usage will be 00063 // higher since this just sets sort buffer size. Only applies to trie 00064 // models. 00065 std::size_t building_memory; 00066 00067 // Template for temporary directory appropriate for passing to mkdtemp. 00068 // The characters XXXXXX are appended before passing to mkdtemp. Only 00069 // applies to trie. If NULL, defaults to write_mmap. If that's NULL, 00070 // defaults to input file name. 00071 const char *temporary_directory_prefix; 00072 00073 // Level of complaining to do when loading from ARPA instead of binary format. 00074 enum ARPALoadComplain {ALL, EXPENSIVE, NONE}; 00075 ARPALoadComplain arpa_complain; 00076 00077 // While loading an ARPA file, also write out this binary format file. Set 00078 // to NULL to disable. 00079 const char *write_mmap; 00080 00081 enum WriteMethod { 00082 WRITE_MMAP, // Map the file directly. 00083 WRITE_AFTER // Write after we're done. 00084 }; 00085 WriteMethod write_method; 00086 00087 // Include the vocab in the binary file? Only effective if write_mmap != NULL. 00088 bool include_vocab; 00089 00090 00091 // Left rest options. Only used when the model includes rest costs. 00092 enum RestFunction { 00093 REST_MAX, // Maximum of any score to the left 00094 REST_LOWER, // Use lower-order files given below. 00095 }; 00096 RestFunction rest_function; 00097 // Only used for REST_LOWER. 00098 std::vector<std::string> rest_lower_files; 00099 00100 00101 // Quantization options. Only effective for QuantTrieModel. One value is 00102 // reserved for each of prob and backoff, so 2^bits - 1 buckets will be used 00103 // to quantize (and one of the remaining backoffs will be 0). 00104 uint8_t prob_bits, backoff_bits; 00105 00106 // Bhiksha compression (simple form). Only works with trie. 00107 uint8_t pointer_bhiksha_bits; 00108 00109 00110 // ONLY EFFECTIVE WHEN READING BINARY 00111 00112 // How to get the giant array into memory: lazy mmap, populate, read etc. 00113 // See util/mmap.hh for details of MapMethod. 00114 util::LoadMethod load_method; 00115 00116 00117 // Set defaults. 00118 Config(); 00119 }; 00120 00121 } /* namespace ngram */ } /* namespace lm */ 00122 00123 #endif // LM_CONFIG__