second word

hello ,today is my second day in the blog

today's work is

1.the research about web service with axis of apache

remote precedure calling

在class LanguageModel的基础上,补充完整代码如下: ``` class LanguageModel(LanguageModel): def get_unigram_logp(self, unigram): """Computes the log-probability of unigram under this LanguageModel. Args: unigram (str): Unigram for which to compute the log-probability. Returns: log_p (float): Log-probability of unigram under this LanguageModel. """ count_w1 = self.unigram_counts[unigram] total_tokens = self.total_num_tokens V = len(self.unigram_counts) log_p = np.log((count_w1 + self.lambda_) / (total_tokens + self.lambda_ * V)) return log_p def get_bigram_logp(self, w_1, w_2): """Computes the log-probability of unigram under this LanguageModel. Note: Use self.lambda_ for the unigram-bigram interpolation factor. Args: w_1 (str): First word in bigram. w_2 (str): Second word in bigram. Returns: log_p (float): Log-probability of bigram under this LanguageModel. """ count_w1w2 = self.bigram_counts[(w_1, w_2)] count_w1 = self.unigram_counts[w_1] total_tokens = self.total_num_tokens V = len(self.unigram_counts) log_p = np.log((count_w1w2 + self.lambda_) / (count_w1 + self.lambda_ * V)) + np.log((count_w1 + self.lambda_) / (total_tokens + self.lambda_ * V)) return log_p def get_query_logp(self, query): """Computes the log-probability of query under this LanguageModel. Args: query (str): Whitespace-delimited sequence of terms in the query. Returns: log_p (float): Log-probability assigned to the query under this LanguageModel. """ log_p = 0.0 query_tokens = query.split() for i, token in enumerate(query_tokens): if i == 0: log_p += self.get_unigram_logp(token) else: log_p += self.get_bigram_logp(query_tokens[i-1], token) return log_p ``` 其中,get_unigram_logp方法用于计算给定unigram的对数概率,get_bigram_logp方法用于计算给定bigram的对数概率,get_query_logp方法用于计算给定query的对数概率。这些方法都是基于语言模型的先验概率进行计算的。在计算bigram的对数概率时,使用了一元二元平滑的插值方法,其中self.lambda_为插值因子。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值