code: def trec_dataset(
      directory="datasets/trec/",
      train_filename="train_5500.label",
      test_filename="TREC_10.label",
      validation_dataset_nb=500,
      urls=[
          "https://cogcomp.seas.upenn.edu/Data/QA/QC/train_5500.label",
          "https://cogcomp.seas.upenn.edu/Data/QA/QC/TREC_10.label",
      ],
  ):
      os.makedirs(directory, exist_ok=True)
  
      ret = []
      for url, filename in zip(urls, [train_filename, test_filename]):
          full_path = os.path.join(directory, filename)
          if not os.path.exists(full_path):
              util.http_get(url, full_path)
  
          examples = []
          label_map = {}
          guid = 1
          for line in open(full_path, "rb"):
              # there is one non-ASCII byte: sisterBADBYTEcity; replaced with space
              label, _, text = (
                  line.replace(b"\xf0", b" ")
                  .strip()
                  .decode()
                  .partition(" ")
              )
  
              if label not in label_map:
                  label_map[label] = len(label_map)
  
              label_id = label_map[label]
              guid += 1
              examples.append(
                  InputExample(guid=guid, texts=[text], label=label_id)
              )
          ret.append(examples)
  
      train_set, test_set = ret
      dev_set = None
  
      # Create a dev set from train set
      if validation_dataset_nb > 0:
          dev_set = train_set[-validation_dataset_nb:]
          train_set = train_set[:-validation_dataset_nb]
  
      # For dev & test set, we return triplets (anchor, positive, negative)
      random.seed(
          42
      )  # Fix seed, so that we always get the same triplets
      dev_triplets = triplets_from_labeled_dataset(dev_set)
      test_triplets = triplets_from_labeled_dataset(test_set)
  
      return train_set, dev_triplets, test_triplets
  
file_path: sentence-transformers/examples/training/other/training_batch_hard_trec.py
imports: from sentence_transformers import SentenceTransformer, LoggingHandler, losses, util
  from sentence_transformers.datasets import SentenceLabelDataset
  from torch.utils.data import DataLoader
  from sentence_transformers.readers import InputExample
  from sentence_transformers.evaluation import TripletEvaluator
  from datetime import datetime
  import logging
  import os
  import random
  from collections import defaultdict
label_desc: Use image node_id 1 for calling a global function with example usage: trec_dataset(directory, train_filename, test_filename, validation_dataset_nb, urls) and returns: train_set,  dev_triplets,  test_triplets