class_docstr: This class provides a method for accessing Perspective API using the Google API Client to obtain attribute scores for generated texts.
class_docstr_tok: ["This","class","provides","a","method","for","accessing","Perspective","API","using","the","Google","API","Client","to","obtain","attribute","scores","for","generated","texts","."]
docstr: Get attribute scores for a given text via Perspective API.
  :param input_text: the input text
  :param requested_attributes: the attributes for which to compute scores
  :return: a mapping from attribute names to scores
docstr_tok: ["Get","attribute","scores","for","a","given","text","via","Perspective","API",".",":","param","input_text",":","the","input","text",":","param","requested_attributes",":","the","attributes","for","which","to","compute","scores",":","return",":","a","mapping","from","attribute","names","to","scores"]
code: def get_scores(
      self,
      input_text: str,
      requested_attributes: Optional[List[str]] = None,
  ) -> Dict[str, float]:
      """
      Get attribute scores for a given text via Perspective API.
      :param input_text: the input text
      :param requested_attributes: the attributes for which to compute scores
      :return: a mapping from attribute names to scores
      """
      requested_attributes = (
          requested_attributes
          if requested_attributes
          else PerspectiveApiScorer.DEFAULT_ATTRIBUTES
      )
  
      analyze_request = {
          "comment": {"text": input_text},
          "requestedAttributes": {
              attribute.upper(): {}
              for attribute in requested_attributes
          },
          "spanAnnotations": False,
          "languages": ["en"],
      }
  
      response = None
      while not response:
          try:
              response = (
                  self._service.comments()
                  .analyze(body=analyze_request)
                  .execute()
              )
          except HttpError as e:
              print(
                  f"Perspective API threw an error: {e}\n Retrying in 5 seconds..."
              )
              print(input_text)
              time.sleep(1)
  
      return {
          attribute: response["attributeScores"][attribute.upper()][
              "summaryScore"
          ]["value"]
          for attribute in requested_attributes
      }
  
file_path: megatron-lm/examples/detxoify_lm/perspective_api.py
imports: import json
  import time
  from typing import Dict, Optional, List
  import joblib
  from googleapiclient import discovery
  from googleapiclient.errors import HttpError
  import argparse
  from tqdm import tqdm
label_desc: Use image node_id 2 for calling the PerspectiveApiScorer obj's underlying member method code with example usage: obj.get_scores(input_text, requested_attributes) and returns: unknown