code: def transfer_weights_torch_to_tf(tf_vars, var_map_dict, state_dict):
      """Transfer weigths from torch state_dict to TF variables"""
      print(" > Passing weights from Torch to TF ...")
      for tf_var in tf_vars:
          torch_var_name = var_map_dict[tf_var.name]
          print(f" | > {tf_var.name} <-- {torch_var_name}")
          # if tuple, it is a bias variable
          if not isinstance(torch_var_name, tuple):
              torch_layer_name = ".".join(
                  torch_var_name.split(".")[-2:]
              )
              torch_weight = state_dict[torch_var_name]
          if (
              "convolution1d/kernel" in tf_var.name
              or "conv1d/kernel" in tf_var.name
          ):
              # out_dim, in_dim, filter -> filter, in_dim, out_dim
              numpy_weight = (
                  torch_weight.permute([2, 1, 0]).detach().cpu().numpy()
              )
          elif "lstm_cell" in tf_var.name and "kernel" in tf_var.name:
              numpy_weight = (
                  torch_weight.transpose(0, 1).detach().cpu().numpy()
              )
          # if variable is for bidirectional lstm and it is a bias vector there
          # needs to be pre-defined two matching torch bias vectors
          elif (
              "_lstm/lstm_cell_" in tf_var.name
              and "bias" in tf_var.name
          ):
              bias_vectors = [
                  value
                  for key, value in state_dict.items()
                  if key in torch_var_name
              ]
              assert len(bias_vectors) == 2
              numpy_weight = bias_vectors[0] + bias_vectors[1]
          elif "rnn" in tf_var.name and "kernel" in tf_var.name:
              numpy_weight = (
                  torch_weight.transpose(0, 1).detach().cpu().numpy()
              )
          elif "rnn" in tf_var.name and "bias" in tf_var.name:
              bias_vectors = [
                  value
                  for key, value in state_dict.items()
                  if torch_var_name[:-2] in key
              ]
              assert len(bias_vectors) == 2
              numpy_weight = bias_vectors[0] + bias_vectors[1]
          elif (
              "linear_layer" in torch_layer_name
              and "weight" in torch_var_name
          ):
              numpy_weight = (
                  torch_weight.transpose(0, 1).detach().cpu().numpy()
              )
          else:
              numpy_weight = torch_weight.detach().cpu().numpy()
          assert np.all(
              tf_var.shape == numpy_weight.shape
          ), f" [!] weight shapes does not match: {tf_var.name} vs {torch_var_name} --> {tf_var.shape} vs {numpy_weight.shape}"
          tf.keras.backend.set_value(tf_var, numpy_weight)
      return tf_vars
  
imports: import numpy
  import tensorflow
label_desc: Use image node_id 4 for calling a global function with example usage: transfer_weights_torch_to_tf(tf_vars, var_map_dict, state_dict) and returns: tf_vars