class_docstr: Basic class for a `Learner` in NLP.
class_docstr_tok: ["Basic","class","for","a","`","Learner","`","in","NLP","."]
docstr: Load the encoder `file` from the model directory, optionally ensuring it's on `device`
docstr_tok: ["Load","the","encoder","`","file","`","from","the","model","directory",",","optionally","ensuring","it","'s","on","`","device","`"]
code: def load_encoder(
      self,
      file: str,  # Filename of the saved encoder
      device: int
      | str
      | torch.device = None,  # Device used to load, defaults to `dls` device
  ):
      "Load the encoder `file` from the model directory, optionally ensuring it's on `device`"
      encoder = get_model(self.model)[0]
      if device is None:
          device = self.dls.device
      if hasattr(encoder, "module"):
          encoder = encoder.module
      distrib_barrier()
      wgts = torch.load(
          join_path_file(file, self.path / self.model_dir, ext=".pth"),
          map_location=device,
      )
      encoder.load_state_dict(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 3 for calling the TextLearner obj's underlying member method code with example usage: obj.load_encoder(file, device) and returns: self