class_docstr: Utility functions used to preprocess, save, load, partition, etc. the Criteo
  dataset in a binary (numpy) format.
class_docstr_tok: ["Utility","functions","used","to","preprocess",",","save",",","load",",","partition",",","etc",".","the","Criteo","dataset","in","a","binary","(","numpy",")","format","."]
docstr: Convert one Criteo tsv file to three npy files: one for dense (np.float32), one
  for sparse (np.int32), and one for labels (np.int32).
  
  The tsv file is expected to be part of the Criteo 1TB Click Logs Dataset ("criteo_1tb")
  or the Criteo Kaggle Display Advertising Challenge dataset ("criteo_kaggle").
  
  For the "criteo_kaggle" test set, we set the labels to -1 representing filler data,
  because label data is not included in the "criteo_kaggle" test set.
  
  Args:
      in_file (str): Input tsv file path.
      out_dense_file (str): Output dense npy file path.
      out_sparse_file (str): Output sparse npy file path.
      out_labels_file (str): Output labels npy file path.
      dataset_name (str): The dataset name. "criteo_1tb" or "criteo_kaggle" is expected.
      path_manager_key (str): Path manager key used to load from different
          filesystems.
  
  Returns:
      None.
docstr_tok: ["Convert","one","Criteo","tsv","file","to","three","npy","files",":","one","for","dense","(","np.float32",")",",","one","for","sparse","(","np.int32",")",",","and","one","for","labels","(","np.int32",")",".","The","tsv","file","is","expected","to","be","part","of","the","Criteo","1TB","Click","Logs","Dataset","(","``","criteo_1tb","''",")","or","the","Criteo","Kaggle","Display","Advertising","Challenge","dataset","(","``","criteo_kaggle","''",")",".","For","the","``","criteo_kaggle","''","test","set",",","we","set","the","labels","to","-1","representing","filler","data",",","because","label","data","is","not","included","in","the","``","criteo_kaggle","''","test","set",".","Args",":","in_file","(","str",")",":","Input","tsv","file","path",".","out_dense_file","(","str",")",":","Output","dense","npy","file","path",".","out_sparse_file","(","str",")",":","Output","sparse","npy","file","path",".","out_labels_file","(","str",")",":","Output","labels","npy","file","path",".","dataset_name","(","str",")",":","The","dataset","name",".","``","criteo_1tb","''","or","``","criteo_kaggle","''","is","expected",".","path_manager_key","(","str",")",":","Path","manager","key","used","to","load","from","different","filesystems",".","Returns",":","None","."]
code: def tsv_to_npys(
      in_file: str,
      out_dense_file: str,
      out_sparse_file: str,
      out_labels_file: str,
      dataset_name: str = "criteo_1tb",
      path_manager_key: str = PATH_MANAGER_KEY,
  ) -> None:
      """
      Convert one Criteo tsv file to three npy files: one for dense (np.float32), one
      for sparse (np.int32), and one for labels (np.int32).
  
      The tsv file is expected to be part of the Criteo 1TB Click Logs Dataset ("criteo_1tb")
      or the Criteo Kaggle Display Advertising Challenge dataset ("criteo_kaggle").
  
      For the "criteo_kaggle" test set, we set the labels to -1 representing filler data,
      because label data is not included in the "criteo_kaggle" test set.
  
      Args:
          in_file (str): Input tsv file path.
          out_dense_file (str): Output dense npy file path.
          out_sparse_file (str): Output sparse npy file path.
          out_labels_file (str): Output labels npy file path.
          dataset_name (str): The dataset name. "criteo_1tb" or "criteo_kaggle" is expected.
          path_manager_key (str): Path manager key used to load from different
              filesystems.
  
      Returns:
          None.
      """
  
      # Add fake label for criteo_kaggle test set, which does not include label data
      def row_mapper_with_fake_label_constant(
          row: List[str],
      ) -> Tuple[List[int], List[int], int]:
          label = -1
          dense = [
              int(row[i] or "0")
              for i in range(0, 0 + INT_FEATURE_COUNT)
          ]
          sparse = [
              int(row[i] or "0", 16)
              for i in range(
                  0 + INT_FEATURE_COUNT,
                  0 + INT_FEATURE_COUNT + CAT_FEATURE_COUNT,
              )
          ]
          return dense, sparse, label
  
      def row_mapper(
          row: List[str],
      ) -> Tuple[List[int], List[int], int]:
          # Missing values are mapped to zero for both dense and sparse features
          label = int(row[0] or "0")
          dense = [
              int(row[i] or "0")
              for i in range(1, 1 + INT_FEATURE_COUNT)
          ]
          sparse = [
              int(row[i] or "0", 16)
              for i in range(
                  1 + INT_FEATURE_COUNT,
                  1 + INT_FEATURE_COUNT + CAT_FEATURE_COUNT,
              )
          ]
          return dense, sparse, label
  
      dense, sparse, labels = [], [], []
      for row_dense, row_sparse, row_label in CriteoIterDataPipe(
          [in_file],
          row_mapper=row_mapper
          if not (dataset_name == "criteo_kaggle" and "test" in in_file)
          else row_mapper_with_fake_label_constant,
      ):
          dense.append(row_dense)
          sparse.append(row_sparse)
          labels.append(row_label)
  
      # PyTorch tensors can't handle uint32, but we can save space by not
      # using int64. Numpy will automatically handle dense values >= 2 ** 31.
      dense_np = np.array(dense, dtype=np.int32)
      del dense
      sparse_np = np.array(sparse, dtype=np.int32)
      del sparse
      labels_np = np.array(labels, dtype=np.int32)
      del labels
  
      # Log is expensive to compute at runtime.
      dense_np += 3
      dense_np = np.log(dense_np, dtype=np.float32)
  
      # To be consistent with dense and sparse.
      labels_np = labels_np.reshape((-1, 1))
  
      path_manager = PathManagerFactory().get(path_manager_key)
      for fname, arr in [
          (out_dense_file, dense_np),
          (out_sparse_file, sparse_np),
          (out_labels_file, labels_np),
      ]:
          with path_manager.open(fname, "wb") as fout:
              np.save(fout, arr)
  
imports: import os
  import shutil
  import time
  from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.utils.data.datapipes
  from iopath.common.file_io import PathManager, PathManagerFactory
  from pyre_extensions import none_throws
  from torch.utils.data import IterableDataset, IterDataPipe
  from torchrec.datasets.utils import Batch, LoadFiles, PATH_MANAGER_KEY, ReadLinesFromCSV, safe_cast
  from torchrec.sparse.jagged_tensor import KeyedJaggedTensor
label_desc: Use image node_id 1 for calling the BinaryCriteoUtils obj's underlying member method code with example usage: obj.tsv_to_npys(in_file, out_dense_file, out_sparse_file, out_labels_file, dataset_name, path_manager_key) and returns: dense,  sparse,  label, dense,  sparse,  label