code: def subword_map_by_joiner(
      subwords, original_subwords=None, marker=SubwordMarker.JOINER
  ):
      """Return word id for each subword token (annotate by joiner)."""
  
      flags = [1] * len(subwords)
      j = 0
      finished = True
      for i, tok in enumerate(subwords):
          previous_tok = (
              subwords[i - 1] if i else ""
          )  # Previous N-1 token
          previous_tok_2 = (
              subwords[i - 2] if i > 1 else ""
          )  # Previous N-2 token
          # Keeps track of the original words/subwords
          # ('prior_tokenization' option)
          current_original_subword = (
              ""
              if not original_subwords
              else original_subwords[j]
              if j < len(original_subwords)
              else ""
          )
  
          if tok.startswith(marker) and tok != current_original_subword:
              flags[i] = 0
          elif (
              previous_tok.endswith(marker)
              or begin_case(previous_tok)
              or begin_uppercase(previous_tok)
          ) and not finished:
              flags[i] = 0
          elif (
              previous_tok_2.endswith(marker)
              and case_markup(previous_tok)
              and not finished
          ):
              flags[i] = 0
          elif end_uppercase(tok) and tok != current_original_subword:
              flags[i] = 0
          else:
              finished = False
              if tok == current_original_subword:
                  finished = True
              j += 1
  
      flags[0] = 0
      word_group = list(accumulate(flags))
  
      if original_subwords:
          assert max(word_group) < len(original_subwords)
      return word_group
  
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 9 for calling a global function with example usage: subword_map_by_joiner(subwords, original_subwords, marker) and returns: word_group