deepmorpheus/model.py
def accuracy(self, sentence, outputs):
        """Calculates the summed/mean accuracy for this sentence as well as the accuracy by tag"""
        sum_accuracy = 0.0
        sentence_len = len(sentence)
        sum_acc_by_tag = [0 for i in range(self.tag_len)]
        for word_idx in range(sentence_len):
            output = outputs[word_idx]
            target = sentence[word_idx][2]

            try:
                acc = [(torch.argmax(output[i]) == target[i]).float() for i in range(self.tag_len)] # Accuracy per tag per word
                sum_accuracy += sum(acc) / self.tag_len # Accuracy per word
                sum_acc_by_tag = add_element_wise(sum_acc_by_tag, acc)

            # During development this happened once or twice, should not happen anymore, but let's leave it in there
            except Exception as e:
                print(e)

        acc_by_tag = [acc / sentence_len for acc in sum_acc_by_tag]

        return sum_accuracy / sentence_len, acc_by_tag
Calculates the summed/mean accuracy for this sentence as well as the accuracy by tag
Calculates the summed/mean accuracy for this sentence as well as the accuracy by tag
Calculates the summed / mean accuracy for this sentence as well as the accuracy by tag
def accuracy(self, sentence, outputs):
        sum_accuracy = 0.0
        sentence_len = len(sentence)
        sum_acc_by_tag = [0 for i in range(self.tag_len)]
        for word_idx in range(sentence_len):
            output = outputs[word_idx]
            target = sentence[word_idx][2]
            try:
                acc = [(torch.argmax(output[i]) == target[i]).float() for i in range(self.tag_len)] 
                sum_accuracy += sum(acc) / self.tag_len 
                sum_acc_by_tag = add_element_wise(sum_acc_by_tag, acc)
            except Exception as e:
                print(e)
        acc_by_tag = [acc / sentence_len for acc in sum_acc_by_tag]
        return sum_accuracy / sentence_len, acc_by_tag
def accuracy ( self , sentence , outputs ) : sum_accuracy = 0.0 sentence_len = len ( sentence ) sum_acc_by_tag = [ 0 for i in range ( self . tag_len ) ] for word_idx in range ( sentence_len ) : output = outputs [ word_idx ] target = sentence [ word_idx ] [ 2 ] try : acc = [ ( torch . argmax ( output [ i ] ) == target [ i ] ) . float ( ) for i in range ( self . tag_len ) ] sum_accuracy += sum ( acc ) / self . tag_len sum_acc_by_tag = add_element_wise ( sum_acc_by_tag , acc ) except Exception as e : print ( e ) acc_by_tag = [ acc / sentence_len for acc in sum_acc_by_tag ] return sum_accuracy / sentence_len , acc_by_tag
Calculates the summed/mean accuracy for this sentence as well as the accuracy by tag
Calculates the summed / mean accuracy for this sentence as well as the accuracy by tag
"""Calculates the summed/mean accuracy for this sentence as well as the accuracy by tag""" # Accuracy per tag per word # Accuracy per word # During development this happened once or twice, should not happen anymore, but let's leave it in there
self
sentence
outputs