Abstract
Code Community Question Answering (CCQA) seeks to tackle programming-related issues, thereby boosting productivity in both software engineering and academic research. Recent advancements in Reinforcement Learning from Human Feedback (RLHF) have transformed the fine-tuning process of Large Language Models (LLMs) to produce responses that closely mimic human behavior. Leveraging LLMs with RLHF for practical CCQA applications has thus emerged as a promising area of study. Unlike standard code question-answering tasks, CCQA involves multiple possible answers, with varying user preferences for each response. Additionally, code communities often show a preference for new APIs. These challenges prevent LLMs from generating responses that cater to the diverse preferences of users in CCQA tasks. To address these issues, we propose a novel framework called Aligning LLMs through Multi-perspective User Preference Ranking-based Feedback for Programming Question Answering (ALMupQA) to create user-focused responses. Our approach starts with Multi-perspective Preference Ranking Alignment (MPRA), which synthesizes varied user preferences based on the characteristics of answers from code communities. We then introduce a Retrieval-augmented In-context Learning (RIL) module to mitigate the problem of outdated answers by retrieving responses to similar questions from a question bank. Due to the limited availability of high-quality, multi-answer CCQA datasets, we also developed a dataset named StaCCQA from real code communities. Extensive experiments demonstrated the effectiveness of the ALMupQA framework in terms of accuracy and user preference. Compared to the base model, ALMupQA showed nearly an 11% improvement in BLEU, with increases of 20% and 17.5% in BERTScore and CodeBERTScore, respectively.
Introduction: The Complexity of Programming Q&A
Code Community Question Answering (CCQA), exemplified by platforms like Stack Overflow, is significantly more complex than standard Q&A tasks. In programming, there is rarely a single "correct" answer; instead, multiple solutions exist with varying trade-offs in efficiency, readability, and modern API usage.
Standard Large Language Model (LLM) alignment techniques face three major hurdles in this domain:
- The "Accepted Answer" Trap: Standard RLHF often prioritizes the questioner's "accepted" answer, even when the broader community prefers a more modern or efficient alternative (indicated by higher votes).
- Diverse Preferences: Users value different attributes, such as brevity, detailed explanation, or specific library usage.
- The Staleness Problem: Programming standards evolve rapidly. An answer that was ideal years ago may be deprecated today.
Methodology: The ALMupQA Framework
To overcome these challenges, the researchers introduced ALMupQA, a framework designed to align LLMs with the nuanced, multi-perspective preferences of the programming community.
Multi-perspective Preference Ranking Alignment (MPRA)
Rather than using simple binary comparisons (e.g., "Answer A is better than Answer B"), MPRA creates a ranked list of potential answers. This ranking is synthesized from three distinct perspectives:
- Questioner-perspective (Bias Score): Measures alignment with the original questioner's choice.
- Users-perspective (Vote Score): Captures the "wisdom of the crowd" via community votes.
- LLM-perspective (Content Score): Evaluates semantic quality and logical flow using an auxiliary LLM.
By training on this hierarchy using a list-wise contrastive loss, the model learns a robust representation of code quality across a spectrum of answers.
Retrieval-augmented In-context Learning (RIL)
To combat knowledge cutoff and outdated advice, the framework utilizes a dense retriever to find similar, up-to-date question-answer pairs. These are provided as few-shot examples in the prompt, ensuring the LLM remains current with modern API trends.
Dataset and Results
The researchers developed StaCCQA, a dataset of 270,716 high-quality pairs from Stack Overflow. Every entry contains code blocks and an answer pool of at least two responses to facilitate preference ranking.
Experimental results show that ALMupQA (built on a Code Llama 2 7B base) achieved dramatic performance gains:
- Accuracy: BLEU scores improved from 11.86% to 22.86%.
- Semantic Alignment: BERTScore and CodeBERTScore increased by 20% and 17.5%, respectively.
- Competitive Performance: In zero-shot tests, the 7B ALMupQA model outperformed larger closed-source models, including GPT-3.5 and Claude 2, on several coding benchmarks.
Conclusion
ALMupQA demonstrates that moving beyond binary feedback to a multi-perspective ranking system—grounded in real-world community signals—significantly improves the utility and accuracy of LLMs for specialized technical domains. Future work will focus on refining the "LLM-as-a-judge" components to further tighten alignment with expert developer preferences.
Summary updated