code: def to_one_hot(x: torch.Tensor, length: int) -> torch.Tensor:
      """
      Args:
          x (torch.Tensor):[B] , 一般是 target 的值
          length (int) : L ,一般是关系种类树
      Return:
          x_one_hot.to(device=x.device) (torch.Tensor) : [B, L]  每一行，只有对应位置为1，其余为0
      """
      B = x.size(0)
      x_one_hot = torch.zeros(B, length)
      for i in range(B):
          x_one_hot[i, x[i]] = 1.0
  
      return x_one_hot.to(device=x.device)
  
file_path: DeepKE/src/deepke/attribution_extraction/standard/utils/nnUtils.py
imports: import torch
  import random
  import logging
  import numpy
  from typing import List, Tuple, Dict, Union
label_desc: Use image node_id 3 for calling a global function with example usage: to_one_hot(x, length) and returns: x_one_hot