def create_and_check_question_encoder(
     self, config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
 ):
     model = DPRQuestionEncoder(config=config)
     model.to(torch_device)
     model.eval()
     result = model(input_ids, attention_mask=input_mask, token_type_ids=token_type_ids)
     result = model(input_ids, token_type_ids=token_type_ids)
     result = model(input_ids)
     self.parent.assertEqual(result.pooler_output.shape, (self.batch_size, self.projection_dim or self.hidden_size))
    def test_init_changed_config(self):
        config = self.model_tester.prepare_config_and_inputs()[0]

        model = DPRQuestionEncoder(config=config)
        model.to(torch_device)
        model.eval()

        with tempfile.TemporaryDirectory() as tmp_dirname:
            model.save_pretrained(tmp_dirname)
            model = DPRQuestionEncoder.from_pretrained(tmp_dirname,
                                                       projection_dim=512)

        self.assertIsNotNone(model)
Пример #3
0
    def create_and_check_dpr_question_encoder(self, config, input_ids,
                                              token_type_ids, input_mask,
                                              sequence_labels, token_labels,
                                              choice_labels):
        model = DPRQuestionEncoder(config=config)
        model.to(torch_device)
        model.eval()
        embeddings = model(input_ids,
                           attention_mask=input_mask,
                           token_type_ids=token_type_ids)[0]
        embeddings = model(input_ids, token_type_ids=token_type_ids)[0]
        embeddings = model(input_ids)[0]

        result = {
            "embeddings": embeddings,
        }
        self.parent.assertListEqual(
            list(result["embeddings"].size()),
            [self.batch_size, self.projection_dim or self.hidden_size])