class_docstr: A text with a rationale explanation.
docstr: Initializes with a text and a list of token weights.
  
  Args:
    text: A full-text input to a classifier with tokens separated with ' '.
    token_weights: A list of token weights (in the token position order).
    top_k_ratio: Rationale size in tokens is defined proportional to the input
      length (in tokens). The percentages are given for the ERASER datasets
      and are 10% on average.
docstr_tok: ["Initializes","with","a","text","and","a","list","of","token","weights",".","Args",":","text",":","A","full-text","input","to","a","classifier","with","tokens","separated","with","'","'",".","token_weights",":","A","list","of","token","weights","(","in","the","token","position","order",")",".","top_k_ratio",":","Rationale","size","in","tokens","is","defined","proportional","to","the","input","length","(","in","tokens",")",".","The","percentages","are","given","for","the","ERASER","datasets","and","are","10","%","on","average","."]
code: def __init__(
      self,
      text: str,
      token_weights: list[float],
      top_k_ratio: float = TOP_K_AVG_RATIO,
  ):
      """Initializes with a text and a list of token weights.
  
      Args:
        text: A full-text input to a classifier with tokens separated with ' '.
        token_weights: A list of token weights (in the token position order).
        top_k_ratio: Rationale size in tokens is defined proportional to the input
          length (in tokens). The percentages are given for the ERASER datasets
          and are 10% on average.
      """
      self.text = text
      self.tokens = str.split(text)
      assert len(self.tokens) == len(
          token_weights
      ), "Token count does not match."
      self.token_weights = token_weights
  
      # Round to the closest equal or larger integer.
      top_k_value = math.ceil(len(self.tokens) * top_k_ratio)
  
      self.top_k_ids = np.argsort(token_weights)[-top_k_value:]
      self.top_k_ids = list(reversed(self.top_k_ids))
      self.top_k_ids_set = set(self.top_k_ids)
  
file_path: lit/lit_nlp/components/citrus/helpers.py
imports: from collections.abc import Sequence
  import math
  from typing import Any, Optional
  import attr
  import numpy
label_desc: Use image node_id 1 to create a new TextRationale object  with example: obj = TextRationale(text, token_weights, top_k_ratio)