--- license: apache-2.0 --- # Instruction Pre-Training: Language Models are Supervised Multitask Learners This repo contains the **context-based instruction synthesizer** used in our paper **Instruction Pre-Training: Language Models are Supervised Multitask Learners**. we explore supervised multitask pre-training by proposing ***Instruction Pre-Training***, a framework that scalably augments massive raw corpora with instruction-response pairs to pre-train language models. The instruction-response pairs are generated by an efficient instruction synthesizer built on open-source models. In our experiments, we synthesize 200M instruction-response pairs covering 40+ task categories to verify the effectiveness of *Instruction Pre-Training*. ***Instruction Pre-Training* outperforms *Vanilla Pre-training* in both general pre-training from scratch and domain-adaptive continued pre-training.** In pre-training from scratch, *Instruction Pre-Training* not only improves pre-trained base models but also benefits more from further instruction tuning. In continual pre-training, *Instruction Pre-Training* enables Llama3-8B to be comparable to or even outperform Llama3-70B.
## Synthesize Instruction-Response Pairs from Any Raw Corproa We conduct multitask fine-tuning on a language model to develop an instruction synthesizer capable of generating instruction-response pairs from any raw text.
An example script to prompt the synthesizer to generate instruction-response pairs based on the given raw text is: ```python from transformers import AutoModelForCausalLM, AutoTokenizer model = AutoModelForCausalLM.from_pretrained("instruction-pretrain/instruction-synthesizer") tokenizer = AutoTokenizer.from_pretrained("instruction-pretrain/instruction-synthesizer") # Put your raw text here: context = '''Free Fishing Weekend in NYS Slated This weekend (June 28th-29th) New Yorkers may fish for free without a license in any of the state's 7,500 lakes and ponds or 50,000 miles of rivers and streams. In addition, there are a number of free events and fishing clinics taking place across the state to encourage New Yorkers to enjoy the great outdoors. For more information, visit''' def parse_pred(pred): """Extract the list of instruction-response pairs from the prediction""" QA_str_list = pred.split('') if not pred.endswith(''): QA_str_list = QA_str_list[:-1] QA_list = [] raw_questions = [] for QA_str in QA_str_list: try: assert len(QA_str.split('