code: def get_iter_for_task(
      task_H,
      *,
      encoder=summarize_from_feedback.encoder,
      dataset_split,
      batch_size,
      seed,
      layout: Optional[ModelLayout] = None,
      repeat=True,
      all_fields=False,
  ):
      response_encoder = tasks.ResponseEncoder(task_H.response, encoder)
  
      def map_input(raw_data):
          ref_response = task_H.response.ref_format_str.format(
              **raw_data
          )
          ref_tokens = response_encoder.encode_response(
              ref_response, allow_truncate=True
          )
          query_info = tasks.process_query(
              raw_data, encoder=encoder, hparams=task_H.query
          )
          return dict(
              context=query_info,
              # NOTE: tokens are truncated but text is not
              reference=dict(tokens=ref_tokens, text=ref_response),
              # NOTE: we remove reference to prevent mistakes, after the rm4 space bug
              extra_fields={
                  k: v for k, v in raw_data.items() if k != "reference"
              }
              if all_fields
              else dict(),
          )
  
      ds = get_dataset(
          task_H.query.dataset,
          split=dataset_split,
          seed=seed,
          repeat=repeat,
          layout=layout,
      )
      ds = map(map_input, ds)
      ds = torch_loader(
          ds,
          num_workers=1,
          batch_size=batch_size,
          drop_last=True,
          collate_fn=partial(_collate_fn, all_fields=all_fields),
      )
      return ds
  
file_path: summarize-from-feedback/summarize_from_feedback/task_data.py
imports: import json
  import os
  from functools import partial
  from glob import glob
  from typing import Optional
  import blobfile
  import torch
  import summarize_from_feedback
  from summarize_from_feedback import tasks
  from summarize_from_feedback.datasets import jsonl_encoding, get_dataset
  from summarize_from_feedback.model_layout import ModelLayout
  from summarize_from_feedback.utils import even_more_itertools, blobs
label_desc: Use image node_id 3 for calling a global function with example usage: get_iter_for_task(task_H) and returns: ds, dict