def test_baseline_generation(self): baseline_generator = BaselineGenerator(self.model, self.data_handler, "cpu") embedding_list = configure_model_integ_grads_embeddings(self.model) integrated_gradients_embedding = embedding_list[0] self.assertTrue( torch.allclose( baseline_generator.generate_baseline( integrated_gradients_embedding, 5)[0], torch.tensor([[1, 1, 1, 1, 1]]), ))
def test_word_embeddings(self): embedding_list = configure_model_integ_grads_embeddings(self.model) integrated_gradients_embedding = embedding_list[0] input = torch.arange(0, 300).unsqueeze(0).unsqueeze(0) self.assertEqual(integrated_gradients_embedding.embedding_dim, 300) self.assertEqual(embedding_list.embedding_dim[0], 300) self.assertEqual(embedding_list(input).shape[2], input.shape[2]) self.assertTrue( torch.allclose( integrated_gradients_embedding.get_attribution_map(input) ["word"], input))