code: def _finetune_summarization(df, args):
      df = df.rename(
          columns={
              args["target"]: "summary",
              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)
      config = AutoConfig.from_pretrained(args["model_name"])
  
      def _tokenize_summarize_fn(examples):
          prefix = "summarize: " if "t5" in args["model_name"] else ""
          inputs = [prefix + doc for doc in examples["text"]]
          model_inputs = tokenizer(
              inputs,
              padding="max_length",
              truncation=True,
              max_length=config.max_position_embeddings,
              pad_to_max_length=True,
          )  # noqa
          labels = tokenizer(
              text_target=examples["summary"],
              max_length=config.max_position_embeddings,
              truncation=True,
          )  # noqa
          model_inputs["labels"] = labels["input_ids"]
          return model_inputs
  
      tokenized_datasets = dataset.map(
          _tokenize_summarize_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"]
      ft_args["predict_with_generate"] = True
  
      model = AutoModelForSeq2SeqLM.from_pretrained(
          args["model_name"], config=config
      )
      metric = evaluate.load("rouge")
      training_args = Seq2SeqTrainingArguments(**ft_args)
      data_collator = DataCollatorForSeq2Seq(tokenizer, model=model)
  
      def _compute_metrics(eval_pred):
          # ref: github.com/huggingface/notebooks/blob/main/examples/summarization.ipynb
          predictions, labels = eval_pred
          decoded_preds = tokenizer.batch_decode(
              predictions, skip_special_tokens=True
          )
          decoded_labels = tokenizer.batch_decode(
              labels, skip_special_tokens=True
          )
  
          # Rogue expects a newline after each sentence
          decoded_preds = [
              "\n".join(nltk.sent_tokenize(pred.strip()))
              for pred in decoded_preds
          ]
          decoded_labels = [
              "\n".join(nltk.sent_tokenize(label.strip()))
              for label in decoded_labels
          ]
  
          result = metric.compute(
              predictions=decoded_preds,
              references=decoded_labels,
              use_stemmer=True,
              use_aggregator=True,
          )
          result = {key: value * 100 for key, value in result.items()}
          prediction_lens = [
              np.count_nonzero(pred != tokenizer.pad_token_id)
              for pred in predictions
          ]
          result["gen_len"] = np.mean(prediction_lens)  # todo: remove?
          return {k: round(v, 4) for k, v in result.items()}
  
      # generate trainer and finetune
      trainer = Trainer(
          model=model,
          args=training_args,
          train_dataset=train_ds,
          eval_dataset=eval_ds,
          data_collator=data_collator,
          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 3 for calling a global function with example usage: _finetune_summarization(df, args) and returns: tokenizer,  trainer, model_inputs, unknown