class_docstr: Dataset class for classifiers from Pytorch Integration.
      
docstr: Constructs a new PytorchTextClassificationDataset from the given text and label arrays.
  
  Parameters
  ----------
  texts : list of str or np.ndarray[str]
      List of text documents.
  y : np.ndarray[int] or scipy.sparse.csr_matrix
      List of labels where each label belongs to the features of the respective row.
      Depending on the type of `y` the resulting dataset will be single-label (`np.ndarray`)
      or multi-label (`scipy.sparse.csr_matrix`).
  text_field : torchtext.data.field.Field or torchtext.legacy.data.field.Field
      A torchtext field used for preprocessing the text and building the vocabulary.
  vocab : object
      A torch
  target_labels : numpy.ndarray[int] or None, default=None
      List of possible labels. Will be directly passed to the datset constructor.
  train : bool
      If `True` fits the vectorizer and transforms the data, otherwise just transforms the
      data.
  
  Returns
  -------
  dataset : PytorchTextClassificationDataset
      A dataset constructed from the given texts and labels.
  
  
  .. warning::
     This functionality is still experimental and may be subject to change.
  
  .. versionadded:: 1.1.0
docstr_tok: ["Constructs","a","new","PytorchTextClassificationDataset","from","the","given","text","and","label","arrays",".","Parameters","--","--","--","--","--","texts",":","list","of","str","or","np.ndarray","[","str","]","List","of","text","documents",".","y",":","np.ndarray","[","int","]","or","scipy.sparse.csr_matrix","List","of","labels","where","each","label","belongs","to","the","features","of","the","respective","row",".","Depending","on","the","type","of","`","y","`","the","resulting","dataset","will","be","single-label","(","`","np.ndarray","`",")","or","multi-label","(","`","scipy.sparse.csr_matrix","`",")",".","text_field",":","torchtext.data.field.Field","or","torchtext.legacy.data.field.Field","A","torchtext","field","used","for","preprocessing","the","text","and","building","the","vocabulary",".","vocab",":","object","A","torch","target_labels",":","numpy.ndarray","[","int","]","or","None",",","default=None","List","of","possible","labels",".","Will","be","directly","passed","to","the","datset","constructor",".","train",":","bool","If","`","True","`","fits","the","vectorizer","and","transforms","the","data",",","otherwise","just","transforms","the","data",".","Returns","--","--","--","-","dataset",":","PytorchTextClassificationDataset","A","dataset","constructed","from","the","given","texts","and","labels",".","..","warning",":",":","This","functionality","is","still","experimental","and","may","be","subject","to","change",".","..","versionadded",":",":","1.1.0"]
code: def from_arrays(
      cls, texts, y, text_field, target_labels=None, train=True
  ):
      """Constructs a new PytorchTextClassificationDataset from the given text and label arrays.
  
      Parameters
      ----------
      texts : list of str or np.ndarray[str]
          List of text documents.
      y : np.ndarray[int] or scipy.sparse.csr_matrix
          List of labels where each label belongs to the features of the respective row.
          Depending on the type of `y` the resulting dataset will be single-label (`np.ndarray`)
          or multi-label (`scipy.sparse.csr_matrix`).
      text_field : torchtext.data.field.Field or torchtext.legacy.data.field.Field
          A torchtext field used for preprocessing the text and building the vocabulary.
      vocab : object
          A torch
      target_labels : numpy.ndarray[int] or None, default=None
          List of possible labels. Will be directly passed to the datset constructor.
      train : bool
          If `True` fits the vectorizer and transforms the data, otherwise just transforms the
          data.
  
      Returns
      -------
      dataset : PytorchTextClassificationDataset
          A dataset constructed from the given texts and labels.
  
  
      .. warning::
         This functionality is still experimental and may be subject to change.
  
      .. versionadded:: 1.1.0
      """
      unk_token_idx = 0  # TODO: check this index
  
      if not train and not hasattr(text_field, "vocab"):
          raise ValueError(
              "Vocab must have been built when using this function "
              "to obtain test data."
          )
  
      texts_preprocessed = [
          text_field.preprocess(text) for text in texts
      ]
  
      if train:
          text_field.build_vocab(texts_preprocessed)
          assert text_field.vocab.itos[0] == "<unk>"
          assert text_field.vocab.itos[1] == "<pad>"
  
      multi_label = isinstance(y, csr_matrix)
      if multi_label:
          y = csr_to_list(y)
  
      vocab = text_field.vocab
  
      data = [
          (
              torch.LongTensor(
                  [
                      vocab.stoi[token]
                      if token in vocab.stoi
                      else unk_token_idx
                      for token in text_preprocessed
                  ]
              ),
              y[i],
          )
          for i, text_preprocessed in enumerate(texts_preprocessed)
      ]
  
      return PytorchTextClassificationDataset(
          data,
          vocab,
          multi_label=multi_label,
          target_labels=target_labels,
      )
  
imports: import torch
  import numpy
  from abc import ABC, abstractmethod
  from scipy.sparse import csr_matrix
  from small_text.base import LABEL_UNLABELED
  from small_text.data import DatasetView
  from small_text.data.datasets import check_size, check_target_labels, get_updated_target_labels
  from small_text.data.exceptions import UnsupportedOperationException
  from small_text.utils.annotations import experimental
  from small_text.utils.labels import csr_to_list, get_num_labels, list_to_csr
label_desc: Use image node_id 15 for calling the PytorchTextClassificationDataset obj's underlying member method code with example usage: obj.from_arrays(cls, texts, y, text_field, target_labels, train) and returns: PytorchTextClassificationDataset