code: def prepare_hh_dpo_modeling(split: str) -> pd.DataFrame:
      """
      Adapted from
      https://github.com/eric-mitchell/direct-preference-optimization/blob/main/preference_datasets.py
      """
      dataset = load_dataset("Anthropic/hh-rlhf", split=split)
      rnd = random.Random()
      rnd.seed(123)
      dfs = []
      for row in tqdm(dataset):
          prompt, chosen_response, rejected_response = _parse_row(row)
          if len(rejected_response) == 0:
              # remove rejected answers that are empty
              continue
  
          parent_uuid = None
          parsed_texts = []
          for human_text, assistant_text in _split_up_prompt(prompt):
              random_uuid = str(
                  uuid.UUID(int=rnd.getrandbits(128), version=4)
              )
              parsed_texts += [
                  [
                      human_text,
                      assistant_text,
                      random_uuid,
                      parent_uuid,
                      None,
                      None,
                  ]
              ]
              parent_uuid = random_uuid
  
          parsed_texts[-1][-2] = chosen_response
          parsed_texts[-1][-1] = rejected_response
          df = pd.DataFrame(
              parsed_texts,
              columns=[
                  "instruction",
                  "output",
                  "id",
                  "parent_id",
                  "chosen_response",
                  "rejected_response",
              ],
          )
          dfs.append(df)
      df = pd.concat(dfs).reset_index(drop=True)
      # merge output into chosen and rejected response
      df["chosen_response"] = df["chosen_response"].fillna(df["output"])
      df["rejected_response"] = df["rejected_response"].fillna(
          df["output"]
      )
      del df["output"]
      return df
  
file_path: h2o-llmstudio/llm_studio/app_utils/default_datasets.py
imports: import os
  import random
  import re
  import uuid
  import pandas
  from datasets import load_dataset
  from tqdm import tqdm
label_desc: Use image node_id 6 for calling a global function with example usage: prepare_hh_dpo_modeling(split) and returns: df