class_docstr: A trainer for training models. 
class_docstr_tok: ["A","trainer","for","training","models","."]
code: def __init__(
      self,
      args=None,
      vocab=None,
      pretrain=None,
      model_file=None,
      device=None,
      foundation_cache=None,
  ):
      if model_file is not None:
          # load everything from file
          self.load(model_file, pretrain, args, foundation_cache)
      else:
          # build model from scratch
          self.args = args
          self.vocab = vocab
          self.model = Parser(
              args,
              vocab,
              emb_matrix=pretrain.emb if pretrain is not None else None,
          )
      self.model = self.model.to(device)
      self.optimizer = utils.get_optimizer(
          self.args["optim"],
          self.model,
          self.args["lr"],
          betas=(0.9, self.args["beta2"]),
          eps=1e-6,
          bert_learning_rate=self.args.get("bert_learning_rate", 0.0),
      )
  
file_path: stanza/stanza/models/depparse/trainer.py
imports: import sys
  import logging
  import torch
  from torch import nn
  from stanza.models.common.trainer import Trainer
  from stanza.models.common import utils, loss
  from stanza.models.common.foundation_cache import NoTransformerFoundationCache
  from stanza.models.common.chuliu_edmonds import chuliu_edmonds_one_root
  from stanza.models.depparse.model import Parser
  from stanza.models.pos.vocab import MultiVocab
label_desc: Use image node_id 1 to create a new Trainer object from inherited base classes: BaseTrainer with example: obj = Trainer(args, vocab, pretrain, model_file, device, foundation_cache)