Home

Awesome

LingLong (玲珑): A Small-Scale Chinese PreTrained Language Model

version 1.0.3 Python >=3.11,<3.12 PyTorch 2.3 TensorFlow 2.16 License GNU GPL v3

This is LingLong (玲珑), a Chinese pretrained language model trained by the College of Software at Nankai University. Built on the foundation of the GPT-3 architecture, it has been meticulously trained on a vast collection of private datasets. With a modest parameter count of only 317 million, LingLong is significantly smaller than the original GPT-3 model, yet it delivers impressive results across various NLP tasks. In Chinese, "玲珑" translates to "exquisite" or "delicate," which perfectly embodies the small yet mighty nature of this model. Therefore, we chose to name it "LingLong" in honor of its exceptional precision and finesse.

Although it's true that this model's performance isn't on par with the large pretrained language models boasting hundreds of billions of parameters, its relatively low parameter count makes it accessible to researchers with limited computing resources. As a result, this model serves as an excellent foundation for conducting follow-up research, such as fine-tuning. By utilizing this model, researchers can begin to delve into the intricacies of pretrained language models and to unravel the mysteries of language processing without the need for excessive computational resources.

Hardware Requirements

The following hardware is recommended for training:

The following hardware is recommended for inference:

The model can also run on CPUs, but the training and inference speed will be significantly slower.

Python Requirements

This package requires Python 3.11 or later.

Environment Setup

The required packages are not listed in setup.py yet, so you need to install them manually.

  1. Clone the repository.

    git clone https://github.com/nkcs-iclab/linglong.git
    cd linglong
    
  2. Create new conda environment with environment.yaml.

    conda env create -f environment.yaml
    conda activate linglong
    
  3. Install the required packages. Be sure to install PyTorch first. You have to edit the requirements-torch.txt and requirements.txt file to match your CUDA version. The default version is 12.1.

    pip install -r requirements-torch.txt
    pip install -r requirements.txt
    

    Optional: If you want to perform evaluation on public datasets, you need to install the evaluation dependencies.

    pip install -r requirements-evaluation.txt
    
  4. Install the package.

    pip install -e .
    
  5. Install DeepSpeed (optional, for DeepSpeed enabled training).

    pip install ninja deepspeed
    

    After installation, you can validate your installation and see which ops your machine is compatible with via the DeepSpeed environment report with ds_report or python -m deepspeed.env_report.

A Quick Guide to Text Generation

We provide an interactive text generation script generation/generate.py for generating text from a trained model.

python generate.py --model=/path/to/linglong/model

There is also a script generation/api-example.py demonstrating how to use the generation API.

More usage details can be found using the --help flag.

You can also use the Transformers pipeline to generate text.

from transformers import pipeline

pipe = pipeline(
    'text-generation',
    model='/path/to/linglong/model',
    device='cuda',
    trust_remote_code=True,
)
generated_text = pipe('你好')[0]['generated_text']

Pretrained Models

Latest Models

Model NameParametersSizeDownload
LingLong-317M317 M1.27 GBhttps://huggingface.co/AlumiK/LingLong-317M
LingLong-317M-Chat317 M1.27 GBhttps://huggingface.co/AlumiK/LingLong-317M-Chat

Legacy Models

You have to convert these legacy models to the latest format before using them with the current version of the codebase. A conversion script is provided at utils/torch2transformers.sh.

Model NameParametersSizeDownload
LingLong317 M1.2 GBOneDrive
LingLong-Backward317 M1.2 GBOneDrive
LingLong-Pinyin318 M1.2 GBOneDrive
LingLong-Small106 M367 MBOneDrive
LingLong-Small-Word106 M404 MBOneDrive

Changelog

1.0

0.10

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2