class_docstr: Dataset for Causal Language modeling.
docstr: Reads a single text observation.
docstr_tok: ["Reads","a","single","text","observation","."]
code: def __getitem__(self, idx: int) -> Dict:
      """Reads a single text observation."""
      input_text_dict = self.conversation_chain_handler[idx]
      input_text_dict["systems"] = [
          self.parse_system(self.cfg, system)
          for system in input_text_dict["systems"]
      ]
      input_text_dict["prompts"] = [
          self.parse_prompt(self.cfg, prompt)
          for prompt in input_text_dict["prompts"]
      ]
  
      sample = dict()
      (
          system_encoding,
          prompt_encodings,
          answer_encodings,
      ) = self.get_encodings(input_text_dict=input_text_dict)
  
      input_ids = torch.cat(
          [
              torch.cat([prompt_encoding, answer_encoding])
              for prompt_encoding, answer_encoding in zip(
                  prompt_encodings, answer_encodings
              )
          ]
      )
  
      sample.update(self.get_labels(prompt_encodings, answer_encodings))
      sample.update(
          self.pad_tokens(
              input_ids,
              attention_mask=torch.ones_like(input_ids),
              max_length=self.cfg.tokenizer.max_length,
              pad_token_id=self.tokenizer.pad_token_id,
          )
      )
  
      # get answer encodings
      sample.update(
          self.pad_tokens(
              answer_encodings[-1],
              attention_mask=torch.ones_like(answer_encodings[-1]),
              max_length=self.cfg.tokenizer.max_length_answer,
              pad_token_id=self.tokenizer.pad_token_id,
              direction="right",
              prefix="answer_",
          )
      )
  
      # Remove last answer from encoding to create the prompt for inference
      answer_encodings[-1] = torch.empty(0)
      prompt_input_ids = torch.cat(
          [
              torch.cat([prompt_encoding, answer_encoding])
              for prompt_encoding, answer_encoding in zip(
                  prompt_encodings, answer_encodings
              )
          ]
      )
      sample.update(
          self.pad_tokens(
              prompt_input_ids,
              attention_mask=torch.ones_like(prompt_input_ids),
              max_length=self.cfg.tokenizer.max_length,
              pad_token_id=self.tokenizer.pad_token_id,
              prefix="prompt_",
          )
      )
  
      # make sure system encoding is always prepended if max_length exceeded
      if sample["input_ids"][0] != self.tokenizer.pad_token_id:
          sample["input_ids"][: len(system_encoding)] = system_encoding
          if (
              self.cfg.dataset.mask_prompt_labels
              and "labels" in sample.keys()
          ):
              sample["labels"][: len(system_encoding)] = -100
      if sample["prompt_input_ids"][0] != self.tokenizer.pad_token_id:
          sample["prompt_input_ids"][
              : len(system_encoding)
          ] = system_encoding
  
      return sample
  
imports: import codecs
  import collections.abc
  import logging
  from typing import Any, Dict, List, Tuple, Union
  import numpy
  import pandas
  import torch
  from torch.utils.data import Dataset
  from llm_studio.src.datasets.conversation_chain_handler import ConversationChainHandler
  from llm_studio.src.datasets.text_utils import get_tokenizer
label_desc: Use image node_id 3 for calling the CustomDataset obj's underlying member method code with example usage: obj.__getitem__(idx) and returns: sample