code: def test_replace_dense_for_sparse_layers(
      new_sparse_feature_sizes: List[int],
      old_sparse_feature_sizes: List[int],
      feature_type: Text,
      use_bias: bool,
  ):
      """Tests if `DenseForSparse` layers are adjusted correctly."""
      output_units = 10
      kernel_initializer = tf.constant_initializer(
          np.random.random(
              (sum(old_sparse_feature_sizes), output_units)
          )
      )
      layer = layers.DenseForSparse(
          units=output_units,
          kernel_initializer=kernel_initializer,
          use_bias=use_bias,
      )
      layer.build(input_shape=sum(old_sparse_feature_sizes))
  
      new_layer = RasaCustomLayer._replace_dense_for_sparse_layer(
          layer_to_replace=layer,
          new_sparse_feature_sizes=new_sparse_feature_sizes,
          old_sparse_feature_sizes=old_sparse_feature_sizes,
          attribute=TEXT,
          feature_type=feature_type,
          reg_lambda=0.02,
      )
      new_layer.build(input_shape=sum(new_sparse_feature_sizes))
  
      # check dimensions
      assert new_layer.get_kernel().shape[0] == sum(
          new_sparse_feature_sizes
      )
  
      # check if bias tensor was preserved correctly
      if use_bias:
          assert np.array_equal(
              layer.get_bias().numpy(), new_layer.get_bias().numpy()
          )
      else:
          assert new_layer.get_bias() is None
  
      # check if the existing weights were preserved
      chunk_index, new_chunk_index = 0, 0
      kernel, new_kernel = (
          layer.get_kernel().numpy(),
          new_layer.get_kernel().numpy(),
      )
      for old_size, new_size in zip(
          old_sparse_feature_sizes, new_sparse_feature_sizes
      ):
          chunk = kernel[chunk_index : chunk_index + old_size, :]
          new_chunk = new_kernel[
              new_chunk_index : new_chunk_index + old_size, :
          ]
          assert np.array_equal(chunk, new_chunk)
          chunk_index += old_size
          new_chunk_index += new_size
  
imports: import pytest
  import tensorflow
  import numpy
  from typing import Text, Union, Any, Dict, List, Type
  from rasa.shared.nlu.constants import TEXT, FEATURE_TYPE_SENTENCE, FEATURE_TYPE_SEQUENCE
  from rasa.utils.tensorflow import layers
  from rasa.utils.tensorflow.rasa_layers import ConcatenateSparseDenseFeatures, RasaFeatureCombiningLayer, RasaSequenceLayer, RasaCustomLayer
  from rasa.utils.tensorflow.constants import DENSE_INPUT_DROPOUT, SPARSE_INPUT_DROPOUT, DROP_RATE, DENSE_DIMENSION, REGULARIZATION_CONSTANT, CONCAT_DIMENSION, CONNECTION_DENSITY, DROP_RATE_ATTENTION, KEY_RELATIVE_ATTENTION, VALUE_RELATIVE_ATTENTION, MAX_RELATIVE_POSITION, UNIDIRECTIONAL_ENCODER, HIDDEN_LAYERS_SIZES, NUM_TRANSFORMER_LAYERS, TRANSFORMER_SIZE, NUM_HEADS, SENTENCE, SEQUENCE, MASKED_LM, LABEL
  from rasa.utils.tensorflow.exceptions import TFLayerConfigException
  from rasa.utils.tensorflow.model_data import FeatureSignature
label_desc: Use image node_id 10 for calling a global function with example usage: test_replace_dense_for_sparse_layers(new_sparse_feature_sizes, old_sparse_feature_sizes, feature_type, use_bias) without return types