自然语言处理中的统计与神经模型
在自然语言处理(NLP)领域,有多种技术和模型用于处理和理解文本。下面将介绍一些关键的概念和模型。
1. 统计语言模型的计算与应用
首先来看一段代码,它展示了如何计算句子的概率:
c = res.get(words[i-1] +" "+words[i], 0)
N = res.get(words[i], 0)
print("["+words[i-1] + " " + words[i] + "] : " + str(c)
+ " & " + words[i] +" : " + str(N))
prob = (c + 1)/(N + 8) # V = 8
prob_sentence *= prob
return prob_sentence
res = compute_model(sentences)
print(res)
test_sentence = ("I skipped my breakfast yesterday")
prob = test_probability(test_sentence)
print(test_sentence, ": ", prob)
这里的 compute_model 函数会创建一元语法(unigrams)和二元语法(bigrams)的计数,并将它们存储在 res 中,使用了 scikitlearn 的 CountVectorizer 。 test_probability
超级会员免费看
订阅专栏 解锁全文
2015

被折叠的 条评论
为什么被折叠?



