docstr: Test the whole thing on a small dataset for an iteration or two
docstr_tok: ["Test","the","whole","thing","on","a","small","dataset","for","an","iteration","or","two"]
code: def test_build_model(self):
      """
      Test the whole thing on a small dataset for an iteration or two
      """
      with tempfile.TemporaryDirectory() as tempdir:
          eval_file = os.path.join(tempdir, "en_test.dev.txt")
          with open(eval_file, "w", encoding="utf-8") as fout:
              fout.write(fake_text_1)
          train_file = os.path.join(tempdir, "en_test.train.txt")
          with open(train_file, "w", encoding="utf-8") as fout:
              for i in range(1000):
                  fout.write(fake_text_1)
                  fout.write("\n")
                  fout.write(fake_text_2)
                  fout.write("\n")
          save_name = "en_test.forward.pt"
          vocab_save_name = "en_text.vocab.pt"
          checkpoint_save_name = "en_text.checkpoint.pt"
          args = [
              "--train_file",
              train_file,
              "--eval_file",
              eval_file,
              "--eval_steps",
              "0",  # eval once per opoch
              "--epochs",
              "2",
              "--cutoff",
              "1",
              "--batch_size",
              "%d" % len(fake_text_1),
              "--shorthand",
              "en_test",
              "--save_dir",
              tempdir,
              "--save_name",
              save_name,
              "--vocab_save_name",
              vocab_save_name,
              "--checkpoint_save_name",
              checkpoint_save_name,
          ]
          args = charlm.parse_args(args)
          charlm.train(args)
  
          assert os.path.exists(os.path.join(tempdir, vocab_save_name))
  
          # test that saving & loading of the model worked
          assert os.path.exists(os.path.join(tempdir, save_name))
          model = char_model.CharacterLanguageModel.load(
              os.path.join(tempdir, save_name)
          )
  
          # test that saving & loading of the checkpoint worked
          assert os.path.exists(
              os.path.join(tempdir, checkpoint_save_name)
          )
          model = char_model.CharacterLanguageModel.load(
              os.path.join(tempdir, checkpoint_save_name)
          )
          trainer = char_model.CharacterLanguageModelTrainer.load(
              args, os.path.join(tempdir, checkpoint_save_name)
          )
  
          assert trainer.global_step > 0
          assert trainer.epoch == 2
  
          # quick test to verify this method works with a trained model
          charlm.get_current_lr(trainer, args)
  
          # test loading a vocab built by the training method...
          vocab = charlm.load_char_vocab(
              os.path.join(tempdir, vocab_save_name)
          )
          trainer = (
              char_model.CharacterLanguageModelTrainer.from_new_model(
                  args, vocab
              )
          )
          # ... and test the get_current_lr for an untrained model as well
          # this test is super "eager"
          assert charlm.get_current_lr(trainer, args) == args["lr0"]
  
imports: from collections import Counter
  import glob
  import lzma
  import os
  import tempfile
  import pytest
  from stanza.models import charlm
  from stanza.models.common import char_model
  from stanza.tests import TEST_MODELS_DIR
label_desc: Use image node_id 6 for calling the TestCharModel obj's underlying member method code with example usage: obj.test_build_model() without return types