class_docstr: Container module with an encoder, a recurrent module, and a decoder.
class_docstr_tok: ["Container","module","with","an","encoder",",","a","recurrent","module",",","and","a","decoder","."]
code: def _apply(self, fn):
      # models that were serialized using torch versions older than 1.4.0 lack the _flat_weights_names attribute
      # check if this is the case and if so, set it
      for child_module in self.children():
          if isinstance(child_module, torch.nn.RNNBase) and not hasattr(
              child_module, "_flat_weights_names"
          ):
              _flat_weights_names = []
  
              num_direction = (
                  2 if child_module.__dict__["bidirectional"] else 1
              )
              for layer in range(child_module.__dict__["num_layers"]):
                  for direction in range(num_direction):
                      suffix = "_reverse" if direction == 1 else ""
                      param_names = [
                          "weight_ih_l{}{}",
                          "weight_hh_l{}{}",
                      ]
                      if child_module.__dict__["bias"]:
                          param_names += [
                              "bias_ih_l{}{}",
                              "bias_hh_l{}{}",
                          ]
                      param_names = [
                          x.format(layer, suffix) for x in param_names
                      ]
                      _flat_weights_names.extend(param_names)
  
              child_module._flat_weights_names = _flat_weights_names
  
          child_module._apply(fn)
  
imports: import math
  from pathlib import Path
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import logsumexp, nn
  from torch.optim import Optimizer
  import flair
  from flair.data import Dictionary
  from flair.nn.recurrent import create_recurrent_layer
label_desc: Use image node_id 18 for calling the LanguageModel obj's underlying member method code with example usage: obj._apply(fn) without return types