• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A large-scale language model for scientific domain, trained on redpajama arXiv split

Mozi: A Scientific Large-scale Language Model

Code License Python 3.8+

ๅขจๅญ

Team of Beijing Institute of Technology: Tian Lan*, Tianyi Che*, Zewen Chi, Xuhao Hu and Xian-ling Mao


Catalogue:


1. Introduction: [Back to Top]

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.


2. Running Mozi Models: [Back to Top]

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.

  1. First of all, please download LLaMA-7B checkpoint and Baichuan-7B checkpoint.

  2. 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
  3. 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?"
}

3. Train SciDPR model for Mozi Model: [Back to Top]

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.


4. Train Your Own Mozi Model: [Back to Top]

Prerequisites: Before training the model, making sure the environment is properly installed and the checkpoints of LLaMA-7B and Baichuan-7B are downloaded.

4.1. Data Preparation: [Back to Top]

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.

4.2 Training Configurations: [Back to Top]

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).

4.3. Training Mozi Models: [Back to Top]

4.3.1. Scientific Pre-training Mozi Models: [Back to Top]

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 in config/base.json.
  • --model_path: The checkpoint for large-scale langauge models, baichuan-inc/baichuan-7B for baichuan-7B model and decapoda-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.

4.3.2. Supversied Fine-tuning Mozi Models: [Back to Top]

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 in config/base.json.
  • --model_path: The checkpoint for large-scale langauge models, baichuan-inc/baichuan-7B for baichuan-7B model and decapoda-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!

More Repositories

1

Copyisallyouneed

[ICLR 2023] Codebase for Copy-Generator model, including an implementation of kNN-LM
Python
182
star
2

MultiTurnDialogZoo

Multi-turn dialogue baselines written in PyTorch
Python
162
star
3

OpenDialog

An Open-Source Package for Chinese Open-domain Conversational Chatbot (ไธญๆ–‡้—ฒ่Šๅฏน่ฏ็ณป็ปŸ๏ผŒไธ€้”ฎ้ƒจ็ฝฒๅพฎไฟก้—ฒ่Šๆœบๅ™จไบบ)
Python
108
star
4

SimpleReDial-v1

The sources codes of the DR-BERT model and baselines
Python
38
star
5

RUBER-and-Bert-RUBER

Implementation of RUBER: An Unsupervised Method for Automatic Evaluation of Open-Domain Dialog Systems
Python
29
star
6

Rep-Dropout

[NeurIPS 2023] Repetition In Repetition Out: Towards Understanding Neural Text Degeneration from the Data Perspective
Python
27
star
7

MomentumDecoding

Momentum Decoding: Open-ended Text Generation as Graph Exploration
Python
19
star
8

EDA-NLP-Chinese

Easy Data Augmentation for NLP on Chinese
Python
16
star
9

PONE

Jupyter Notebook
13
star
10

GPT2Dialog

English or Chinses GPT2Dialog model from GPT2-chitchat
Python
11
star
11

Study

Good good study, day day ugly
Jupyter Notebook
10
star
12

Primary_Explainable_Factual_Consistency_Evaluation_Model

The simple demo of explainable factual consistency evaluation model, optimzing InternLM-7B by QLoRA
Python
10
star
13

WhenToSpeak

The codes of our paper When to Talk: Chatbot Controls the Timing of Talking during Multi-turn Open-domain Dialogue Generation
Jupyter Notebook
9
star
14

BIT-PSO

PSO Algorithm for solving the JSP problem
Python
6
star
15

Transformer-Dialog

PyTorch Transformer Dialogue Model
Python
6
star
16

EasyNLP

Python
5
star
17

EvidenceRetrievalLeaderboard

The leaderboard for evidence retrieval task
5
star
18

General-Zero

The AlphaZero for the WTN-EinStein Chess
Python
5
star
19

FeedbackPreference

This is the repo for our proposed Feedback Preference corpus
Python
4
star
20

SurveyFactory

All the survey I made, save the idea, help the newbie, review for myself
4
star
21

DeepLearning-Course

DeepLearning Course (RL, RNN, CNN, TextGen)
Jupyter Notebook
3
star
22

BITNLP

NLP project
Python
2
star
23

housechat

https://www.datafountain.cn/competitions/474
Python
2
star
24

CCompilerInPython

The Simple C Compiler in Python
HTML
2
star
25

HashRetrieval

Learning to Hash for Coarse Retrieval in Open-Domain Dialog Systems
Python
1
star
26

DataHammer-Training-Room

Machine Learning Practice for students get in touch with Group DataHammer
Shell
1
star
27

Paper-shredder

Paper, paper, and paper
Python
1
star
28

ubuntu-v2

Jupyter Notebook
1
star