TransformLLM: Adapting Large Language Models via LLM-Transformed Reading Comprehension Text

Iftach Arbel, Yehonathan Refael, Ofir LindenbaumarXiv 2024 · DOI

Introduction

Adapting Large Language Models (LLMs) to specialized domains like law, medicine, or finance presents a significant challenge. The traditional approach—continued pre-training on raw domain-specific corpora—often results in "prompting degradation," where the model loses its general instruction-following and reasoning capabilities. Furthermore, raw text is frequently noisy, and previous attempts to structure this data relied on rigid, limited heuristics.

TransformLLM addresses these issues by introducing a framework that moves beyond simple next-token prediction. Instead, it uses LLMs to convert raw domain-specific text into structured reading comprehension tasks, forcing the model to engage in active "comprehension" during adaptation. By training on these "transformed" datasets, the authors developed Phi-2-Legal and Mistral-Legal-7B, which achieve state-of-the-art performance on legal benchmarks while using significantly fewer resources than previous specialized models.

Methodology: LLM-Transformed Reading Comprehension

The core innovation of TransformLLM is its data synthesis pipeline. Rather than feeding raw legal text directly into the training process, the authors utilized existing open-source LLMs (ranging from 7B to 70B parameters) to act as "data engineers." These teacher models transformed raw legal text into a variety of structured formats, including Q&A pairs, summarization tasks, and natural language inference (NLI) exercises.

Examples of LLM-transformed reading comprehension tasks.

By framing domain adaptation as a reading comprehension task, the model learns the underlying logic and relationships within the domain rather than just the statistical distribution of specialized vocabulary. This approach ensures that the model maintains its ability to follow complex instructions while acquiring deep domain knowledge.

Training Strategy

The authors applied this method to Phi-2 (3B) and Mistral-7B-v0.1, training them on approximately 500 million tokens of transformed legal data. To maintain efficiency and prevent catastrophic forgetting of general reasoning, the training process included:

  • Parameter Efficiency: Using LoRA (Low-Rank Adaptation) with a rank of $r=64$ to update attention and feed-forward layers, avoiding the high cost of full-parameter updates.
  • Balanced Mixture: Mixing legal data with general instruction datasets covering math (CoT), code, and general chat. These datasets act as an anchor for logical reasoning, which is particularly vital in the legal domain where "if-then" logic is paramount.
  • Greedy Packing: Implementing a greedy packing algorithm to concatenate examples into full context windows (2K for Phi-2, 4K for Mistral) without truncating individual tasks, improving training efficiency by up to 80%.

Datasets and Evaluation

The legal training data was sourced from major repositories including The Pile (FreeLaw subset), Pile of Law, and USClassActions. To evaluate the resulting models, the authors used the legal subsets of the MMLU benchmark (International Law, Jurisprudence, Professional Law) and the LexGLUE suite, which includes tasks like contract provision classification (LEDGAR), legal citation (CaseHOLD), and Unfair Terms of Service (ToS) detection.

Key Results

The results demonstrate that data quality and structure are more important than raw volume. Mistral-Legal-7B, for instance, outperformed Saul-7B despite the latter being trained on 30 times more data and using full-parameter updates. This suggests that using LLMs to "distill" raw data is far superior to using human-written heuristics.

Performance of legal-adapted models on MMLU and LexGLUE benchmarks.

As shown in the results table, the improvements were particularly dramatic for the smaller Phi-2 model. On the LEDGAR benchmark, Phi-2-Legal's performance jumped from a base of 0.143 to 0.603. Mistral-Legal-7B achieved state-of-the-art results for its size class, scoring 0.739 on LEDGAR and 0.778 on CaseHOLD, outperforming both AdaptLLM and Saul-7B across nearly all LexGLUE subsets.

Discussion and Conclusion

TransformLLM proves that LLMs can be used to effectively structure raw "library" data into high-quality "textbooks" for domain adaptation. The inclusion of general reasoning anchors is vital for domains like law, where logical reasoning is a core requirement.

While these models show significant gains in reasoning, the authors note that multiple-choice benchmarks are only proxies for real-world legal work. They do not fully measure a model's ability to draft complex, nuanced legal documents from scratch. Future work will explore applying this transformation method to other technical fields and incorporating Reinforcement Learning from Human Feedback (RLHF) to further align models with professional standards. For tasks requiring extreme factual precision, the authors recommend deploying these models within a Retrieval-Augmented Generation (RAG) framework to mitigate potential hallucinations.

Summary updated

BibTeX
@misc{arbel2024transformllm,
  author = {Iftach Arbel and Yehonathan Refael and Ofir Lindenbaum},
  title = {{TransformLLM: Adapting Large Language Models via LLM-Transformed Reading Comprehension Text}},
  year = {2024},
  eprint = {2410.21479},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.21479},
}
Figure