class_docstr: Precision-IA@k (Pre-IA@k).
  
  Intent-aware Precision@k ([Agrawal et al, 2009][agrawal2009];
  [Clarke et al, 2009][clarke2009]) is a precision metric that operates on
  subtopics and is typically used for diversification tasks..
  
  For each list of scores `s` in `y_pred` and list of labels `y` in `y_true`:
  
  ```
  Pre-IA@k(y, s) = sum_t sum_i I[rank(s_i) <= k] y_{i,t} / (# of subtopics * k)
  ```
  
  NOTE: The labels `y_true` should be of shape
  `[batch_size, list_size, subtopic_size]`, indicating relevance for each
  subtopic in the last dimension.
  
  NOTE: This metric converts graded relevance to binary relevance by setting
  `y_{i,t} = 1` if `y_{i,t} >= 1`.
  
  Standalone usage:
  
  >>> y_true = [[[0., 1.], [1., 0.], [1., 1.]]]
  >>> y_pred = [[3., 1., 2.]]
  >>> pre_ia = tfr.keras.metrics.PrecisionIAMetric()
  >>> pre_ia(y_true, y_pred).numpy()
  0.6666667
  
  >>> # Using ragged tensors
  >>> y_true = tf.ragged.constant(
  ...   [[[0., 0.], [1., 0.]], [[1., 1.], [0., 2.], [1., 0.]]])
  >>> y_pred = tf.ragged.constant([[2., 1.], [2., 5., 4.]])
  >>> pre_ia = tfr.keras.metrics.PrecisionIAMetric(ragged=True)
  >>> pre_ia(y_true, y_pred).numpy()
  0.5833334
  
  Usage with the `compile()` API:
  
  ```python
  model.compile(optimizer='sgd',
                metrics=[tfr.keras.metrics.PrecisionIAMetric()])
  ```
  
  Definition:
  
  $$
  \text{Pre-IA@k}(y, s) = \frac{1}{\text{# of subtopics} \cdot k}
  \sum_t \sum_i I[\text{rank}(s_i) \leq k] y_{i,t}
  $$
  
  where $\text{rank}(s_i)$ is the rank of item $i$ after sorting by scores
  $s$ with ties broken randomly.
  
  References:
  
    - [Diversifying Search Results, Agrawal et al, 2009][agrawal2009]
    - [Overview of the TREC 2009 Web Track, Clarke et al, 2009][clarke2009]
  
  [agrawal2009]:
  https://www.microsoft.com/en-us/research/publication/diversifying-search-results/
  [clarke2009]: https://trec.nist.gov/pubs/trec18/papers/ENT09.OVERVIEW.pdf
class_docstr_tok: ["Precision-IA","@","k","(","Pre-IA","@","k",")",".","Intent-aware","Precision","@","k","(","[","Agrawal","et","al",",","2009","]","[","agrawal2009","]",";","[","Clarke","et","al",",","2009","]","[","clarke2009","]",")","is","a","precision","metric","that","operates","on","subtopics","and","is","typically","used","for","diversification","tasks","..","For","each","list","of","scores","`","s","`","in","`","y_pred","`","and","list","of","labels","`","y","`","in","`","y_true","`",":","``","`","Pre-IA","@","k","(","y",",","s",")","=","sum_t","sum_i","I","[","rank","(","s_i",")","<","=","k","]","y_","{","i",",","t","}","\/","(","#","of","subtopics","*","k",")","``","`","NOTE",":","The","labels","`","y_true","`","should","be","of","shape","`","[","batch_size",",","list_size",",","subtopic_size","]","`",",","indicating","relevance","for","each","subtopic","in","the","last","dimension",".","NOTE",":","This","metric","converts","graded","relevance","to","binary","relevance","by","setting","`","y_","{","i",",","t","}","=","1","`","if","`","y_","{","i",",","t","}",">","=","1","`",".","Standalone","usage",":",">",">",">","y_true","=","[","[","[","0.",",","1",".","]",",","[","1.",",","0",".","]",",","[","1.",",","1",".","]","]","]",">",">",">","y_pred","=","[","[","3.",",","1.",",","2",".","]","]",">",">",">","pre_ia","=","tfr.keras.metrics.PrecisionIAMetric","(",")",">",">",">","pre_ia","(","y_true",",","y_pred",")",".numpy","(",")","0.6666667",">",">",">","#","Using","ragged","tensors",">",">",">","y_true","=","tf.ragged.constant","(","...","[","[","[","0.",",","0",".","]",",","[","1.",",","0",".","]","]",",","[","[","1.",",","1",".","]",",","[","0.",",","2",".","]",",","[","1.",",","0",".","]","]","]",")",">",">",">","y_pred","=","tf.ragged.constant","(","[","[","2.",",","1",".","]",",","[","2.",",","5.",",","4",".","]","]",")",">",">",">","pre_ia","=","tfr.keras.metrics.PrecisionIAMetric","(","ragged=True",")",">",">",">","pre_ia","(","y_true",",","y_pred",")",".numpy","(",")","0.5833334","Usage","with","the","`","compile","(",")","`","API",":","``","`","python","model.compile","(","optimizer='sgd","'",",","metrics=","[","tfr.keras.metrics.PrecisionIAMetric","(",")","]",")","``","`","Definition",":","$","$","\\text","{","Pre-IA","@","k","}","(","y",",","s",")","=","\\frac","{","1","}","{","\\text","{","#","of","subtopics","}","\\cdot","k","}","\\sum_t","\\sum_i","I","[","\\text","{","rank","}","(","s_i",")","\\leq","k","]","y_","{","i",",","t","}","$","$","where","$","\\text","{","rank","}","(","s_i",")","$","is","the","rank","of","item","$","i","$","after","sorting","by","scores","$","s","$","with","ties","broken","randomly",".","References",":","-","[","Diversifying","Search","Results",",","Agrawal","et","al",",","2009","]","[","agrawal2009","]","-","[","Overview","of","the","TREC","2009","Web","Track",",","Clarke","et","al",",","2009","]","[","clarke2009","]","[","agrawal2009","]",":","https",":","\/\/www.microsoft.com\/en-us\/research\/publication\/diversifying-search-results\/","[","clarke2009","]",":","https",":","\/\/trec.nist.gov\/pubs\/trec18\/papers\/ENT09.OVERVIEW.pdf"]
code: def get_config(self):
      config = super(PrecisionIAMetric, self).get_config()
      config.update(
          {
              "topn": self._topn,
          }
      )
      return config
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Any, Dict, List, Optional
  import tensorflow.compat.v2
  from tensorflow_ranking.python import metrics_impl
  from tensorflow_ranking.python.keras import utils
label_desc: Use image node_id 2 for calling the PrecisionIAMetric obj's underlying member method code with example usage: obj.get_config() and returns: config