Skip to content

Commit

Permalink
[PERFORMANCE] Adds B_dic for the first word
Browse files Browse the repository at this point in the history
This design can better train the model and have a better prediction accuracy.
  • Loading branch information
Chen Wang committed Dec 10, 2020
1 parent 8077641 commit 36aabd3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions chapter-3/分词.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@
" self.Pi_dic[v] += 1 # 每个句子的第一个字的状态,用于计算初始状态概率\n",
" else:\n",
" self.A_dic[line_state[k - 1]][v] += 1 # 计算转移概率\n",
" self.B_dic[line_state[k]][word_list[k]] = \\\n",
" self.B_dic[line_state[k]].get(word_list[k], 0) + 1.0 # 计算发射概率\n",
" self.B_dic[line_state[k]][word_list[k]] = \\\n",
" self.B_dic[line_state[k]].get(word_list[k], 0) + 1.0 # 计算发射概率\n",
" \n",
" self.Pi_dic = {k: v * 1.0 / line_num for k, v in self.Pi_dic.items()}\n",
" self.A_dic = {k: {k1: v1 / Count_dic[k] for k1, v1 in v.items()}\n",
Expand Down

0 comments on commit 36aabd3

Please sign in to comment.