code: def get_bert_optimizer(
      models, type_optimization, learning_rate, fp16=False
  ):
      """Optimizes the network with AdamWithDecay"""
      if type_optimization not in patterns_optimizer:
          print(
              "Error. Type optimizer must be one of %s"
              % (str(patterns_optimizer.keys()))
          )
      parameters_with_decay = []
      parameters_with_decay_names = []
      parameters_without_decay = []
      parameters_without_decay_names = []
      no_decay = ["bias", "gamma", "beta"]
      patterns = patterns_optimizer[type_optimization]
  
      for model in models:
          for n, p in model.named_parameters():
              if any(t in n for t in patterns):
                  if any(t in n for t in no_decay):
                      parameters_without_decay.append(p)
                      parameters_without_decay_names.append(n)
                  else:
                      parameters_with_decay.append(p)
                      parameters_with_decay_names.append(n)
  
      print("The following parameters will be optimized WITH decay:")
      print(ellipse(parameters_with_decay_names, 5, " , "))
      print("The following parameters will be optimized WITHOUT decay:")
      print(ellipse(parameters_without_decay_names, 5, " , "))
  
      optimizer_grouped_parameters = [
          {"params": parameters_with_decay, "weight_decay": 0.01},
          {"params": parameters_without_decay, "weight_decay": 0.0},
      ]
      optimizer = AdamW(
          optimizer_grouped_parameters,
          lr=learning_rate,
          correct_bias=False,
      )
  
      if fp16:
          optimizer = fp16_optimizer_wrapper(optimizer)
  
      return optimizer
  
file_path: BLINK/blink/common/optimizer.py
imports: import torch
  import os
  import numpy
  from pytorch_transformers.modeling_bert import BertPreTrainedModel, BertConfig, BertModel
  from pytorch_transformers.tokenization_bert import BertTokenizer
  from torch import nn
  from pytorch_transformers.file_utils import PYTORCH_PRETRAINED_BERT_CACHE
  from pytorch_transformers.optimization import AdamW
label_desc: Use image node_id 1 for calling a global function with example usage: get_bert_optimizer(models, type_optimization, learning_rate, fp16) and returns: optimizer