class_docstr: Add functionality to `TextLearner` when dealing with a language model
class_docstr_tok: ["Add","functionality","to","`","TextLearner","`","when","dealing","with","a","language","model"]
docstr: Return `text` and the `n_words` that come after
docstr_tok: ["Return","`","text","`","and","the","`","n_words","`","that","come","after"]
code: def predict(
      self,
      text,
      n_words=1,
      no_unk=True,
      temperature=1.0,
      min_p=None,
      no_bar=False,
      decoder=decode_spec_tokens,
      only_last_word=False,
  ):
      "Return `text` and the `n_words` that come after"
      self.model.reset()
      idxs = idxs_all = (
          self.dls.test_dl([text]).items[0].to(self.dls.device)
      )
      if no_unk:
          unk_idx = self.dls.vocab.index(UNK)
      for _ in (
          range(n_words)
          if no_bar
          else progress_bar(range(n_words), leave=False)
      ):
          with self.no_bar():
              preds, _ = self.get_preds(dl=[(idxs[None],)])
          res = preds[0][-1]
          if no_unk:
              res[unk_idx] = 0.0
          if min_p is not None:
              if (res >= min_p).float().sum() == 0:
                  warn(
                      f"There is no item with probability >= {min_p}, try a lower value."
                  )
              else:
                  res[res < min_p] = 0.0
          if temperature != 1.0:
              res.pow_(1 / temperature)
          idx = torch.multinomial(res, 1).item()
          idxs = idxs_all = torch.cat([idxs_all, idxs.new([idx])])
          if only_last_word:
              idxs = idxs[-1][None]
  
      num = self.dls.train_ds.numericalize
      tokens = [
          num.vocab[i]
          for i in idxs_all
          if num.vocab[i] not in [BOS, PAD]
      ]
      sep = self.dls.train_ds.tokenizer.sep
      return sep.join(decoder(tokens))
  
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 1 for calling the LMLearner obj's underlying member method code with example usage: obj.predict(text, n_words, no_unk, temperature, min_p, no_bar, decoder, only_last_word) and returns: sep