Skip to content

Commit

Permalink
deb
Browse files Browse the repository at this point in the history
  • Loading branch information
LiyuanLucasLiu committed Sep 14, 2017
1 parent 4096634 commit 19fc960
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions model/crf.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def forward(self, scores, target, current):
scores: crf scores, of size Word_Seq_len * Batch_size * target_size_from * target_size_to
targer: golden list, of shape Word_Seq_len * Batch_size
current: current state, of shape Word_Seq_len * Batch_size
output:
return:
loss: Loss
"""
ins_num = current.size(0)
Expand All @@ -254,9 +254,6 @@ class CRFLoss_vb(nn.Module):
"""

def __init__(self, tagset_size, start_tag, end_tag, average_batch=True):
"""Constructor
"""
super(CRFLoss_vb, self).__init__()
self.tagset_size = tagset_size
self.start_tag = start_tag
Expand All @@ -265,16 +262,12 @@ def __init__(self, tagset_size, start_tag, end_tag, average_batch=True):

def forward(self, scores, target, mask):
"""
viterbi decode loss, :math:`\frac{ \prod_{j=1}^n \phi(\hat{y}_{j-1}, \hat{y}_j, \mathbf{z}_j) } { \sum_{\mathbf{y}' \in \mathbf{Y}(\mathbf{Z})} \prod_{j=1}^n \phi(y'_{j-1}, y'_j, \mathbf{z}_j)`
.. math::
viterbi decode loss,
\frac{ \prod_{j=1}^n \phi(\hat{y}_{j-1}, \hat{y}_j, \mathbf{z}_j) } { \sum_{\mathbf{y}' \in \mathbf{Y}(\mathbf{Z})} \prod_{j=1}^n \phi(y'_{j-1}, y'_j, \mathbf{z}_j)
args:
scores: crf scores, of size seq_len * bat_size * target_size_from * target_size_to
target: golden state, of size seq_len * bat_size * 1
mask: mask for padding, of size seq_len * bat_size
scores (seq_len, bat_size, target_size_from, target_size_to) : crf scores
target (seq_len, bat_size, 1) : golden state
mask (size seq_len, bat_size) : mask for padding
output:
loss: loss
"""
Expand Down

0 comments on commit 19fc960

Please sign in to comment.