code: def prepare_dataset_for_annotation_task(
      dataset: Union["FeedbackDataset", "RemoteFeedbackDataset"],
      question_name: str,
      filter_by: Optional[
          Dict[
              str,
              Union[
                  "ResponseStatusFilter", List["ResponseStatusFilter"]
              ],
          ]
      ] = None,
      sort_by: Optional[List["SortBy"]] = None,
      max_records: Optional[int] = None,
  ) -> "FormattedResponses":
      """Helper function to prepare the dataset for the nltk's AnnotationTask.
  
      The AnnotationTask class from nltk expects the data to be formatted as a list
      of tuples, each containing the annotator id, the task id and the label.
  
      The AnnotationTask is supposed to deal with sets and hashable objects, but
      there are errors transforming the data to sets and using the MASI distance function.
      For the moment what we do with those type of questions is create a string
      with all the values, and use the edit distance function.
  
      Note:
          We could potentially extend the functionality to a more than a question name. The
          requirement would be that all the questions are of the same type, as that would
          determine the type of distance function to use.
  
      Args:
          dataset: FeedbackDataset to compute the metrics.
          question_name: Name of the question for which we want to analyse the agreement.
          filter_by: A dict with key the field to filter by, and values the filters to apply.
              Can be one of: draft, pending, submitted, and discarded. If set to None,
              no filter will be applied. Defaults to None (no filter is applied).
          sort_by: A list of `SortBy` objects to sort your dataset by.
              Defaults to None (no filter is applied).
          max_records: The maximum number of records to use for training. Defaults to None.
  
      Returns:
          formatted_responses: The responses formatted as a list of tuples of (user_id, question_id, value).
      """
      question_type = type(dataset.question_by_name(question_name))
      # Check to assume the remote questions behave just like local ones
      if issubclass(question_type, RemoteSchema):
          question_type = type(
              dataset.question_by_name(question_name).to_local()
          )
  
      supported_question_types = list(QUESTION_TO_DISTANCE.keys())
      if question_type not in supported_question_types:
          raise NotImplementedError(
              f"Question '{question_name}' is of type '{question_type}', the supported question types are: {supported_question_types}."
          )
  
      if filter_by:
          dataset = dataset.filter_by(**filter_by)
      if sort_by:
          dataset = dataset.sort_by(sort_by)
      if max_records:
          dataset = dataset.pull(max_records=max_records)
  
      hf_dataset = dataset.format_as("datasets")
  
      formatted_responses: FormattedResponses = []
  
      for row in hf_dataset:
          responses_ = row[question_name]
          question_text = row["text"]
          for response in responses_:
              user_id = response["user_id"]
              if user_id is None:
                  raise ValueError(
                      "Please push your dataset to argilla to have the user_id necessary for this computation."
                  )
  
              value = response["value"]
              if value is None:
                  continue
              # To avoid errors with the MASI distance function
              if isinstance(value, list):
                  if len(value) == 0:
                      continue
              if question_type == RankingQuestion:
                  value = tuple(value["rank"])
              elif question_type == MultiLabelQuestion:
                  value = frozenset(value)
  
              formatted_responses.append(
                  (user_id, question_text, value)
              )
  
      return formatted_responses
  
file_path: argilla/src/argilla/client/feedback/metrics/agreement_metrics.py
imports: from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Union
  from nltk.metrics.agreement import AnnotationTask
  from nltk.metrics.distance import binary_distance, interval_distance, masi_distance
  from argilla.client.feedback.dataset import FeedbackDataset
  from argilla.client.feedback.metrics.base import AgreementMetricResult, AnnotationTaskMetricBase, MetricBase
  from argilla.client.feedback.schemas import LabelQuestion, MultiLabelQuestion, RankingQuestion, RatingQuestion
  from argilla.client.feedback.schemas.remote.shared import RemoteSchema
label_desc: Use image node_id 1 for calling a global function with example usage: prepare_dataset_for_annotation_task(dataset, question_name, filter_by, sort_by, max_records) and returns: formatted_responses