code: def get_text_sine_pos_embed(
      pos_tensor: torch.Tensor,
      num_pos_feats: int = 128,
      temperature: int = 10000,
      exchange_xy: bool = True,
  ):
      """generate sine position embedding from a position tensor
      Args:
          pos_tensor (torch.Tensor): shape: [..., n].
          num_pos_feats (int): projected shape for each float in the tensor.
          temperature (int): temperature in the sine/cosine function.
          exchange_xy (bool, optional): exchange pos x and pos y. For example,
              input tensor is [x,y], the results will be [pos(y), pos(x)].
              Defaults to True.
      Returns:
          pos_embed (torch.Tensor): shape: [..., n*num_pos_feats].
      """
      scale = 2 * math.pi
      dim_t = torch.arange(
          num_pos_feats, dtype=torch.float32, device=pos_tensor.device
      )
      dim_t = temperature ** (
          2 * torch.div(dim_t, 2, rounding_mode="floor") / num_pos_feats
      )
  
      def sine_func(x: torch.Tensor):
          sin_x = x * scale / dim_t
          sin_x = torch.stack(
              (sin_x[..., 0::2].sin(), sin_x[..., 1::2].cos()), dim=3
          ).flatten(2)
          return sin_x
  
      pos_res = [
          sine_func(x)
          for x in pos_tensor.split([1] * pos_tensor.shape[-1], dim=-1)
      ]
      if exchange_xy:
          pos_res[0], pos_res[1] = pos_res[1], pos_res[0]
      pos_res = torch.cat(pos_res, dim=-1)
      return pos_res
  
imports: import math
  import warnings
  from typing import Optional, Sequence, Tuple, Union
  import torch
  import torch.nn.functional
  from mmcv.cnn import Linear, build_activation_layer, build_conv_layer, build_norm_layer
  from mmcv.cnn.bricks.drop import Dropout
  from mmengine.model import BaseModule, ModuleList
  from mmengine.utils import to_2tuple
  from torch import Tensor, nn
  from mmdet.registry import MODELS
  from mmdet.utils import OptConfigType, OptMultiConfig
label_desc: Use image node_id 5 for calling a global function with example usage: get_text_sine_pos_embed(pos_tensor, num_pos_feats, temperature, exchange_xy) and returns: pos_res, sin_x