code: def _finetune_cls(df, args):
      df = df.rename(
          columns={
              args["target"]: "labels",
              args["input_column"]: "text",
          }
      )
      tokenizer_from = args.get("using", {}).get(
          "tokenizer_from", args["model_name"]
      )
      tokenizer = AutoTokenizer.from_pretrained(tokenizer_from)
      dataset = Dataset.from_pandas(df)
  
      def _tokenize_text_cls_fn(examples):
          return tokenizer(
              examples["text"], padding="max_length", truncation=True
          )
  
      tokenized_datasets = dataset.map(
          _tokenize_text_cls_fn, batched=True
      )
      ds = tokenized_datasets.shuffle(seed=42).train_test_split(
          test_size=args.get("eval_size", 0.1)
      )
      train_ds = ds["train"]
      eval_ds = ds["test"]
  
      ft_args = args.get("using", {}).get("trainer_args", {})
      ft_args["output_dir"] = args["model_folder"]
  
      n_labels = len(args["labels_map"])
      # todo replace for prod
      assert (
          n_labels == df["labels"].nunique()
      ), f'Label mismatch! Ensure labels match what the model was originally trained on. Found {df["labels"].nunique()} classes, expected {n_labels}.'  # noqa
      # TODO: ideally check that labels are a subset of the original ones, too.
      config = AutoConfig.from_pretrained(args["model_name"])
      model = AutoModelForSequenceClassification.from_pretrained(
          args["model_name"], config=config
      )
      metric = evaluate.load("accuracy")
      training_args = TrainingArguments(**ft_args)
  
      def _compute_metrics(eval_pred):
          logits, labels = eval_pred
          predictions = np.argmax(logits, axis=-1)
          return metric.compute(
              predictions=predictions, references=labels
          )
  
      # generate trainer and finetune
      trainer = Trainer(
          model=model,
          args=training_args,
          train_dataset=train_ds,
          eval_dataset=eval_ds,
          compute_metrics=_compute_metrics,
      )
  
      return tokenizer, trainer
  
file_path: mindsdb/mindsdb/integrations/handlers/huggingface_handler/finetune.py
imports: import evaluate
  import nltk
  import numpy
  from datasets import Dataset
  from transformers import AutoConfig, AutoModelForSeq2SeqLM, AutoModelForSequenceClassification, AutoTokenizer, DataCollatorForSeq2Seq, Seq2SeqTrainingArguments, Trainer, TrainingArguments
label_desc: Use image node_id 1 for calling a global function with example usage: _finetune_cls(df, args) and returns: tokenizer,  trainer, tokenizer, metric