Ejemplo n.º 1
0
    def test(self):
        self.model.eval()  # set to eval mode
        self.model = self.model.to(device)
        predictions = TestLanguageModel.prediction(
            fixtures_pred['inp'], self.model)  # get predictions
        self.predictions.append(predictions)
        generated_logits = TestLanguageModel.generation(
            fixtures_gen, 10, self.model)  # generated predictions for 10 words
        generated_logits_test = TestLanguageModel.generation(
            fixtures_gen_test, 10, self.model)
        nll = test_prediction(predictions, fixtures_pred['out'])
        generated = test_generation(fixtures_gen, generated_logits, vocab)
        generated_test = test_generation(fixtures_gen_test,
                                         generated_logits_test, vocab)
        self.val_losses.append(nll)

        self.generated.append(generated)
        self.generated_test.append(generated_test)
        self.generated_logits.append(generated_logits)
        self.generated_logits_test.append(generated_logits_test)

        # generate predictions for test data
        predictions_test = TestLanguageModel.prediction(
            fixtures_pred_test['inp'], self.model)  # get predictions
        self.predictions_test.append(predictions_test)

        print('[VAL]  Epoch [%d/%d]   Loss: %.4f' %
              (self.epochs + 1, self.max_epochs, nll))
        return nll
Ejemplo n.º 2
0
    def test(self):
        # don't change these
        self.model.eval()  # set to eval mode
        predictions = TestLanguageModel.prediction(
            fixtures_pred['inp'], self.model)  # get predictions
        print(predictions.shape)
        self.predictions.append(predictions)
        nll = test_prediction(predictions, fixtures_pred['out'])

        generated_logits = TestLanguageModel.generation(
            fixtures_gen, 10, self.model)  # predictions for 20 words
        generated_logits_test = TestLanguageModel.generation(
            fixtures_gen_test, 10, self.model)  # predictions for 20 words

        generated = test_generation(fixtures_gen, generated_logits, vocab)
        generated_test = test_generation(fixtures_gen_test,
                                         generated_logits_test, vocab)
        self.val_losses.append(nll)

        self.generated.append(generated)
        self.generated_test.append(generated_test)
        self.generated_logits.append(generated_logits)
        self.generated_logits_test.append(generated_logits_test)

        # generate predictions for test data
        predictions_test = TestLanguageModel.prediction(
            fixtures_pred_test['inp'], self.model)  # get predictions
        self.predictions_test.append(predictions_test)

        print('[VAL]  Epoch [%d/%d]   NLL: %.4f' %
              (self.epochs, self.max_epochs, nll))
        return nll
Ejemplo n.º 3
0
    def test(self):
        self.model.eval()  # set to eval mode
        predictions = TestLanguageModel.prediction(
            fixtures_pred['inp'], self.model)  # get predictions
        nll = test_prediction(predictions, fixtures_pred['out'])

        print('[VAL]  Epoch [%d/%d]   NLL: %.4f' %
              (self.epochs, self.max_epochs, nll))
        return nll