Uni-Encoder: A Fast and Accurate Response Selection Paradigm for Generation-Based Dialogue Systems (2023)

Abstract: Sample-and-rank is a key decoding strategy for modern generation-based dialogue systems. It helps achieve diverse and high-quality responses by selecting an answer from a small pool of generated candidates. The current state-of-the-art ranking methods mainly use an encoding paradigm called Cross-Encoder, which separately encodes each context-candidate pair and ranks the candidates according to their fitness scores. However, Cross-Encoder repeatedly encodes the same lengthy context for each candidate, resulting in high computational costs. Poly-Encoder addresses the above problems by reducing the interaction between context and candidates, but with a price of performance drop. In this work, we develop a new paradigm called Uni-Encoder, that keeps the full attention over each pair as in Cross-Encoder while only encoding the context once, as in Poly-Encoder. Uni-Encoder encodes all the candidates with the context in one forward pass. We use the same positional embedding for all candidates to ensure they are treated equally and design a new attention mechanism to avoid confusion. Our Uni-Encoder can simulate other ranking paradigms using different attention and response concatenation methods. Extensive experiments show that our proposed paradigm achieves new state-of-the-art results on four benchmark datasets with high computational efficiency. For instance, it improves R10@1 by 2.9% with an approximately 4X faster inference speed on the Ubuntu V2 dataset.

## introduction one of the major milestones of artificial intelligence is the ability to converse freely in natural language. researchers in this field are working on building open-domain dialogue systems capable paradigm context-response full attention avoidance of context recomputation performance bi-encoder ✗ ✓ 80.6% cross-encoder ✓ ✗ 82.8% poly-encoder ✗ ✓ 80.9% uni-encoder (ours) ✓ ✓ 85.9% to combine the advantage of both methods, @xcite proposed a "sample-and-rank" method, which first samples a small pool of candidate responses from the generator and then reranks the candidates to get the best response by a ranker. because a ranking model can view the whole responses while a pure generation method can only generate answers based on partial information, sample-and-rank method often performs better than the pure sample method. under the sampleand-rank framework, researchers have greater free-dom to explore different ranking methods @xcite @xcite . they can encode candidates on-the-fly and encode them with the context. cross-encoder @xcite is one such paradigm. it jointly encodes the historical context with every candidate using full attention and ranks them according to the context-candidate matching scores. despite its superior performance, cross-encoder repeatedly encodes the context for each candidate. since contexts are often much longer than responses, the computation is slow for practical use. poly-encoder @xcite mitigates the above problem by reducing the full attention at every layer of transformer @xcite to global attention at the last layer. however, later work @xcite @xcite confirms the importance of full attention and still uses cross-encoder as the base building block for response selection. one interesting research question is whether there is a way to realize full attention between each context-response pair without repeatedly encoding the same long context. to answer the above question, we proposed a new paradigm called uni-encoder, as presented in first, we use the same set of positional embeddings for all candidates so that they are all treated equally because each is a possible continuation of the given context. second, we also design a novel attention mechanism for our new paradigm that only allows contextcandidate attention and forbids the candidates to attend to each other directly. through changing these two designs, uni-encoder can simulate the effects of any other paradigm (cross-, bi-or poly-encoder) by changing how context and candidate attend to each other and how many candidates are processed in a single forward pass. we evaluate our new paradigm on four benchmark datasets: personachat @xcite , ubuntu dialogue corpus v1 @xcite , ubuntu dialogue corpus v2 @xcite , and douban conversation corpus @xcite . empirical results show that our method achieves state-of-the-art performance, jointly with high computational efficiency. for instance, our uni-encoder has an absolute 2.9% r@1 improvement over the state-of-the-art cross-encoder on the widely used ubuntu dialogue corpus v2 dataset. it also has a lower computational cost than cross-encoder and is approximately four times faster at inference time. our source code and model checkpoints will be released for reproducibility and future research foot_0 . ## related work neural approaches for open-domain dialogue have seen significant recent progress. due to this progress, generation-based dialogue systems have started outperforming retrieval-based methods @xcite as they can handle a wider variety of topics. @xcite show that sample-and-rank provides much more diverse and content-rich responses than beam-search. an additional ranking step allows responses to have full attention/view over themselves and the context, while pure generation methods only have left attention/view. this different view is why an additional ranking process is needed. in this study, we particularly focus on improving this ranking process. because scoring candidates given a context is a classical problem in machine learning, numerous methods @xcite @xcite have been developed over the years. we will only discuss a few closely related works. please refer to @xcite for a more detailed discussion. bi-encoder @xcite encodes the context and the candidate separately, then scores the relatedness between their representations. due to its simplicity and efficiency, bi-encoder often serves as a baseline method when a new dataset introduces @xcite . one significant advantage of the bi-encoder is that its response representations can be pre-computed as they are context-independent. however, in modern generation-based dialogue systems, this advantage becomes a weakness. it is not necessary to pre-encode responses that are generated on-the-fly. and without context-response interaction, the ranking performance is severely weakened. poly-encoder @xcite improves the accuracy of the bi-encoder by adding a learned self-attention layer on top of the context and candidate features extracted from both encoders. nevertheless, cross-encoder is preferable to generation-based dialogues systems in practice due to its high effectiveness @xcite . instead of encoding each context and response pair separately, they encode them jointly using a full attention mechanism. recent improvements in response selection are mostly on cross-encoder. for example, @xcite adapt contrastive learning to cross-encoder with a specially designed strategy and obtain a significant performance gain. @xcite and @xcite add speaker change information to the inputs showing a large improvement in the response selection task. @xcite and @xcite further post-train the encoder on domainspecific data and see additional improvements. to further utilize target data, @xcite and @xcite investigate some additional self-supervised learning tasks. these tasks served as additional objectives jointly trained with the response selection task. unlike all the above improvements, our improvement is on the encoder itself and can incorporate these additional tricks. ## methods this section elaborates on the problem formulation of dialogue response selection, compares different paradigms to model this task, and describes our implementation of uni-encoder. ## discussion this paper presents a new paradigm for the generation-based dialogue response selection task. our proposed uni-encoder avoids re-computing the lengthy context in the current state-of-the-art cross-encoder method while maintaining the full context to candidate attention. experimental results on four benchmark datasets show that our approach is both fast and accurate. as uni-encoder holds the potential to build a more effective and efficient ranking paradigm, our future research will explore its usage in broader applications, such as improving the reward model in the reinforcement learning from human feedback (rlhf) framework @xcite @xcite . ## limitations one major limitation of uni-encoder is its suitability only for generation-based dialogue systems in which the number of responses is small. a twostage approach is necessary for retrieval-based systems: context-independent encoding methods like poly-encoder first filter out a small set of candidates from the large pool, then uni-encoder can pick out the best response from the pre-filtered collection. moreover, as discussed in section 5, uni-encoder could be a good component of the rlhf approach. however, the increasing research of pure generation methods with alignments bakedin @xcite may gradually replace the sft+rl method. consequently, uni-encoder will have a smaller and smaller impact in terms of application. nevertheless, because uni-encoder unified all other ranking paradigms, we believe it remains helpful even as a theoretical framework.