merlin.models.utils.schema_utils.get_embedding_size_from_cardinality

merlin.models.utils.schema_utils.get_embedding_size_from_cardinality(cardinality: int, multiplier: float = 2.0, ensure_multiple_of_8: bool = False)int[source]

Provides a heristic (from Google) that suggests the embedding dimension as a function (forth root) of the feature cardinality.

Parameters
  • cardinality (int) – The number of unique values of a categorical feature

  • multiplier (float, optional) – Multiplier to be applied on the forth root of the cardinality. Google recommends multiplier in the [2.0,10.0] range, by default 2.0

  • ensure_multiple_of_8 (bool, optional) – If enabled, adjusts the embedding dim to the smallest greater number multiple of 8, to ensure best performance with GPU ops, by default False

Returns

The suggested embedding dimension based on the feature cardinality

Return type

int