class_docstr: Ranks Documents based on their similarity to the query.
  It uses a pre-trained cross-encoder model (from the Hugging Face Hub) to embed the query and the Documents.
  
  Usage example:
  ```
  from haystack import Document
  from haystack.components.rankers import TransformersSimilarityRanker
  
  ranker = TransformersSimilarityRanker()
  docs = [Document(content="Paris"), Document(content="Berlin")]
  query = "City in Germany"
  output = ranker.run(query=query, documents=docs)
  docs = output["documents"]
  assert len(docs) == 2
  assert docs[0].content == "Berlin"
  ```
class_docstr_tok: ["Ranks","Documents","based","on","their","similarity","to","the","query",".","It","uses","a","pre-trained","cross-encoder","model","(","from","the","Hugging","Face","Hub",")","to","embed","the","query","and","the","Documents",".","Usage","example",":","``","`","from","haystack","import","Document","from","haystack.components.rankers","import","TransformersSimilarityRanker","ranker","=","TransformersSimilarityRanker","(",")","docs","=","[","Document","(","content=","''","Paris","''",")",",","Document","(","content=","''","Berlin","''",")","]","query","=","``","City","in","Germany","''","output","=","ranker.run","(","query=query",",","documents=docs",")","docs","=","output","[","``","documents","''","]","assert","len","(","docs",")","==","2","assert","docs","[","0","]",".content","==","``","Berlin","''","``","`"]
docstr: Deserialize this component from a dictionary.
docstr_tok: ["Deserialize","this","component","from","a","dictionary","."]
code: def from_dict(
      cls, data: Dict[str, Any]
  ) -> "TransformersSimilarityRanker":
      """
      Deserialize this component from a dictionary.
      """
      torch_and_transformers_import.check()
      init_params = data.get("init_parameters", {})
      model_kwargs = init_params.get("model_kwargs", {})
      # convert string to torch.dtype
      # 1. torch_dtype and bnb_4bit_compute_dtype can be specified in model_kwargs
      for key, value in model_kwargs.items():
          if key in [
              "torch_dtype",
              "bnb_4bit_compute_dtype",
          ] and value.startswith("torch."):
              data["init_parameters"]["model_kwargs"][key] = getattr(
                  torch, value.strip("torch.")
              )
      # 2. bnb_4bit_compute_dtype can be specified in model_kwargs["quantization_config"]
      quantization_config = model_kwargs.get("quantization_config", {})
      bnb_4bit_compute_dtype = quantization_config.get(
          "bnb_4bit_compute_dtype", None
      )
      if isinstance(
          bnb_4bit_compute_dtype, str
      ) and bnb_4bit_compute_dtype.startswith("torch."):
          data["init_parameters"]["model_kwargs"][
              "quantization_config"
          ]["bnb_4bit_compute_dtype"] = getattr(
              torch, bnb_4bit_compute_dtype.strip("torch.")
          )
  
      return default_from_dict(cls, data)
  
file_path: haystack/haystack/components/rankers/transformers_similarity.py
imports: import logging
  from pathlib import Path
  from typing import List, Union, Dict, Any, Optional
  from haystack import ComponentError, Document, component, default_to_dict, default_from_dict
  from haystack.lazy_imports import LazyImport
  from haystack.utils import get_device
label_desc: Use image node_id 5 for calling the TransformersSimilarityRanker obj's underlying member method code with example usage: obj.from_dict(cls, data) and returns: default_from_dict