Example #1
0
 def create_and_check_electra_for_pretraining(
     self, config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
 ):
     model = TFElectraForPreTraining(config=config)
     inputs = {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     (prediction_scores,) = model(inputs)
     result = {
         "prediction_scores": prediction_scores.numpy(),
     }
     self.parent.assertListEqual(list(result["prediction_scores"].shape), [self.batch_size, self.seq_length])
Example #2
0
    def test_inference_masked_lm(self):
        model = TFElectraForPreTraining.from_pretrained(
            "lysandre/tiny-electra-random")
        input_ids = tf.constant([[0, 1, 2, 3, 4, 5]])
        output = model(input_ids)[0]

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

        print(output[:, :3])

        expected_slice = tf.constant([[-0.24651965, 0.8835437, 1.823782]])
        tf.debugging.assert_near(output[:, :3], expected_slice, atol=1e-4)
Example #3
0
 def create_and_check_electra_for_pretraining(self, config, input_ids,
                                              token_type_ids, input_mask,
                                              sequence_labels, token_labels,
                                              choice_labels):
     model = TFElectraForPreTraining(config=config)
     inputs = {
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids
     }
     result = model(inputs)
     self.parent.assertEqual(result.logits.shape,
                             (self.batch_size, self.seq_length))