本文整理汇总了Python中hmm.HMM.initEM方法的典型用法代码示例。如果您正苦于以下问题:Python HMM.initEM方法的具体用法?Python HMM.initEM怎么用?Python HMM.initEM使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hmm.HMM
的用法示例。
在下文中一共展示了HMM.initEM方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: max
# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import initEM [as 别名]
prob = max(V[t - 1][y0]*hmm.transition_p(y0,s)*hmm.emission_p(obs[t],s) for y0 in hmm.states)
V[t][s] = prob
else:
prob = max(V[t - 1][y0]*hmm.transition_p(y0,s)*(1/1000) for y0 in hmm.states)
V[t][s] = prob
opt = []
# For each row in V
for j in V:
# For the tuple of key:value for each column in V
for x, y in j.items():
# If the cell x is the most probable append that state to opt
if j[x] == max(j.values()):
opt.append(x)
# The highest probability value
h = max(V[-1].values())
for i in range(len(obs)):
outfile.write(str(obs[i])+"\t"+str(opt[i])+"\n")
# print('The steps of states are ' + ' '.join(opt) + ' with highest probability of %s'%h)
hmm = HMM(concat_sents)
hmm.initEM()
hmm.initTM()
read_sents = re.split(r'\n{2}', readFile)
read_sents.pop()
obsSents = []
for sent in read_sents:
obsSents.append(sent.split())
for sent in obsSents:
viterbi(sent, hmm, outFile)
outFile.write('\n')