class_docstr: This abstract class represents a model to be trained. Rather than relying completely
  on the Pytorch Module, we modify the output spec of ``forward`` to be a dictionary.
  
  Models built using this API are still compatible with other pytorch models and can
  be used naturally as modules within other models - outputs are dictionaries, which
  can be unpacked and passed into other layers. One caveat to this is that if you
  wish to use an AllenNLP model inside a Container (such as nn.Sequential), you must
  interleave the models with a wrapper module which unpacks the dictionary into
  a list of tensors.
  
  In order for your model to be trained using the :class:`~allennlp.training.Trainer`
  api, the output dictionary of your Model must include a "loss" key, which will be
  optimised during the training process.
  
  Finally, you can optionally implement :func:`Model.get_metrics` in order to make use
  of early stopping and best-model serialization based on a validation metric in
  :class:`~allennlp.training.Trainer`. Metrics that begin with "_" will not be logged
  to the progress bar by :class:`~allennlp.training.Trainer`.
docstr: Instantiates an already-trained model, based on the experiment
  configuration and some optional overrides.
  
  Parameters
  ----------
  config: Params
      The configuration that was used to train the model. It should definitely
      have a `model` section, and should probably have a `trainer` section
      as well.
  serialization_dir: str = None
      The directory containing the serialized weights, parameters, and vocabulary
      of the model.
  weights_file: str = None
      By default we load the weights from `best.th` in the serialization
      directory, but you can override that value here.
  cuda_device: int = -1
      By default we load the model on the CPU, but if you want to load it
      for GPU usage you can specify the id of your GPU here
  
  
  Returns
  -------
  model: Model
      The model specified in the configuration, loaded with the serialized
      vocabulary and the trained weights.
docstr_tok: ["Instantiates","an","already-trained","model",",","based","on","the","experiment","configuration","and","some","optional","overrides",".","Parameters","--","--","--","--","--","config",":","Params","The","configuration","that","was","used","to","train","the","model",".","It","should","definitely","have","a","`","model","`","section",",","and","should","probably","have","a","`","trainer","`","section","as","well",".","serialization_dir",":","str","=","None","The","directory","containing","the","serialized","weights",",","parameters",",","and","vocabulary","of","the","model",".","weights_file",":","str","=","None","By","default","we","load","the","weights","from","`","best.th","`","in","the","serialization","directory",",","but","you","can","override","that","value","here",".","cuda_device",":","int","=","-1","By","default","we","load","the","model","on","the","CPU",",","but","if","you","want","to","load","it","for","GPU","usage","you","can","specify","the","id","of","your","GPU","here","Returns","--","--","--","-","model",":","Model","The","model","specified","in","the","configuration",",","loaded","with","the","serialized","vocabulary","and","the","trained","weights","."]
code: def load(
      cls, config, serialization_dir, weights_file=None, cuda_device=-1
  ):
      """
      Instantiates an already-trained model, based on the experiment
      configuration and some optional overrides.
  
      Parameters
      ----------
      config: Params
          The configuration that was used to train the model. It should definitely
          have a `model` section, and should probably have a `trainer` section
          as well.
      serialization_dir: str = None
          The directory containing the serialized weights, parameters, and vocabulary
          of the model.
      weights_file: str = None
          By default we load the weights from `best.th` in the serialization
          directory, but you can override that value here.
      cuda_device: int = -1
          By default we load the model on the CPU, but if you want to load it
          for GPU usage you can specify the id of your GPU here
  
  
      Returns
      -------
      model: Model
          The model specified in the configuration, loaded with the serialized
          vocabulary and the trained weights.
      """
  
      # Peak at the class of the model.
      model_type = config["model"]["type"]
  
      # Load using an overridable _load method.
      # This allows subclasses of Model to override _load.
      # pylint: disable=protected-access
      return cls.by_name(model_type)._load(
          config, serialization_dir, weights_file, cuda_device
      )
  
imports: from __future__ import with_statement
  from __future__ import absolute_import
  import logging
  import os
  import numpy
  import torch
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.params import Params
  from allennlp.common.registrable import Registrable
  from allennlp.data import Instance, Vocabulary
  from allennlp.data.dataset import Batch
  from allennlp.nn import util
  from allennlp.nn.regularizers import RegularizerApplicator
label_desc: Use image node_id 12 for calling the Model obj's underlying member method code with example usage: obj.load(cls, config, serialization_dir, weights_file, cuda_device) and returns: cls