code: def transformers_hyperparameter_functional(tmp_path):
      random.seed(555)
      np.random.seed(555)
      torch.manual_seed(555)
  
      tokenizer = DistilBertTokenizerFast.from_pretrained(
          "distilbert-base-uncased"
      )
  
      train_texts = [
          "I simply adore artisinal baked goods!",
          "I thoroughly dislike artisinal bathroom cleaning.",
      ]
      train_labels = [1, 0]
      eval_texts = [
          "It was an excellent experience.",
          "I'd rather pick my teeth with a rusty pitchfork.",
      ]
      eval_labels = [1, 0]
  
      train_encodings = tokenizer(
          train_texts, truncation=True, padding=True
      )
      eval_encodings = tokenizer(
          eval_texts, truncation=True, padding=True
      )
  
      class CustomDataset(torch.utils.data.Dataset):
          def __init__(self, encodings, labels):
              self.encodings = encodings
              self.labels = labels
  
          def __getitem__(self, idx):
              item = {
                  key: torch.tensor(val[idx])
                  for key, val in self.encodings.items()
              }
              item["labels"] = torch.tensor(self.labels[idx])
              return item
  
          def __len__(self):
              return len(self.labels)
  
      train_dataset = CustomDataset(train_encodings, train_labels)
      eval_dataset = CustomDataset(eval_encodings, eval_labels)
  
      training_args = TrainingArguments(
          output_dir=str(tmp_path.joinpath("results")),
          num_train_epochs=1,
          per_device_train_batch_size=4,
          logging_dir=str(tmp_path.joinpath("logs")),
          report_to="none",
      )
  
      def model_init():
          return DistilBertForSequenceClassification.from_pretrained(
              "distilbert-base-uncased", num_labels=2
          )
  
      trainer = Trainer(
          model_init=model_init,
          args=training_args,
          train_dataset=train_dataset,
          eval_dataset=eval_dataset,
      )
  
      def my_hp_space_optuna(trial):
          return {
              "learning_rate": trial.suggest_float(
                  "learning_rate", 1e-5, 1e-1, log=True
              ),
          }
  
      best_run = trainer.hyperparameter_search(
          hp_space=my_hp_space_optuna,
          backend="optuna",
          n_trials=2,
          direction="minimize",
      )
  
      best_training_args = TrainingArguments(
          output_dir=str(tmp_path.joinpath("best_results")),
          num_train_epochs=1,
          per_device_train_batch_size=4,
          learning_rate=best_run.hyperparameters["learning_rate"],
          logging_dir=str(tmp_path.joinpath("best_logs")),
      )
  
      return Trainer(
          model=model_init(),
          args=best_training_args,
          train_dataset=train_dataset,
      )
  
imports: import random
  import numpy
  import optuna
  import pytest
  import sklearn
  import sklearn.cluster
  import torch
  from datasets import load_dataset
  from sentence_transformers.losses import CosineSimilarityLoss
  from setfit import SetFitModel, sample_dataset
  from setfit import Trainer
  from setfit import TrainingArguments
  from transformers import DistilBertForSequenceClassification, DistilBertTokenizerFast, Trainer, TrainingArguments, pipeline
  import mlflow
label_desc: Use image node_id 5 for calling a global function with example usage: transformers_hyperparameter_functional(tmp_path) and returns: Trainer, DistilBertForSequenceClassification, dict, item, len