code: def decode_arr_to_seq(arr, idx2vocab):
      """
      Input: torch 1d array: y_arr
      Output: a sequence of words.
      """
  
      eos_idx_list = torch.nonzero(
          arr == len(idx2vocab) - 1, as_tuple=False
      )  # find the position of __EOS__ (the last vocab in idx2vocab)
      if len(eos_idx_list) > 0:
          clippted_arr = arr[
              : torch.min(eos_idx_list)
          ]  # find the smallest __EOS__
      else:
          clippted_arr = arr
  
      return list(map(lambda x: idx2vocab[x], clippted_arr.cpu()))
  
file_path: ogb/examples/graphproppred/code2/utils.py
imports: import torch
  from collections import Counter
  import numpy
  import torch
label_desc: Use image node_id 5 for calling a global function with example usage: decode_arr_to_seq(arr, idx2vocab) and returns: list