code: def get_lm_corpus(datadir, dataset):
      fn = os.path.join(datadir, "cache.pt")
      fn_pickle = os.path.join(datadir, "cache.pkl")
      if os.path.exists(fn):
          logger.info("Loading cached dataset...")
          corpus = torch.load(fn_pickle)
      elif os.path.exists(fn):
          logger.info("Loading cached dataset from pickle...")
          with open(fn, "rb") as fp:
              corpus = pickle.load(fp)
      else:
          logger.info(f"Producing dataset {dataset}...")
          kwargs = {}
          if dataset in ["wt103", "wt2"]:
              kwargs["special"] = ["<eos>"]
              kwargs["lower_case"] = False
          elif dataset == "ptb":
              kwargs["special"] = ["<eos>"]
              kwargs["lower_case"] = True
          elif dataset == "lm1b":
              kwargs["special"] = []
              kwargs["lower_case"] = False
              kwargs["vocab_file"] = os.path.join(
                  datadir, "1b_word_vocab.txt"
              )
          elif dataset in ["enwik8", "text8"]:
              pass
  
          corpus = TransfoXLCorpus(datadir, dataset, **kwargs)
          torch.save(corpus, fn)
  
      return corpus
  
imports: import glob
  import os
  import pickle
  import re
  from collections import Counter, OrderedDict
  from typing import List, Optional, Tuple
  import numpy
  from ...tokenization_utils import PreTrainedTokenizer
  from ...utils import cached_file, is_sacremoses_available, is_torch_available, logging, requires_backends, torch_only_method
label_desc: Use image node_id 3 for calling a global function with example usage: get_lm_corpus(datadir, dataset) and returns: corpus