code: def test_optimizer_parameter_groups(self):
      optimizer_params = Params(
          {
              "type": "sgd",
              "lr": 1,
              "momentum": 5,
              "parameter_groups": [
                  # the repeated "bias_" checks a corner case
                  # NOT_A_VARIABLE_NAME displays a warning but does not raise an exception
                  [
                      [
                          "weight_i",
                          "bias_",
                          "bias_",
                          "NOT_A_VARIABLE_NAME",
                      ],
                      {"lr": 2},
                  ],
                  [["tag_projection_layer"], {"lr": 3}],
                  [
                      ["^text_field_embedder.*$"],
                      {"requires_grad": False},
                  ],
              ],
          }
      )
  
      # Before initializing the optimizer all params in this module will still require grad.
      assert all(
          [
              param.requires_grad
              for param in self.model.text_field_embedder.parameters()
          ]
      )
  
      parameters = [
          [n, p]
          for n, p in self.model.named_parameters()
          if p.requires_grad
      ]
      optimizer = Optimizer.from_params(
          model_parameters=parameters, params=optimizer_params
      )
      param_groups = optimizer.param_groups
  
      # After initializing the optimizer, requires_grad should be false for all params in this module.
      assert not any(
          [
              param.requires_grad
              for param in self.model.text_field_embedder.parameters()
          ]
      )
  
      assert len(param_groups) == 3
      assert param_groups[0]["lr"] == 2
      assert param_groups[1]["lr"] == 3
      # base case uses default lr
      assert param_groups[2]["lr"] == 1
      for k in range(3):
          assert param_groups[k]["momentum"] == 5
  
      # all LSTM parameters except recurrent connections (those with weight_h in name)
      assert len(param_groups[0]["params"]) == 6
      # just the projection weight and bias
      assert len(param_groups[1]["params"]) == 2
      # the recurrent connections left in the default group
      assert len(param_groups[2]["params"]) == 2
  
imports: import copy
  import re
  from allennlp.common.params import Params
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.data import Vocabulary
  from allennlp.data.dataset_readers import SequenceTaggingDatasetReader
  from allennlp.data.data_loaders import SimpleDataLoader
  from allennlp.models.simple_tagger import SimpleTagger
  from allennlp.training import GradientDescentTrainer
  from allennlp.training.optimizers import Optimizer
label_desc: Use image node_id 3 for calling the TestOptimizer obj's underlying member method code with example usage: obj.test_optimizer_parameter_groups() without return types