Mozi: A Scientific Large-scale Language Model
Team of Beijing Institute of Technology: Tian Lan*, Tianyi Che*, Zewen Chi, Xuhao Hu and Xian-ling Mao
Catalogue:
- 1. Introduction
- 2. Running Mozi Demo
- 3. Train Your Own SciDPR model
- 3. Train Your Own Mozi models
- Citation
- Technical Report
- Acknowledgments
[Back to Top]
1. Introduction:Mozi is the first large-scale language model for the scientific paper domain, such as question answering and emotional support. With the help of the large-scale language and evidence retrieval models, SciDPR, Mozi generates concise and accurate responses to users' questions about specific papers and provides emotional support for academic researchers.
We will explore more real-world application scenarios for Mozi in the future, making it a foundation model for solving various scientific tasks.
[Back to Top]
2. Running Mozi Models:2.1. Environment Installation:
To install the required environment, please run
pip install -r requirements.txt
Then install the Pytorch package with the correct cuda version, for example
pip install torch==1.13.1+cu117 -f https://download.pytorch.org/whl/torch/
2.2. Prepare Mozi Checkpoint:
The Mozi model weights (pre-trained on scientific corpus) consists of the pre-trained large-scale language and the LoRA weights.
-
First of all, please download LLaMA-7B checkpoint and Baichuan-7B checkpoint.
-
Then, please download the LoRA weights for these two models from:
LoRA checkpoints Huggingface Delta Weights Address Baichuan-7B delta weight mozi_baichuan_7b LLaMA-7B delta weight mozi_llama_7b -
We also release the delta LoRA model weights for scientific emotional dialogue, which can be found in here. The emotional dialogue delta weights are built on Baichuan-7B model. In the future, we will directly optimize this scientific emotional dialogue instruction tuning dataset with other instruction dataset, such as paper-ground question answering and scientific information retrieval.
Now, the model parameters are all prepared.
2.3. Deploying Demo:
Upon completion of previous steps, you can run the demo locally as
./scripts/deploy.sh
# #!/bin/bash
# CUDA_VISIBLE_DEVICES=0 python deploy.py \
# --model scillm-sft\
# --model_path baichuan-inc/baichuan-7B\
# --delta_model_path ../ckpt/scillm-emotional-sft/18\
# --port 23333
This script runs the Mozi model emotional model on 23333
port and the input POST
request should be like:
{
"decoding_method": "greedy",
"top_p": 0.7,
"top_k": 10,
"penalty_alpha": 0.5,
"max_new_tokens": 128,
"history": [
"Human: ๆ่ฟ็ง็ ๅๅ็็ๅฅฝๅคงๅ"
]
}
If you want to test the paper-ground dialog model, please replace the --delta_model_path
with the corresponding model checkpoints weights that you download.
For the paper-ground dialog, the input POST
request should be like:
{
"decoding_method": "greedy",
"top_p": 0.7,
"top_k": 10,
"penalty_alpha": 0.5,
"max_new_tokens": 128,
"evidences": [
"During the first two decades of the 21st century, the sharing and processing of vast amounts of data has become pervasive ...",
"One way of circumventing this problem is to anonymise the data by removing, ...",
"Given that this paper is concerned with text documents (e.g. medical records), the involved techniques are related to Natural Language Processing (NLP) ..."
],
"question": "Which dataset do the author use in this paper?"
}
[Back to Top]
3. Train SciDPR model for Mozi Model:SciDPR servers the evidence retrieval component for Mozi paper-ground question answering models, which retrieves related evidences of user's queries. For model details about SciDPR model, please refer to this README.md file.
[Back to Top]
4. Train Your Own Mozi Model:Prerequisites: Before training the model, making sure the environment is properly installed and the checkpoints of LLaMA-7B and Baichuan-7B are downloaded.
[Back to Top]
4.1. Data Preparation:Declaimer: To ensure the reproducibility of our results, we have released our training dataset. The dataset must be used for research purpose only. The use of the dataset must comply with the licenses from original sources, i.e. QASPER and SciMRC. These datasets may be taken down when requested by the original authors.
Training Task | Dataset Address |
---|---|
Scientific Pre-training | Redpajama Dataset |
Paper-ground Dataset QASPER | QASPER-v0.3 dataset |
Paper-ground Dataset SciMRC | SciMRC dataset |
Emotional Dataset | scientific-emotional-dialog |
Due to the limited computation resources, we only collect 4B tokens from Redpajama arXiv corpus for the first version of scientific pre-training, and the downloading scripts could be found in this scripts.
After downloading, put the downloaded file and unzip them under the ./data/ directory, and the directory should look like:
.
โโโ pretrain
โย ย โโโ download_from_hf.py
โย ย โโโ test
โย ย โย ย โโโ collect.py
โย ย โโโ train
โย ย โโโ combine_chinese_corpus.sh
โย ย โโโ split.sh
โโโ sft
โโโ alpaca
โย ย โโโ alpaca_data.json
โโโ combine.py
โโโ dolly
โย ย โโโ download_from_hf.py
โย ย โโโ train.json
โโโ emotional
โย ย โโโ train.json
โโโ processed_qasper_test_set.json
โโโ processed_scimrc_test_set.json
โโโ qasper
โย ย โโโ README-test.md
โย ย โโโ README.md
โย ย โโโ collect.py
โย ย โโโ qasper-dev-v0.3.json
โย ย โโโ qasper-test-and-evaluator-v0.3.tgz
โย ย โโโ qasper-test-v0.3.json
โย ย โโโ qasper-train-dev-v0.3.tgz
โย ย โโโ qasper-train-v0.3.json
โย ย โโโ qasper_dev_sft.json
โย ย โโโ qasper_evaluator.py
โย ย โโโ qasper_sft.json
โย ย โโโ qasper_test_sft.json
โย ย โโโ qasper_train_sft.json
โย ย โโโ qasper_yes_no_test_sft.json
โย ย โโโ qasper_yes_no_train_sft.json
โย ย โโโ scillm_test.json
โโโ scimrc
โย ย โโโ collect.py
โย ย โโโ scimrc_dev_sft.json
โย ย โโโ scimrc_test_sft.json
โย ย โโโ scimrc_train_sft.json
โย ย โโโ scimrc_yes_no_test_sft.json
โย ย โโโ scimrc_yes_no_train_sft.json
โย ย โโโ smrc_dev.jsonl
โย ย โโโ smrc_test.jsonl
โย ย โโโ smrc_train.jsonl
โโโ train.json
After downloading these datasets and saving them at the proper path, please refer to Dataset Prepareing Tutorial for preprocessing these for corpus for following training.
[Back to Top]
4.2 Training Configurations:To train the model properly, we use the QLoRA and deepspeed toolkit. Before running, please make sure these essential toolkit are downloaded.
The configurations about training are shown as follows:
Models | Model Name | Training Configurations |
---|---|---|
Scientific Pretraining | scillm | scillm-train; scillm-deepspeed |
Paper-ground SFT | scillm-sft | scillm-sft-train; scillm-deepspeed |
Paper-ground SFT | scillm-sft | scillm-sft-train; scillm-deepspeed |
Please refer to these configuration file for more training details. Note that these models are pre-trained on 8 x 3090 (24G) GPUs for over 9 days (over 4B tokens). As for paper-ground question answering SFT, the training process cost less than 3 hours (with 2000 steps).
[Back to Top]
4.3. Training Mozi Models:[Back to Top]
4.3.1. Scientific Pre-training Mozi Models:To pre-train Mozi on scientific pre-training corpus with 4B tokens, please run the following commands:
./scripts/train_pretrain.sh
The key arguments of the training script are as follows:
--model
: The model name listed inconfig/base.json
.--model_path
: The checkpoint for large-scale langauge models,baichuan-inc/baichuan-7B
for baichuan-7B model anddecapoda-research/llama-7b-hf
for LLaMA-7B.--train_data_path
: The path saves the pretraining corpus.--log_path
: The directory that saves the pre-trained log in tensorboard format. This directory will be automatically created.--save_path
: The directory which saves the trained QLoRA delta weights. This directory will be automatically created.
Note that the total training steps can be set in the total_step
argument at ./config/base.yaml file. Set this argument carefully to make sure all the tokens will be used during training.
[Back to Top]
4.3.2. Supversied Fine-tuning Mozi Models:Furthermore, to supervised fine-tune Mozi models on paper-ground question answering corpus, first make sure the dataset
is set as QASPERDataset
, and then please run the following commands:
./scripts/train_sft.sh
The key arguments of the training script are as follows:
--model
: The model name listed inconfig/base.json
.--model_path
: The checkpoint for large-scale langauge models,baichuan-inc/baichuan-7B
for baichuan-7B model anddecapoda-research/llama-7b-hf
for LLaMA-7B.--delta_model_path
: The LoRA checkpoint weighted pre-traing in Section 3.3.1. The SFT process will continue optimize these LoRA weights for paper-ground question answering task.--train_data_path
: The path saves the pretraining corpus.--log_path
: The directory that saves the pre-trained log in tensorboard format. This directory will be automatically created.--save_path
: The directory which saves the trained QLoRA delta weights. This directory will be automatically created.
Note that the total training steps can be set in the total_step
argument at ./config/base.yaml file. Set this argument carefully to make sure all the tokens will be used during training (2000 steps is enough in our hardware settings).
If you want to train the emotional dialog task, just simply replace the dataset with the path of emotional dataset path,and make sure the dataset_name
in config/bash.yaml
should also be set as EmotionalDataset
.
Citation:
If you found Mozi models useful in your research or applications, please kindly cite using the following BibTeX:
...
Technical Report:
You can refer to our technical report for more details, which is saved in this path.
Acknowledgments:
This repo benefits from OpenAlpaca, PandaGPT. Thanks for their wonderful works!