class_docstr: Creates a one-hot encoding (OHE) for categorical data. One-hot encoding represents categorical information as a vector where each individual dimension corresponds to a category. A category has a 1:1 mapping between dimension indicated by a "1" in that position. For example, imagine 3 categories, :math:`A`, :math:`B`, and :math:`C`; these can be represented as follows:
  
  .. math::
  
     A &= [1, 0, 0] \
     B &= [0, 1, 0] \
     C &= [0, 0, 1]
  
  The OHE encoder operates in 2 modes:
      (1) "use_unknown=True": Makes an :math:`N+1` length vector for :math:`N` categories, the first index always corresponds to the unknown category.
  
      (2) "use_unknown=False": Makes an :math:`N` length vector for :math:`N` categories, where an empty vector of 0s indicates an unknown/missing category.
  
  An encoder can represent a feature column or target column; in this case it represents a target, `is_target` is `True`, and `target_weights`. The `target_weights` parameter enables users to specify how heavily each class should be weighted within a mixer - useful in imbalanced classes.
  
  By default, `dataprep_ml.StatisticalAnalysis` phase will provide `target_weights` as the relative fraction of each class in the data which is important for imbalanced populations; for example, suppose there is a 80/05/15 imbalanced representation across 3 different classes - `target_weights` will be a vector as such::
  
  target_weights = {"class1": 0.8, "class2": 0.05, "class3": 0.15}
  
  Users should note that models will be presented with the inverse of the target weights, `inv_target_weights`, which will perform the 1/target_value_per_class operation. **This means large values will result in small weights for the model**.
docstr: Encodes pre-processed data into OHE. Unknown/unrecognized classes vector of all 0s.
  
  :param column_data: Pre-processed data to encode
  :returns: Encoded data of form :math:`N_{rows} x N_{categories}`
docstr_tok: ["Encodes","pre-processed","data","into","OHE",".","Unknown\/unrecognized","classes","vector","of","all","0s",".",":","param","column_data",":","Pre-processed","data","to","encode",":","returns",":","Encoded","data","of","form",":","math",":","`","N_","{","rows","}","x","N_","{","categories","}","`"]
code: def encode(self, column_data: Iterable[str]) -> torch.Tensor:
      """
      Encodes pre-processed data into OHE. Unknown/unrecognized classes vector of all 0s.
  
      :param column_data: Pre-processed data to encode
      :returns: Encoded data of form :math:`N_{rows} x N_{categories}`
      """  # noqa
      if not self.is_prepared:
          raise Exception(
              'You need to call "prepare" before calling "encode" or "decode".'
          )
  
      ret = torch.zeros(size=(len(column_data), self.output_size))
  
      for idx, word in enumerate(column_data):
          index = self.map.get(word, None)
  
          if index is not None:
              ret[idx, index] = 1
  
          if self.use_unknown and index is None:
              ret[idx, 0] = 1
  
      return torch.Tensor(ret)
  
file_path: lightwood/lightwood/encoder/categorical/onehot.py
imports: from copy import deepcopy
  from typing import Dict, List, Iterable, Tuple
  import torch
  import numpy
  from scipy.special import softmax
  from lightwood.helpers.log import log
  from lightwood.encoder.base import BaseEncoder
  from lightwood.helpers.constants import _UNCOMMON_WORD
label_desc: Use image node_id 3 for calling the OneHotEncoder obj's underlying member method code with example usage: obj.encode(column_data) and returns: torch