class_docstr: BERT masked LM using Huggingface Transformers and TensorFlow 2.
class_docstr_tok: ["BERT","masked","LM","using","Huggingface","Transformers","and","TensorFlow","2","."]
docstr: Convert raw scores to top-k token predictions.
docstr_tok: ["Convert","raw","scores","to","top-k","token","predictions","."]
code: def _get_topk_tokens(
      self, scores: np.ndarray
  ) -> list[list[tuple[str, float]]]:
      """Convert raw scores to top-k token predictions."""
      # scores is [num_tokens, vocab_size]
      # Find the vocab indices of top k predictions, at each token.
      # np.argpartition is faster than a full argsort for k << V,
      # but we need to sort the output after slicing (see below).
      index_array = np.argpartition(scores, -self.top_k, axis=1)[
          :, -self.top_k :
      ]
      # These are each [num_tokens, tok_k]
      top_tokens = [
          self.tokenizer.convert_ids_to_tokens(idxs)
          for idxs in index_array
      ]
      top_scores = np.take_along_axis(scores, index_array, axis=1)
      # Convert to a list of lists of (token, score) pairs,
      # where inner lists are sorted in descending order of score.
      return [
          sorted(list(zip(toks, scores)), key=lambda ab: -ab[1])
          for toks, scores in zip(top_tokens, top_scores)
      ]
  
imports: import re
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.examples.models import model_utils
  from lit_nlp.lib import file_cache
  from lit_nlp.lib import utils
  import numpy
  import tensorflow
  import transformers
label_desc: Use image node_id 4 for calling the BertMLM obj's underlying member method code with example usage: obj._get_topk_tokens(scores) and returns: unknown