class_docstr: Stores a constituency model and its optimizer
  
  Not inheriting from common/trainer.py because there's no concept of change_lr (yet?)
class_docstr_tok: ["Stores","a","constituency","model","and","its","optimizer","Not","inheriting","from","common\/trainer.py","because","there","'s","no","concept","of","change_lr","(","yet","?",")"]
code: def __init__(
      self,
      model,
      optimizer=None,
      scheduler=None,
      epochs_trained=0,
      batches_trained=0,
      best_f1=0.0,
      best_epoch=0,
  ):
      self.model = model
      self.optimizer = optimizer
      self.scheduler = scheduler
      # keeping track of the epochs trained will be useful
      # for adjusting the learning scheme
      self.epochs_trained = epochs_trained
      self.batches_trained = batches_trained
      self.best_f1 = best_f1
      self.best_epoch = best_epoch
  
imports: from collections import Counter
  from collections import namedtuple
  import copy
  from enum import Enum
  import logging
  from operator import itemgetter
  import os
  import random
  import re
  import sys
  import torch
  from torch import nn
  from stanza.models.common import pretrain
  from stanza.models.common import utils
  from stanza.models.common.foundation_cache import load_bert, load_charlm, load_pretrain, FoundationCache
  from stanza.models.common.large_margin_loss import LargeMarginInSoftmaxLoss
  from stanza.models.constituency import parse_transitions
  from stanza.models.constituency import parse_tree
  from stanza.models.constituency import transition_sequence
  from stanza.models.constituency import tree_reader
  from stanza.models.constituency.base_model import SimpleModel, UNARY_LIMIT
  from stanza.models.constituency.in_order_oracle import InOrderOracle
  from stanza.models.constituency.lstm_model import LSTMModel, StackHistory
  from stanza.models.constituency.parse_transitions import TransitionScheme
  from stanza.models.constituency.parse_tree import Tree
  from stanza.models.constituency.utils import retag_tags, retag_trees, build_optimizer, build_scheduler
  from stanza.models.constituency.utils import DEFAULT_LEARNING_EPS, DEFAULT_LEARNING_RATES, DEFAULT_LEARNING_RHO, DEFAULT_WEIGHT_DECAY
  from stanza.server.parser_eval import EvaluateParser, ParseResult
  from stanza.utils.get_tqdm import get_tqdm
  from stanza.utils.training.common import find_wordvec_pretrain, choose_charlm, find_charlm_file
  from stanza.resources.default_packages import default_charlms, default_pretrains
label_desc: Use image node_id 1 to create a new Trainer object  with example: obj = Trainer(model, optimizer, scheduler, epochs_trained, batches_trained, best_f1, best_epoch)