docstr: :param is_target: Whether this encoder represents the target. NOT functional for text generation yet.
  :param batch_size: size of batch while fine-tuning
  :param max_position_embeddings: max sequence length of input text
  :param frozen: If True, freezes transformer layers during training.
  :param epochs: number of epochs to train model with
  :param output_type: Data dtype of the target; if categorical/binary, the option to return logits is possible.
  :param embed_mode: If True, assumes the output of the encode() step is the CLS embedding (this can be trained or not). If False, returns the logits of the tuned task.
  :param device: name of the device that get_device_from_name will attempt to use.
docstr_tok: [":","param","is_target",":","Whether","this","encoder","represents","the","target",".","NOT","functional","for","text","generation","yet",".",":","param","batch_size",":","size","of","batch","while","fine-tuning",":","param","max_position_embeddings",":","max","sequence","length","of","input","text",":","param","frozen",":","If","True",",","freezes","transformer","layers","during","training",".",":","param","epochs",":","number","of","epochs","to","train","model","with",":","param","output_type",":","Data","dtype","of","the","target",";","if","categorical\/binary",",","the","option","to","return","logits","is","possible",".",":","param","embed_mode",":","If","True",",","assumes","the","output","of","the","encode","(",")","step","is","the","CLS","embedding","(","this","can","be","trained","or","not",")",".","If","False",",","returns","the","logits","of","the","tuned","task",".",":","param","device",":","name","of","the","device","that","get_device_from_name","will","attempt","to","use","."]
code: def __init__(
      self,
      stop_after: float,
      is_target: bool = False,
      batch_size: int = 10,
      max_position_embeddings: int = None,
      frozen: bool = False,
      epochs: int = 1,
      output_type: str = None,
      embed_mode: bool = True,
      device: str = "",
  ):
      """
      :param is_target: Whether this encoder represents the target. NOT functional for text generation yet.
      :param batch_size: size of batch while fine-tuning
      :param max_position_embeddings: max sequence length of input text
      :param frozen: If True, freezes transformer layers during training.
      :param epochs: number of epochs to train model with
      :param output_type: Data dtype of the target; if categorical/binary, the option to return logits is possible.
      :param embed_mode: If True, assumes the output of the encode() step is the CLS embedding (this can be trained or not). If False, returns the logits of the tuned task.
      :param device: name of the device that get_device_from_name will attempt to use.
      """  # noqa
      super().__init__(is_target)
  
      self.output_type = output_type
      self.name = "distilbert text encoder"
  
      self._max_len = max_position_embeddings
      self._frozen = frozen
      self._batch_size = batch_size
      self._epochs = epochs
      self._patience = 3  # measured in batches rather than epochs
      self._val_loss_every = 5  # how many batches to wait before checking val loss. If -1, will check train loss instead of val for early stopping.  # noqa
      self._tr_loss_every = 2  # same as above, but only applies if `_val_loss_every` is set to -1
  
      # Model setup
      self._model = None
      self.model_type = None
  
      self._classifier_model_class = DistilBertForSequenceClassification
      self._embeddings_model_class = DistilBertModel
      self._pretrained_model_name = "distilbert-base-uncased"
      self._tokenizer = DistilBertTokenizerFast.from_pretrained(
          self._pretrained_model_name
      )
  
      self.device = get_device_from_name(device)
  
      self.stop_after = stop_after
  
      self.embed_mode = embed_mode
      self.uses_target = True
      self.output_size = None
  
      if self.embed_mode:
          log.info(
              "Embedding mode on. [CLS] embedding dim output of encode()"
          )
      else:
          log.info("Embedding mode off. Logits are output of encode()")
  
imports: import os
  import time
  from typing import Iterable
  from collections import deque
  import numpy
  import torch
  from torch.utils.data import DataLoader
  import pandas
  from type_infer.dtype import dtype
  from transformers import DistilBertModel, DistilBertForSequenceClassification, DistilBertTokenizerFast, AdamW, get_linear_schedule_with_warmup
  from sklearn.model_selection import train_test_split
  from lightwood.encoder.text.helpers.pretrained_helpers import TextEmbed
  from lightwood.helpers.device import get_device_from_name
  from lightwood.encoder.base import BaseEncoder
  from lightwood.helpers.log import log
  from lightwood.helpers.torch import LightwoodAutocast
  from lightwood.helpers.general import is_none
label_desc: Use image node_id 1 to create a new PretrainedLangEncoder object from inherited base classes: BaseEncoder with example: obj = PretrainedLangEncoder(stop_after, is_target, batch_size, max_position_embeddings, frozen, epochs, output_type, embed_mode, device)