code: def test_embed(self):
      _, train = trec_dataset()  # use small test set as train
  
      kwargs = dict()
      if (
          self.embedding_method
          == KimCNNEmbeddingMixin.EMBEDDING_METHOD_GRADIENT
      ):
          kwargs["module_selector"] = default_module_selector
  
      embedding_matrix = torch.Tensor(
          np.random.rand(len(train.vocab), 100)
      )
      classifier = KimCNNClassifier(
          6, embedding_matrix=embedding_matrix
      )
      classifier.fit(train)
  
      with mock.patch.object(
          classifier.model, "eval", wraps=classifier.model.eval
      ) as model_eval_spy:
          embeddings = classifier.embed(
              train, embedding_method=self.embedding_method, **kwargs
          )
          self.assertFalse(classifier.model.training)
          model_eval_spy.assert_called()
  
          self.assertEqual(len(train), embeddings.shape[0])
          if (
              self.embedding_method
              == KimCNNEmbeddingMixin.EMBEDDING_METHOD_GRADIENT
          ):
              gradient_length = (
                  classifier.model.out_channels
                  * classifier.model.num_kernels
                  * classifier.model.num_classes
              )
              self.assertEqual(
                  classifier.num_classes * gradient_length,
                  embeddings.shape[1],
              )
          else:
              self.assertEqual(
                  classifier.model.out_channels
                  * classifier.model.num_kernels,
                  embeddings.shape[1],
              )
  
file_path: small-text/tests/integration/small_text/integrations/pytorch/classifiers/test_kimcnn_embeddings.py
imports: import unittest
  import pytest
  import numpy
  from unittest import mock
  from parameterized import parameterized_class
  from small_text.integrations.pytorch.exceptions import PytorchNotFoundError
label_desc: Use image node_id 2 for calling the KimCNNEmbeddingTest obj's underlying member method code with example usage: obj.test_embed() without return types