deepmorpheus/model.py
def nll_loss(self, sentence, outputs):
        """Calculates NLL loss over the combination of the predicted output and the ground truth"""
        loss_all_words = 0.0
        for word_idx in range(len(sentence)):
            output = outputs[word_idx]
            target = sentence[word_idx][2]

            try:
                loss_per_tag = [F.nll_loss(output[tag_idx].unsqueeze(0), target[tag_idx]) for tag_idx in range(self.tag_len)]
                loss_all_words += sum(loss_per_tag)
            except Exception as e:
                print(e)
                print('output 5: %s' % str(output[5].unsqueeze(0)))
                print('target 5: %s' % target[5])

        return loss_all_words / len(sentence)
Calculates NLL loss over the combination of the predicted output and the ground truth
Calculates NLL loss over the combination of the predicted output and the ground truth
Calculates NLL loss over the combination of the predicted output and the ground truth
def nll_loss(self, sentence, outputs):
        loss_all_words = 0.0
        for word_idx in range(len(sentence)):
            output = outputs[word_idx]
            target = sentence[word_idx][2]
            try:
                loss_per_tag = [F.nll_loss(output[tag_idx].unsqueeze(0), target[tag_idx]) for tag_idx in range(self.tag_len)]
                loss_all_words += sum(loss_per_tag)
            except Exception as e:
                print(e)
                print('output 5: %s' % str(output[5].unsqueeze(0)))
                print('target 5: %s' % target[5])
        return loss_all_words / len(sentence)
def nll_loss ( self , sentence , outputs ) : loss_all_words = 0.0 for word_idx in range ( len ( sentence ) ) : output = outputs [ word_idx ] target = sentence [ word_idx ] [ 2 ] try : loss_per_tag = [ F . nll_loss ( output [ tag_idx ] . unsqueeze ( 0 ) , target [ tag_idx ] ) for tag_idx in range ( self . tag_len ) ] loss_all_words += sum ( loss_per_tag ) except Exception as e : print ( e ) print ( 'output 5: %s' % str ( output [ 5 ] . unsqueeze ( 0 ) ) ) print ( 'target 5: %s' % target [ 5 ] ) return loss_all_words / len ( sentence )
Calculates NLL loss over the combination of the predicted output and the ground truth
Calculates NLL loss over the combination of the predicted output and the ground truth
"""Calculates NLL loss over the combination of the predicted output and the ground truth"""
self
sentence
outputs