code: def test_to_dict_with_custom_init_parameters(self):
      component = TransformersSimilarityRanker(
          model="my_model",
          device="cuda",
          token="my_token",
          top_k=5,
          scale_score=False,
          calibration_factor=None,
          score_threshold=0.01,
          model_kwargs={"torch_dtype": torch.float16},
      )
      data = component.to_dict()
      assert data == {
          "type": "haystack.components.rankers.transformers_similarity.TransformersSimilarityRanker",
          "init_parameters": {
              "device": "cuda",
              "model": "my_model",
              "token": None,  # we don't serialize valid tokens,
              "top_k": 5,
              "meta_fields_to_embed": [],
              "embedding_separator": "\n",
              "scale_score": False,
              "calibration_factor": None,
              "score_threshold": 0.01,
              "model_kwargs": {
                  "torch_dtype": "torch.float16"
              },  # torch_dtype is correctly serialized
          },
      }
  
file_path: haystack/test/components/rankers/test_transformers_similarity.py
imports: from unittest.mock import MagicMock, patch
  import pytest
  import torch
  from transformers.modeling_outputs import SequenceClassifierOutput
  from haystack import Document, ComponentError
  from haystack.components.rankers.transformers_similarity import TransformersSimilarityRanker
label_desc: Use image node_id 2 for calling the TestSimilarityRanker obj's underlying member method code with example usage: obj.test_to_dict_with_custom_init_parameters() without return types