The well-known Gumbel-Max Trick for sampling elements from a categorical distribution (or more generally a nonnegative vector) and its variants have been widely used in areas such as machine learning and information retrieval. To sample a random element (or a Gumbel-Max variable ) in proportion to its positive weight , the Gumbel-Max Trick first computes a Gumbel random variable for each positive weight element , and then samples the element with the largest value of . Recently, applications including similarity estimation and graph embedding require to generate independent Gumbel-Max variables from high dimensional vectors. However, it is computationally expensive for a large (e.g., hundreds or even thousands) when using the traditional Gumbel-Max Trick. To solve this problem, we propose a novel algorithm, \emph{FastGM}, that reduces the time complexity from to , where is the number of positive elements in the vector of interest. Instead of computing independent Gumbel random variables directly, we find that there exists a technique to generate these variables in descending order. Using this technique, our method FastGM computes variables for all positive elements in descending order. As a result, FastGM significantly reduces the computation time because we can stop the procedure of Gumbel random variables computing for many elements especially for those with small weights. Experiments on a variety of real-world datasets show that FastGM is orders of magnitude faster than state-of-the-art methods without sacrificing accuracy and incurring additional expenses.
View on arXiv