code: def make_batch_align_matrix(index_tensor, size=None, normalize=False):
      """
      Convert a sparse index_tensor into a batch of alignment matrix,
      with row normalize to the sum of 1 if set normalize.
  
      Args:
          index_tensor (LongTensor): ``(N, 3)`` of [batch_id, tgt_id, src_id]
          size (List[int]): Size of the sparse tensor.
          normalize (bool): if normalize the 2nd dim of resulting tensor.
      """
      n_fill, device = index_tensor.size(0), index_tensor.device
      value_tensor = torch.ones([n_fill], dtype=torch.float)
      dense_tensor = torch.sparse_coo_tensor(
          index_tensor.t(), value_tensor, size=size, device=device
      ).to_dense()
      if normalize:
          row_sum = dense_tensor.sum(
              -1, keepdim=True
          )  # sum by row(tgt)
          # threshold on 1 to avoid div by 0
          torch.nn.functional.threshold(row_sum, 1, 1, inplace=True)
          dense_tensor.div_(row_sum)
      return dense_tensor
  
file_path: OpenNMT-py/onmt/utils/alignment.py
imports: import torch
  from itertools import accumulate
  from onmt.constants import SubwordMarker
label_desc: Use image node_id 1 for calling a global function with example usage: make_batch_align_matrix(index_tensor, size, normalize) and returns: dense_tensor