class_docstr: A trainer for training models. 
class_docstr_tok: ["A","trainer","for","training","models","."]
code: def __init__(
      self,
      args=None,
      vocab=None,
      emb_matrix=None,
      model_file=None,
      device=None,
      foundation_cache=None,
  ):
      if model_file is not None:
          # load everything from file
          self.load(model_file, args, foundation_cache)
      else:
          # build model from scratch
          self.args = args
          if args["dict_only"]:
              self.model = None
          else:
              self.model = self.build_seq2seq(
                  args, emb_matrix, foundation_cache
              )
          self.vocab = vocab
          # dict-based components
          self.word_dict = dict()
          self.composite_dict = dict()
      if not self.args["dict_only"]:
          self.model = self.model.to(device)
          if self.args.get("edit", False):
              self.crit = loss.MixLoss(
                  self.vocab["char"].size, self.args["alpha"]
              ).to(device)
              logger.debug(
                  "Running seq2seq lemmatizer with edit classifier..."
              )
          else:
              self.crit = loss.SequenceLoss(self.vocab["char"].size).to(
                  device
              )
          self.optimizer = utils.get_optimizer(
              self.args["optim"], self.model, self.args["lr"]
          )
  
imports: import os
  import sys
  import numpy
  from collections import Counter
  import logging
  import torch
  from torch import nn
  import torch.nn.init
  import stanza.models.common.seq2seq_constant
  from stanza.models.common.foundation_cache import load_charlm
  from stanza.models.common.seq2seq_model import Seq2SeqModel
  from stanza.models.common.char_model import CharacterLanguageModelWordAdapter
  from stanza.models.common import utils, loss
  from stanza.models.lemma import edit
  from stanza.models.lemma.vocab import MultiVocab
label_desc: Use image node_id 1 to create a new Trainer object from inherited base classes: object with example: obj = Trainer(args, vocab, emb_matrix, model_file, device, foundation_cache)