Abstract
In text generation, a large language model (LM) makes a choice of each new word based only on the former selection of its context using the softmax function. Nevertheless, the link statistics information of concurrent words based on a scene-specific corpus is valuable in choosing the next word, which can help to ensure the topic of the generated text to be aligned with the current task. To fully explore the co-occurrence information, we propose a graphmax function for task-specific text generation. Using the graph-based regularization, graphmax enables the final word choice to be determined by both the global knowledge from the LM and the local knowledge from the scene-specific corpus. The traditional softmax function is regularized with a graph total variation (GTV) term, which incorporates the local knowledge into the LM and encourages the model to consider the statistical relationships between words in a scene-specific corpus. The proposed graphmax is versatile and can be readily plugged into any large pre-trained LM for text generation and machine translation. Through extensive experiments, we demonstrate that the new GTV-based regularization can improve performances in various natural language processing tasks in comparison with existing methods. Moreover, through human experiments, we observe that participants can easily distinguish the text generated by graphmax or softmax.
Introduction
Standard Large Language Models (LLMs) typically rely on the softmax function to convert internal logits into a probability distribution for next-word prediction. While effective for general tasks, this approach often fails to capture the "local fluency" or domain-specific word pairings unique to particular contexts. For instance, a model trained on general web data may struggle to replicate the specific linguistic habits of a niche community without expensive fine-tuning.
To address this, researchers have developed Graphmax, a "plug-and-play" alternative to the standard softmax function. Graphmax allows LLMs to better capture the specific style or "vibe" of a target dataset by incorporating graph-based regularization. This method blends the global knowledge of a pre-trained model with the local word-choice habits of a specific corpus, leading to more fluent and contextually appropriate text generation without the need for retraining the entire model.
Methodology
The core innovation of this work is the replacement of the standard softmax optimization problem with a regularized version that incorporates local statistical knowledge.
Graph Construction
The process begins by representing a scene-specific corpus (such as product reviews) as a weighted directed graph. In this graph, words serve as nodes, and edges represent 2-grams (sequences of two words). The weights of these edges are determined by the frequency of those word pairs within the local data.
Graph Total Variation (GTV) and Optimization
Borrowing from image processing, the authors utilize Graph Total Variation (GTV) to measure how much a predicted word distribution deviates from the "natural flow" defined by the local graph. Graphmax is formulated as a minimization problem that balances the model's original global prediction with this GTV term. Because this formulation does not have a simple closed-form solution like standard softmax, the authors employ Projected Gradient Descent (PGD) to iteratively solve for a valid probability distribution.
Experimental Setup
Graphmax was evaluated across several diverse natural language processing tasks:
- General Text Generation: Utilizing the Amazon (product reviews) and Yelp (restaurant reviews) datasets to capture specific colloquialisms.
- Machine Translation: Using the WMT’16 and WMT’21 corpora for translations between English and languages such as Romanian, Czech, German, Japanese, and Chinese.
Results and Discussion
Quantitative and Qualitative Performance
Graphmax consistently outperformed standard softmax in quantitative metrics. Notably, improvements were most significant in BLEU-5 scores, suggesting superior long-range local fluency. Additionally, the model showed a marked reduction in perplexity across various architectures (GPT-2, Llama 2, OPT), indicating it was better adapted to the target local data.
In human preference tests, evaluators rated Graphmax-generated text higher than standard outputs, specifically praising "Text Style" and "Story-line" coherence. Qualitatively, Graphmax-enabled models stayed more focused on the relevant domain narrative rather than drifting into generic or irrelevant information.
Efficiency and Logic
Mathematically, Graphmax acts as an n-gram mixture model. By using a first-order graph, it effectively considers 2-gram and 3-gram relationships simultaneously. This allows the model to respect human linguistic "habits"—the habitual word sequences that define local styles—by introducing the necessary "friction" to prefer these sequences over generic alternatives.
Conclusion and Future Work
While Graphmax offers significant gains in contextual alignment, it introduces a trade-off in inference speed. Due to the iterative nature of the PGD solver, inference time per word for models like Llama 2 was found to be 15–17 times higher than standard implementations. Furthermore, the strength of the local influence requires careful tuning of the penalty parameter ($\lambda$).
Future research will focus on optimizing the PGD algorithm or developing approximation methods to bring Graphmax's inference speed closer to real-time performance, as well as exploring the scalability of the graph structure for even larger vocabularies.
Summary updated