Beispiel #1
0
    def test_inference_masked_lm(self):
        model = TFDistilBertModel.from_pretrained("distilbert-base-uncased")
        input_ids = tf.constant([[0, 1, 2, 3, 4, 5]])
        output = model(input_ids)[0]

        expected_shape = [1, 6, 768]
        self.assertEqual(output.shape, expected_shape)

        expected_slice = tf.constant([[
            [0.19261885, -0.13732955, 0.4119799],
            [0.22150156, -0.07422661, 0.39037204],
            [0.22756018, -0.0896414, 0.3701467],
        ]])
        tf.debugging.assert_near(output[:, :3, :3], expected_slice, atol=1e-4)
    def create_and_check_distilbert_model(self, config, input_ids, input_mask,
                                          sequence_labels, token_labels,
                                          choice_labels):
        model = TFDistilBertModel(config=config)
        inputs = {"input_ids": input_ids, "attention_mask": input_mask}

        result = model(inputs)

        inputs = [input_ids, input_mask]

        result = model(inputs)

        self.parent.assertEqual(
            result.last_hidden_state.shape,
            (self.batch_size, self.seq_length, self.hidden_size))
 def test_model_from_pretrained(self):
     for model_name in list(
             TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]):
         model = TFDistilBertModel.from_pretrained(model_name)
         self.assertIsNotNone(model)