code: def test_regularization(self):
      penalty = self.model.get_regularization_penalty()
      assert penalty == 0
  
      iterator = BasicIterator(batch_size=32)
      trainer = Trainer(
          self.model, None, iterator, self.instances  # optimizer,
      )
  
      # You get a RuntimeError if you call `model.forward` twice on the same inputs.
      # The data and config are such that the whole dataset is one batch.
      training_batch = next(iterator(self.instances, num_epochs=1))
      validation_batch = next(iterator(self.instances, num_epochs=1))
  
      training_loss = trainer._batch_loss(
          training_batch, for_training=True
      ).data
      validation_loss = trainer._batch_loss(
          validation_batch, for_training=False
      ).data
  
      # Training loss should have the regularization penalty, but validation loss should not.
      assert (training_loss == validation_loss).all()
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  from flaky import flaky
  import numpy
  import pytest
  import torch
  from allennlp.common.testing import ModelTestCase
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.params import Params
  from allennlp.data.dataset_readers import DatasetReader
  from allennlp.data.iterators import DataIterator, BasicIterator
  from allennlp.models import Model
  from allennlp.training import Trainer
label_desc: Use image node_id 7 for calling the SimpleTaggerTest obj's underlying member method code with example usage: obj.test_regularization() without return types