示例#1
0
def load_lm_model(lm_fname, order=2): 
    """
    function to load language model 
    """
    lm_model=srilm.initLM(order)
    srilm.readLM(lm_model,lm_fname)    
    return lm_model
示例#2
0
 def __init__(self, m, filename):
     """use srilm language model from filename"""
     self.m = m  #order
     self.model = srilm.initLM(self.m)
     success = srilm.readLM(self.model, filename)
     if not success:
         print('LM load error')
         sys.exit(1)
 def __init__(self, model_path, order=2):
     self.lm_path = model_path
     self.order = order
     self.history = []
     self.EOS_ID = 1
     self.history_len = order - 1
     self.lm = initLM(order)
     readLM(self.lm, self.lm_path)
     self.vocab_size = howManyNgrams(self.lm, 1)
示例#4
0
 def __init__(self, model_path, order=2):
     self.lm_path = model_path
     self.order = order
     self.history = []
     self.EOS_ID = 1
     self.history_len = order - 1
     print u'Initialize LM with order {}'.format(order)
     self.lm = initLM(order)
     readLM(self.lm, self.lm_path)
     self.vocab_size = howManyNgrams(self.lm, 1)
示例#5
0
文件: ngram.py 项目: chagge/sgnmt
 def __init__(self, path, ngram_order):
     """Creates a new n-gram language model predictor.
     
     Args:
         path (string): Path to the ARPA language model file
         ngram_order (int): Order of the language model
         
     Raises:
         NameError. If srilm-swig is not installed
     """
     super(SRILMPredictor, self).__init__()
     self.history_len = ngram_order - 1
     self.lm = initLM(ngram_order)
     readLM(self.lm, path)
示例#6
0
文件: ngram.py 项目: chagge/sgnmt
 def __init__(self, path, ngram_order):
     """Creates a new n-gram language model predictor.
     
     Args:
         path (string): Path to the ARPA language model file
         ngram_order (int): Order of the language model
         
     Raises:
         NameError. If srilm-swig is not installed
     """
     super(SRILMPredictor, self).__init__()
     self.history_len = ngram_order-1
     self.lm = initLM(ngram_order)
     readLM(self.lm, path)
示例#7
0
 def __init__(self, path, ngram_order, convert_to_ln=False):
     """Creates a new n-gram language model predictor.
     
     Args:
         path (string): Path to the ARPA language model file
         ngram_order (int): Order of the language model
         
     Raises:
         NameError. If srilm-swig is not installed
     """
     super(SRILMPredictor, self).__init__()
     self.history_len = ngram_order-1
     self.lm = initLM(ngram_order)
     readLM(self.lm, path)
     self.vocab_size = howManyNgrams(self.lm, 1)
     self.convert_to_ln = convert_to_ln
     if convert_to_ln:
         import logging
         logging.info("SRILM: Convert log scores to ln scores")
示例#8
0
文件: ngram.py 项目: ucam-smt/sgnmt
 def __init__(self, path, ngram_order, convert_to_ln=False):
     """Creates a new n-gram language model predictor.
     
     Args:
         path (string): Path to the ARPA language model file
         ngram_order (int): Order of the language model
         convert_to_ln (bool): Whether to convert ld scores to ln.
         
     Raises:
         NameError. If srilm-swig is not installed
     """
     super(SRILMPredictor, self).__init__()
     self.history_len = ngram_order-1
     self.lm = initLM(ngram_order)
     readLM(self.lm, path)
     self.vocab_size = howManyNgrams(self.lm, 1)
     self.convert_to_ln = convert_to_ln
     if convert_to_ln:
         import logging
         logging.info("SRILM: Convert log scores to ln scores")
示例#9
0
 def _init_lm(self, lm_fname):
     self.lm_model = srilm.initLM(2)
     srilm.readLM(self.lm_model, lm_fname)
 def _init_lm(self,lm_fname): 
     self.lm_model=srilm.initLM(2)
     srilm.readLM(self.lm_model,lm_fname)