EDRep

Efficient distributed representations with linear-time SoftMax normalization

Python Lorenzo Dall'Amico, Enrico Maria Belliardo

EDRep is a Python package to learn distributed representations (embeddings) of any entity described by a probability matrix $P$, such as the nodes of a graph, users and items, or words. Embeddings are obtained by minimizing the cross-entropy between $P$ and a SoftMax of the scalar products of the embedding vectors:

$$ X = \underset{Y \in \mathcal{U}_{n\times d}}{\arg\min} \sum_{i=1}^n \Bigg[\underbrace{-\sum_{j=1}^n P_{ij}\log\Big({\rm SoftMax}(YY^T)_{ij}\Big)}_{\text{cross-entropy}} + \underbrace{\frac{1}{n}\,y_i^T\sum_{j=1}^n y_j}_{\text{regularization}}\Bigg]. $$

Computing the SoftMax normalization constants exactly takes quadratic time. EDRep estimates them in linear time with a mixture-of-Gaussians approximation, making the method fast, interpretable and easy to adapt to arbitrary embedding problems. The method is described in our TMLR paper.

Installation

Install the package from PyPI:

pip install EDRep

We also share the Anaconda environment in which all the code was run and tested (EDRep_env.yml in the repository):

conda env create -f EDRep_env.yml
conda activate EDRep

Quick start

from scipy.sparse import csr_matrix
from EDRep import CreateEmbedding, NodeEmbedding

# embed a (sparse) row-stochastic matrix P
res = CreateEmbedding([P], dim = 32)
X = res.X        # n x dim embedding matrix

# or embed the nodes of a graph from its adjacency matrix A
res = NodeEmbedding(A, dim = 32)
Note

The pages below are rendered from Jupyter notebooks, which you can download from each page and run yourself, together with the helper scripts they import from src/. The datasets are not included: each page explains where to find them.

Contents

Citation

If you use this package, please cite:

@article{dallamico2025learning,
  title   = {Learning distributed representations with efficient SoftMax normalization},
  author  = {Dall'Amico, Lorenzo and Belliardo, Enrico Maria},
  journal = {Transactions on Machine Learning Research},
  issn    = {2835-8856},
  year    = {2025},
  url     = {https://openreview.net/forum?id=9M4NKMZOPu}
}