Abstract
Software documentation is essential for code reuse and maintenance, yet it remains one of the most neglected aspects of the development lifecycle. While Large Language Models (LLMs) have demonstrated significant capabilities in code summarization, they are constrained by context window limitations when processing entire software repositories. This paper introduces LARCH (Large Language Model-based Automatic Readme Creation with Heuristics), a novel pipeline that utilizes heuristics and weak supervision to identify the most representative code snippets within a repository. By providing LLMs with high-signal context, LARCH generates coherent and factually accurate README files that significantly outperform standard retrieval methods. Our evaluation shows that LARCH produces documentation deemed "useful" in 65% of cases, nearly doubling the performance of baseline selection methods.
1. Introduction
The "README struggle" is a well-known phenomenon in software engineering: documentation is vital for project visibility and usability, but its manual creation is tedious and often deferred. Recent advancements in Large Language Models (LLMs) like GPT-4 offer a potential solution for automated documentation. However, a primary bottleneck exists: the context window. A typical software project may contain thousands of lines of code distributed across hundreds of files, far exceeding the token limits of current models.
The core challenge in automated README generation is not merely generation, but selection. To generate an accurate summary, a system must identify the critical 1% of the codebase that defines the project's purpose and functionality. LARCH addresses this by focusing on identifying the "entry point" of a repository to provide the LLM with the most relevant context.
2. Methodology
LARCH employs a multi-stage pipeline designed to distill a whole repository into a representative snippet suitable for LLM processing.
2.1 Representative Code Identification
Rather than selecting files at random or using simple size-based metrics, LARCH utilizes 14 distinct heuristics to identify the core logic of a project. These heuristics include:
- File Content Analysis: Identifying the presence of
mainfunctions, argument parsers (e.g.,argparse), or specific web frameworks (e.g., Flask). - Directory Metadata: Analyzing filenames (e.g.,
cli.py,main.py) and the depth of the file within the folder structure. - Static Analysis: Constructing import trees to identify files at the top of the hierarchy, which typically signify entry points that orchestrate other modules.
2.2 Weak Supervision and Ranking
Because manually labeling "representative" files across thousands of repositories is prohibitively expensive, the authors utilized a weak supervision approach via the Snorkel framework. By combining the 14 noisy heuristics, LARCH generates "silver labels" to train a Gradient Boosting Tree model. This model ranks all files in a repository by their likelihood of being the primary entry point.
2.3 Prompt Engineering
The final generation phase uses GPT-3 (davinci-text-003). The prompt is carefully constructed to include:
- The project name.
- The full text of the top-ranked representative file (truncated if necessary).
- A list of ten additional random filenames from the repository to provide the model with a sense of the project's overall scale and architecture.
3. Experimental Setup
The researchers curated a dataset from GitHub consisting of Python repositories with over 100 stars created after June 2020. This date threshold ensures the projects were not included in the LLM's original training data, preventing data leakage. The evaluation set comprised 1,500 repositories for automatic metrics and a subset of 20 repositories for intensive human evaluation.
4. Results
LARCH was compared against a baseline that selected a Python file from the repository at random. The results demonstrate the efficacy of heuristic-based selection:
- Human Evaluation: In double-blind studies, LARCH was rated as "Useful" (ready for use with only minor revisions) in 65% of cases, compared to 40% for the baseline.
- Factual Correctness: One of the most significant improvements was in the accuracy of generated code examples. LARCH increased factual correctness from 30% (baseline) to 65%.
- Overall Utility: LARCH performed equal to or better than the baseline in 95% of the repositories tested.
5. Discussion and Limitations
Our findings suggest that the "entry point" is the most critical factor in README quality. If an LLM understands how a program is invoked, it can successfully infer the project's broader goals. Furthermore, the study found that imperative prompts (e.g., "Write a detailed readme") outperformed declarative ones.
However, several limitations remain:
- License Hallucination: LARCH frequently hallucinated incorrect software licenses (e.g., citing MIT for a GPL project) because license files were excluded from the prompt context.
- Language Specificity: While the framework is generalizable, the current heuristics are optimized for Python (e.g., looking for
if __name__ == "__main__":). Adaptation for languages like Java or C++ would require new heuristic sets. - Verification: As with all LLM-based tools, LARCH can produce confident but false statements, necessitating a human-in-the-loop for final verification.
6. Conclusion
LARCH demonstrates that intelligent context selection is as important as the generative model itself in automated software documentation. By using weak supervision to identify representative code, LARCH bridges the gap between massive codebases and limited LLM context windows, providing a practical tool for developers to maintain high-quality project documentation.
Summary updated