code: def subword_map_by_spacer(subwords, marker=SubwordMarker.SPACER):
      """Return word id for each subword token (annotate by spacer)."""
      flags = [0] * len(subwords)
      for i, tok in enumerate(subwords):
          if marker in tok:
              if case_markup(tok.replace(marker, "")):
                  if i < len(subwords) - 1:
                      flags[i] = 1
              else:
                  if i > 0:
                      previous = subwords[i - 1].replace(marker, "")
                      if not case_markup(previous):
                          flags[i] = 1
  
      # In case there is a final case_markup when new_spacer is on
      for i in range(1, len(subwords) - 1):
          if case_markup(subwords[-i]):
              flags[-i] = 0
          elif subwords[-i] == marker:
              flags[-i] = 0
              break
  
      word_group = list(accumulate(flags))
      if word_group[0] == 1:  # when dummy prefix is set
          word_group = [item - 1 for item in word_group]
      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 10 for calling a global function with example usage: subword_map_by_spacer(subwords, marker) and returns: word_group