示例#1
0
 def create_and_check_roberta_for_masked_lm(self, config, input_ids,
                                            token_type_ids, input_mask,
                                            sequence_labels, token_labels,
                                            choice_labels):
     model = TFRobertaForMaskedLM(config=config)
     result = model([input_ids, input_mask, token_type_ids])
     self.parent.assertEqual(
         result.logits.shape,
         (self.batch_size, self.seq_length, self.vocab_size))
 def create_and_check_roberta_for_masked_lm(self, config, input_ids, token_type_ids, input_mask, sequence_labels,
                                            token_labels, choice_labels):
     model = TFRobertaForMaskedLM(config=config)
     prediction_scores = model([input_ids, input_mask, token_type_ids])[0]
     result = {
         "prediction_scores": prediction_scores.numpy(),
     }
     self.parent.assertListEqual(
         list(result["prediction_scores"].shape),
         [self.batch_size, self.seq_length, self.vocab_size])
示例#3
0
    def test_inference_masked_lm(self):
        model = TFRobertaForMaskedLM.from_pretrained("roberta-base")

        input_ids = tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]])
        output = model(input_ids)[0]
        expected_shape = [1, 11, 50265]
        self.assertEqual(list(output.numpy().shape), expected_shape)
        # compare the actual values for a slice.
        expected_slice = tf.constant(
            [[[33.8802, -4.3103, 22.7761], [4.6539, -2.8098, 13.6253], [1.8228, -3.6898, 8.8600]]]
        )
        self.assertTrue(numpy.allclose(output[:, :3, :3].numpy(), expected_slice.numpy(), atol=1e-4))