class_docstr: Dataset for DPO optimization.
  The data is assumed to be in the same format as for causal language modeling,
  but an additional column with rejected answers is required.
  For chained conversations, rejected answers are equal normal answers up to the
  last answer. THe last answers are then different.
class_docstr_tok: ["Dataset","for","DPO","optimization",".","The","data","is","assumed","to","be","in","the","same","format","as","for","causal","language","modeling",",","but","an","additional","column","with","rejected","answers","is","required",".","For","chained","conversations",",","rejected","answers","are","equal","normal","answers","up","to","the","last","answer",".","THe","last","answers","are","then","different","."]
docstr: Mask all but the last answer.
docstr_tok: ["Mask","all","but","the","last","answer","."]
code: def get_labels(self, prompt_encodings, answer_encodings):
      """
      Mask all but the last answer.
      """
      labels = torch.cat(
          [
              torch.cat(
                  [
                      torch.full_like(
                          prompt_encoding,
                          fill_value=-100,
                      ),
                      torch.full_like(
                          answer_encoding,
                          fill_value=-100,
                      ),
                  ]
              )
              for prompt_encoding, answer_encoding in zip(
                  prompt_encodings, answer_encodings
              )
          ]
      ).clone()
  
      if len(answer_encodings[-1]):
          # empty answers would create a RuntimeError
          labels[-len(answer_encodings[-1]) :] = answer_encodings[-1]
  
      if self.cfg.dataset.add_eos_token_to_answer:
          # eos_token may be equal to pad_token. Add the label back manually.
          labels[-1] = self.tokenizer.eos_token_id
      if self.cfg.tokenizer.max_length < len(labels):
          labels = labels[-self.cfg.tokenizer.max_length :]
  
      sample = dict(
          labels=torch.full((self.cfg.tokenizer.max_length,), -100)
      )
      sample["labels"][-len(labels) :] = labels
      return sample
  
file_path: h2o-llmstudio/llm_studio/src/datasets/text_dpo_modeling_ds.py
imports: import logging
  from typing import Any, Dict
  import pandas
  import torch
  import llm_studio.src.datasets.text_causal_language_modeling_ds
  from llm_studio.src.datasets.conversation_chain_handler import ConversationChainHandler
  from llm_studio.src.utils.utils import PatchedAttribute
label_desc: Use image node_id 3 for calling the CustomDataset obj's underlying member method code with example usage: obj.get_labels(prompt_encodings, answer_encodings) and returns: sample