<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>PQ-VAE: Eficient Recommendation Using Quantized Embeddings</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Jan Van Balen Apple</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Inc. London</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>UK jvanbalen@apple.com</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Mark Levy Apple</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Inc. London</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>UK mark_levy@apple.com</string-name>
        </contrib>
      </contrib-group>
      <pub-date>
        <year>2019</year>
      </pub-date>
      <abstract>
        <p>Large neural recommendation models can be a challenge to deploy at scale. For recommendation services with a large number of users, the most powerful models may require an impractical amount of space to store the large dense vectors encoding each of the users' tastes. Combining ideas from auto-encoder-based recommender systems, neural discrete representation learning (VQ-VAE), and product quantization (PQ), we propose PQ-VAE, a recommendation model that learns compact, discrete embeddings at only a small cost in accuracy.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>dimension, and P is the precision in bits (typically 32). With tens of millions of users, and sometimes
multiple vectors per user, that could mean upward of 100G of embeddings.</p>
      <p>
        In this work, we propose PQ-VAE: a neural recommendation model that uses quantization to learn
compact user embeddings at only a small accuracy cost. Our approach builds on three ideas: the
auto-encoder recommenders proposed in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], neural discrete representation learning [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], and product
quantization [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
      </p>
    </sec>
    <sec id="sec-2">
      <title>RELATED WORK</title>
      <p>
        Experiments in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] have shown how denoising auto-encoders (DAE) and variational auto-encoders (VAE)
can be used for recommendation. The proposed DAE model is essentially a simple fully-connected
neural network with a few hidden layers. Each input example is a user’s history of item interactions,
as a sparse M-dimensional vector of counts. Its objective is to reconstruct these inputs after noise is
added in the form of dropout. The M reconstructed values are the recommender’s item scores.
      </p>
      <p>
        We combine this model with discrete representations. VQ-VAE, the model proposed in [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], learns
discrete representations of audio and image data, by trying to reconstruct its input from an
intermediate representation to which vector quantization is applied. By reducing an image to a small number
of integer codes, VQ-VAE generally makes for a good tool for data compression.
      </p>
      <p>
        The third innovation on which we built PQ-VAE is product quantization [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. This is a technique that
is used primarily for approximate nearest neighbor search. The idea is that, by applying piece-wise
k-means vector quantization to the candidate vectors, only O(k) distance computations need to
be performed per query. The resulting distances can be relatively cheaply combined to obtain the
approximate distance to each of the neighbors. To the best of our knowledge, the ideas in [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] and [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]
have been previously only been combined in the context of image retrieval [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ].
      </p>
      <p>
        PQ-VAE
PQ-VAE, like the state-of-the-art DAE recommender from [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], is a neural network that takes a user’s
item interaction counts as inputs and produces item scores on the output side. The model’s objective
during training is to reconstruct its inputs. The network itself consists of one or more fully-connected
layers with tanh activations, as shown in the top half of Figure 1. Unlike the DAE, we apply quantization
to the activations of the last hidden layer, similarly to how VQ-VAE learns discrete representations.
This is equivalent to the way vectors are quantized in product quantization.
      </p>
      <p>
        Concretely, the vector of activations corresponding to each example is cut into chunks of around
length 10, and each of these chunks is quantized using a learned codebook. This presents a few
challenges at training time. First, the quantization operation is not diferentiable, making it impossible
to optimize the above model exactly via gradient descent. As in [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], we work around this by using the
unquantized instead of the quantized vector during the gradient computation, as if the quantization
1This is sometimes referred to as
straightthrough estimation. In a way, it is not too
diferent from how a DAE learns: the quantization
effectively produces additive (quantization) noise
to which the model must learn to develop some
amount of invariance.
2In a typical recommendation scenario, user
embeddings function as query vectors, and
item embeddings as candidates to be retrieved.
      </p>
      <p>
        In this paradigm, PQ-VAE quantizes queries as
opposed to (more usually in PQ) the candidate
vectors. Therefore, we cannot use PQ-based
nearest neighbor search directly. We found that
is possible to reduce the complexity of the
similarity computation between a query and a
collection of candidate vectors regardless of which
of the two are quantized. However, eficient
distance computations on quantized user
embeddings require the similarity scores between the
query codebook and all candidates to be
precomputed, trading memory footprint for speed.
step simply never happened.1 Second, we would like to learn codes eficiently as part of model training.
To this end, we use exponential moving average k-means to learn codes in a batch-wise fashion, again
following [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]; this way we avoid having to process the entire dataset on every update, as in the classic
k-means algorithm.
      </p>
      <p>In a trained PQ-VAE, the quantized representations in the last hidden layer represent the user, as
illustrated in Figure 1. When these user representations are frozen for serving, we can convert them
to discrete vectors, allowing us to store them with just 10–100 bytes each, 1-2 orders of magnitudes
less that the the embeddings learned by a large DAE.</p>
      <p>
        Finally, the PQ structure of the embeddings alternatively allows for eficient retrieval. At prediction
time, the PQ structure of the embeddings allows us to swap out the model’s final layer for PQ-based
similarity scoring, replacing most of the multiply-adds with a lookup into precomputed scores.2
However, we noticed that without a highly optimized PQ implementation (see e.g. [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]) it is dificult to
make this approach surpass the performance of brute-force similarity search on real-world datasets.
      </p>
      <p>USER ITEM INTERACTIONS
USER ITEM PREDICTIONS
DROPOUT</p>
      <p>DENSE +</p>
      <p>TANH</p>
      <p>DENSE +</p>
      <p>TANH</p>
      <p>DENSE +</p>
      <p>TANH</p>
      <p>QUANTIZE
CHUNKS</p>
      <p>DENSE +</p>
      <p>SOFTMAX
ranking performance drops by 19%. Preliminary results on the larger internal dataset are consistent
with these findings: a 40× user vector compression can be achieved with a relative performance drop
of less than 5%.</p>
    </sec>
    <sec id="sec-3">
      <title>CONCLUSION</title>
      <p>We show that is possible to learn high-quality, memory-eficient user representations by implementing
product quantization inside a neural recommender. In future work we hope to further leverage the
discrete nature of the learned user representations to speed up prediction.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>Hergé</given-names>
            <surname>Jégou</surname>
          </string-name>
          , Mathijs Douze, and
          <string-name>
            <given-names>Cordelia</given-names>
            <surname>Schmid</surname>
          </string-name>
          .
          <year>2011</year>
          .
          <article-title>Product Quantization for Nearest Neighbor Search</article-title>
          .
          <source>IEEE Transactions on Patern Analysis and Machine Intelligence</source>
          <volume>33</volume>
          ,
          <issue>1</issue>
          (Jan
          <year>2011</year>
          ),
          <fpage>117</fpage>
          -
          <lpage>128</lpage>
          . htps://doi.org/10.1109/TPAMI.
          <year>2010</year>
          .57
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>Jef</given-names>
            <surname>Johnson</surname>
          </string-name>
          , Mathijs Douze, and
          <string-name>
            <given-names>Hervé</given-names>
            <surname>Jégou</surname>
          </string-name>
          .
          <year>2017</year>
          .
          <article-title>Billion-scale similarity search with GPUs</article-title>
          .
          <source>arXiv preprint arXiv:1702.08734</source>
          (
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>Dawen</given-names>
            <surname>Liang</surname>
          </string-name>
          , Rahul G. Krishnan,
          <string-name>
            <given-names>Mathew D.</given-names>
            <surname>Hofman</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Tony</given-names>
            <surname>Jebara</surname>
          </string-name>
          .
          <year>2018</year>
          .
          <article-title>Variational Autoencoders for Collaborative Filtering</article-title>
          .
          <source>In Proceedings of the 2018 World Wide Web Conference (WWW '18)</source>
          .
          <source>International World Wide Web Conferences Steering Commitee, Republic and Canton of Geneva, Switzerland</source>
          ,
          <fpage>689</fpage>
          -
          <lpage>698</lpage>
          . htps://doi.org/10.1145/3178876.3186150
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Harald</given-names>
            <surname>Steck</surname>
          </string-name>
          .
          <year>2019</year>
          .
          <article-title>Embarrassingly Shallow Autoencoders for Sparse Data</article-title>
          . arXiv preprint arXiv:
          <year>1905</year>
          .
          <volume>03375</volume>
          (
          <year>2019</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <surname>Aaron</surname>
            <given-names>van den Oord</given-names>
          </string-name>
          , Oriol Vinyals, and koray kavukcuoglu.
          <year>2017</year>
          .
          <article-title>Neural Discrete Representation Learning</article-title>
          .
          <source>In Advances in Neural Information Processing Systems</source>
          30, I. Guyon,
          <string-name>
            <given-names>U. V.</given-names>
            <surname>Luxburg</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Bengio</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Wallach</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Fergus</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Vishwanathan</surname>
          </string-name>
          , and R. Garnet (Eds.). Curran Associates, Inc.,
          <fpage>6306</fpage>
          -
          <lpage>6315</lpage>
          . htp://papers.nips.cc/paper/ 7210-neural
          <article-title>-discrete-representation-learning</article-title>
          .pdf
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>Hanwei</given-names>
            <surname>Wu</surname>
          </string-name>
          and
          <string-name>
            <given-names>Markus</given-names>
            <surname>Flierl</surname>
          </string-name>
          .
          <year>2018</year>
          .
          <article-title>Learning Product Codebooks using Vector Quantized Autoencoders for Image Retrieval</article-title>
          . arXiv preprint arXiv:
          <year>1807</year>
          .
          <volume>04629</volume>
          (
          <year>2018</year>
          ).
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>