code: def _dataset_to_text_classification_dataset(dataset):
      import torch
  
      assert dataset.fields["text"].vocab.itos[0] == "<unk>"
      assert dataset.fields["text"].vocab.itos[1] == "<pad>"
      unk_token_idx = 1
  
      vocab = dataset.fields["text"].vocab
  
      data = [
          (
              torch.LongTensor(
                  [
                      vocab.stoi[token]
                      if token in vocab.stoi
                      else unk_token_idx
                      for token in example.text
                  ]
              ),
              dataset.fields["label"].vocab.stoi[example.label],
          )
          for example in dataset.examples
      ]
  
      return PytorchTextClassificationDataset(data, vocab)
  
imports: import string
  import numpy
  from collections import Counter
  from scipy import sparse
  from sklearn.datasets import fetch_20newsgroups
  from small_text.data.datasets import SklearnDataset, TextDataset
  from small_text.data.sampling import _get_class_histogram
  from small_text.utils.labels import csr_to_list, list_to_csr
label_desc: Use image node_id 7 for calling a global function with example usage: _dataset_to_text_classification_dataset(dataset) and returns: PytorchTextClassificationDataset