class_docstr: Basic class for a `Learner` in NLP.
class_docstr_tok: ["Basic","class","for","a","`","Learner","`","in","NLP","."]
docstr: Load a pretrained model and adapt it to the data vocabulary.
docstr_tok: ["Load","a","pretrained","model","and","adapt","it","to","the","data","vocabulary","."]
code: def load_pretrained(
      self,
      wgts_fname: str,  # Filename of saved weights
      vocab_fname: str,  # Saved vocabulary filename in pickle format
      model=None,  # Model to load parameters from, defaults to `Learner.model`
  ):
      "Load a pretrained model and adapt it to the data vocabulary."
      old_vocab = load_pickle(vocab_fname)
      new_vocab = _get_text_vocab(self.dls)
      distrib_barrier()
      wgts = torch.load(
          wgts_fname, map_location=lambda storage, loc: storage
      )
      if "model" in wgts:
          wgts = wgts[
              "model"
          ]  # Just in case the pretrained model was saved with an optimizer
      wgts = match_embeds(wgts, old_vocab, new_vocab)
      load_ignore_keys(
          self.model if model is None else model, clean_raw_keys(wgts)
      )
      self.freeze()
      return self
  
imports: from __future__ import annotations
  from ..basics import *
  from .core import *
  from .data import *
  from .models.core import *
  from .models.awdlstm import *
  from ..callback.rnn import *
  from ..callback.progress import *
  from .models.core import _model_meta
label_desc: Use image node_id 4 for calling the TextLearner obj's underlying member method code with example usage: obj.load_pretrained(wgts_fname, vocab_fname, model) and returns: self