Abstract
Automatic code summarization is essential for enhancing developer productivity, but state-of-the-art Transformer models require vast amounts of data. For niche languages like Solidity, such data is scarce. This paper introduces a selective transfer learning method that identifies "universal" attention heads in a pre-trained Python model and transfers them to a Solidity model. Using a discriminator-based filtering process, the approach isolates language-agnostic features. Experimental results demonstrate substantial gains, with BLEU-4 scores improving by up to 10.7% across various baseline architectures.
Introduction: The Data Scarcity Problem in Code Summarization
Code summarization—generating natural language descriptions for code snippets—is a vital task in software engineering. While Transformer-based models have achieved high performance in mainstream languages like Java and Python, they are notoriously "data-hungry." For emerging or specialized languages such as Solidity, used in blockchain smart contracts, the lack of large-scale labeled datasets creates a significant performance gap. This research addresses this challenge by transferring structural and semantic knowledge from a data-rich source language to a data-poor target language.
Methodology: Selective Multi-Head Attention Transfer
The core of the proposed approach is a surgical transfer of knowledge focused on the Multi-Head Attention module. Rather than transferring the entire model, the authors identify specific attention heads that capture universal programming concepts.
1. Transferable Knowledge Identification
The authors utilize a Discriminator ($D$) to distinguish between code representations from the source language (Python) and the target language (Solidity). The discriminator architecture includes Convolutional, Pooling, and LSTM layers.
2. Head Selection and Parameter Transfer
If the discriminator fails to accurately classify the origin of a specific attention head's output (indicated by a low F1 score), that head is deemed "transferable" as it captures domain-invariant features. The parameter matrices ($W^Q, W^K, W^V$) for these heads are copied to the target model and frozen. The remaining heads and the decoder are then trained on the target dataset to learn language-specific nuances.
Experimental Setup and Results
The study compared four state-of-the-art Transformer baselines using a source dataset of 450,000 Python pairs and a target dataset of 45,000 Solidity pairs.
Performance Gains
The application of Transfer Learning (TL) resulted in consistent improvements across all evaluated metrics (BLEU, ROUGE-L, and METEOR). Notably, the BLEU-4 scores saw dramatic increases, ranging from 4.31% to 10.70%.
As shown in the table above, the model [1]+TL achieved a BLEU-4 score of 25.20 compared to the baseline's 14.50, demonstrating the effectiveness of transferring "universal" programming logic even with 10x less training data.
Discussion and Conclusion
The primary innovation lies in treating individual attention heads as specialized feature extractors. By using a discriminator as a filter, the model avoids transferring language-specific "noise" that could hinder performance in the target domain.
However, the method's effectiveness depends on the structural similarity between the source and target languages. Future work may explore automated threshold tuning for head selection and extending the framework to more diverse language pairs. Ultimately, this selective transfer approach provides a robust path forward for applying advanced NLP techniques to low-resource programming environments.
Summary updated