class_docstr: Ranking metric.
class_docstr_tok: ["Ranking","metric","."]
docstr: Create a RankingObject from a RequestState.
docstr_tok: ["Create","a","RankingObject","from","a","RequestState","."]
code: def create_ranking_object(
      self, request_state: RequestState
  ) -> RankingObject:
      """Create a RankingObject from a RequestState."""
      # Get reference index
      assert request_state.reference_index is not None
      reference_index: int = request_state.reference_index
      reference: Reference = request_state.instance.references[
          request_state.reference_index
      ]
  
      # Get gold, relevance and rank fields
      is_gold: bool = CORRECT_TAG in reference.tags
      relevance, rank = None, None
      for tag in reference.tags:
          if "relevance" in tag:
              relevance = int(self.get_tag_value(tag))
          elif "rank" in tag:
              rank = int(self.get_tag_value(tag))
  
      # Get model completion and the associated log probability
      assert request_state.result is not None
      model_output, model_logprob = self.get_model_output_logprob(
          request_state.result
      )
  
      # Create a RankingObject
      ranking_object = RankingObject(
          reference_index=reference_index,
          text=reference.output.text,
          gold=is_gold,
          relevance=relevance,
          rank=rank,
          model_output=model_output,
          model_logprob=model_logprob,
      )
      return ranking_object
  
imports: from dataclasses import dataclass
  from typing import Callable, Dict, List, Tuple, Optional
  import pytrec_eval
  from helm.benchmark.adaptation.adapters.adapter_factory import ADAPT_RANKING_BINARY
  from helm.benchmark.adaptation.request_state import RequestState
  from helm.benchmark.adaptation.adapter_spec import AdapterSpec
  from helm.benchmark.scenarios.scenario import unpack_tag, CORRECT_TAG, Reference
  from helm.common.request import RequestResult
  from helm.common.general import binarize_dict
  from .metric import Metric
  from .metric_name import MetricName
  from .metric_service import MetricService
  from .statistic import Stat
label_desc: Use image node_id 13 for calling the RankingMetric obj's underlying member method code with example usage: obj.create_ranking_object(request_state) and returns: ranking_object