This is the result of the weight difference between
Llama 13B
and
ZhiXi-13B
. You can click
here
to learn more.
Knowledgable Large Language Model Framework.
With the rapid development of deep learning technology, large language models such as ChatGPT have made substantial strides in the realm of natural language processing. However, these expansive models still encounter several challenges in acquiring and comprehending knowledge, including the difficulty of updating knowledge and potential knowledge discrepancies and biases, collectively known as knowledge fallacies. The KnowLM project endeavors to tackle these issues by launching an open-source large-scale knowledgable language model framework and releasing corresponding models.
The project's
initial phase
introduced a knowledge extraction LLM based on LLaMA, dubbed
ZhiXi
(
智析
, which means intelligent analysis of data for knowledge extraction). To integrate the capacity of Chinese understanding into the language models without compromising their inherent knowledge, we firstly
(1) use Chinese corpora for the full-scale pre-training with LLaMA (13B), augment the language model's understanding of Chinese and improve its knowledge richness while retaining its original English and code capacities;
Then
(2) we fine-tune the model obtained from the first step with an instruction dataset, thus bolstering the language model's understanding of human instructions for knowledge extraction.
❗Please note that this project is still undergoing optimization, and the model weights will be regularly updated to support new features and models!
The features of this project are as follows:
Centered on knowledge and large models, a
full-scale pre-training
of the large model, such as LLaMA, is conducted using the built Chinese&English pre-training corpus.
Based on the technology of
KG2Instructions
, the knowledge extraction tasks, including NER, RE, and IE, are optimized and can be completed using human instructions.
Using the built Chinese instruction dataset (approximately 1400K), LoRA fine-tuning is used to enhance the model's understanding of human instructions.
The weights of the pre-training model and LoRA's instruction fine-tuning are open-sourced.
The
full-scale pre-training code
(providing conversion, construction, and loading of large corpora) and
LoRA instruction fine-tuning code
are open-sourced (support multi-machine multi-GPU).
All weights have been uploaded to HuggingFace🤗. It should be noted that all the following effects are based on
ZhiXi-13B-Diff
. If you have downloaded
ZhiXi-13B-Diff-fp16
, there may be some variations in the effects.
The main difference with
ZhiXi-13B-Diff
is the adoption of the
fp16
format for storage, which reduces memory usage. However, it may result in slight differences in the weights obtained from our actual training, which can slightly impact performance. For specific usage instructions, please refer to
here
for specific instructions.
It needs to be used with
ZhiXi-13B
. For specific instructions, please refer to
here
.
ZhiXi-7B Series
Coming soon
Coming soon
Coming soon
Coming soon
Coming soon
NEWS
[
June 2023
] The project name has been changed from CaMA to KnowLM.
[
June 2023
] Release the first version of pre-trained weights and the LoRA weights.
Why it's called ZhiXi (智析)?
In Chinese, "Zhi" (智) signifies intelligence, referencing the AI's advanced language understanding capabilities. "Xi" (析) means to analyze or extract, symbolizing the system's knowledge extraction feature. Together, ZhiXi (智析) epitomizes an intelligent system adept at dissecting and garnering knowledge - characteristics that align with our expectations of a highly knowledgeable model.
Our pre-trained model has demonstrated certain abilities in instruction following, coding, reasoning, as well as some translation capabilities, without any fine-tuning using instructions. Additionally, it has acquired new knowledge. Below are some of our sample cases. If you wish to reproduce our examples and view detailed decoding configuration, please first
set up the environment
and
restore the weights
, then follow the steps outlined
here
.
In the follwing cases, text in
bold
represents the prompt, while non-bold text represents the model's output.
Due to the maximum inference length set to 512, our cases fall into three situations:
Compeleted output. The model generates the termination token EOS and completes the output. We mark this with :white_check_mark:.
Incomplete output. The output is cut off due to the maximum inference length. We mark this with :eight_spoked_asterisk:.
Repeated output. We remove repeated content manually and mark it with :arrow_left:.
Translation
你很擅长将中文翻译成英文。将下面的句子翻译成英文:我们今天准备去西安看兵马俑。答案:
We are going to see the Terracotta Warriors in Xi'an today.:white_check_mark:
You are good at translating English into Chinese. Translate the following sentence into Chinese: Nothing is difficult to a willing heart. Answer:
什么都不难,只要心甘情愿。:white_check_mark:
Can you help me write a formal email to a potential business partner proposing a joint venture? Your answer:
A:
Dear Sir/Madam,
I am writing to propose a joint venture between our two companies. I have attached a proposal for your consideration. Please let me know if you would like to discuss this further.
Yours sincerely,:white_check_mark:
You are now a doctor. Here are some tips for a healthy life. 1.
Don't smoke. 2. Eat a balanced diet. 3. Exercise regularly. 4. Drink alcohol only in moderation. 5. Take care of your teeth. 6. Get enough sleep. 7. See your doctor for regular checkups. 8. Learn to manage stress. 9. Stay up-to-date on vaccinations. 10. Wash your hands often. 11. Avoid secondhand smoke. 12. Use sunscreen and wear sunglasses. 13. Know your family medical history. 14. Be aware of the signs of depression. 15. Protect your hearing. 16. Practice safe sex. 17. If you drink coffee, do so in moderation. 18. Limit your intake of caffeine. 19. Don't drive when you're tired. 20. Don't text and drive. 21. Don't drink and drive. 22. Don't ride a motorcycle without a helmet. 23. Don't swim alone. 24. Don't dive into water where you can't see the bottom. 25. Don't swim if you've been drinking alcohol. 26. Don't swim if you're sick. 27. Don't swim if you have open sores on your body. 28. Don't swim if there are strong currents or undertows. 29. Don't swim in polluted water. 30. Don't swim if there are snakes or alligators nearby. 31. Don't swim if there are jellyfish in the water. 32. Don't swim if there are sharks in the water. 33. Don't swim if there are riptides in the water. 34. Don't:eight_spoked_asterisk:
Coding
using java to sort an unsorted array. Answer:
O(nlogn)
@param arr
@return
/**
* using java to sort an unsorted array. Answer: O(nlogn)
*
* @param arr
* @return
*/
public static <T extends Comparable<T>> void sort(T[] arr) {
if (arr == null || arr.length == 0) {
return;
}
int n = arr.length;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j].compareTo(arr[j + 1]) > 0) {
T tmp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = tmp;
}
}
}
}:white_check_mark:
use python to write the bubble sort algorithm.
def bubble_sort(arr):
"""Bubble sort algorithm.
""" for i in range(len(arr) - 1, 0, -1):
for j in range(len(arr) - 1, 0, -1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr:white_check_mark:
Here is the recommendation letter that I wrote for an application to a dragon feeder position at the Magic Unicorn Corporation:
Dear recruiter
,
I am writing this letter of recommendation on behalf of my student, who is applying for a position as a dragon feeder at the Magic Unicorn Corporation. I have had the pleasure of teaching this student for the past three years, and I can say without hesitation that he is one of the best students I have ever had. He is hard-working, diligent, and intelligent. He is also a very good dragon feeder. In fact, he is the best dragon feeder I have ever had in my class. He has fed many dragons over the years, and they have all been very pleased with his work. I would not hesitate to recommend him for a position as a dragon feeder at the Magic Unicorn Corporation.
Thank you for your consideration.
Sincerely,
Professor Snape
P.S. Please don't tell anyone that I wrote this letter. I don't want to get into any trouble with the Ministry of Magic.
# Chapter 1
# THE MAGIC UNICORN CORPORATION
The Magic Unicorn Corporation (MUC) is a large multinational corporation headquartered in New York City. The company was founded in 1980 by a group of unicorns who wanted to start their own business. They were tired of working for other unicorns and decided to strike out on their own. Their first product was a line of unicorn-themed greeting cards. The cards were a huge success, and the company grew rapidly. By 1985, the company had expanded its product line to include unicorn-themed T-shirts, coffee mugs, and stuffed animals. In 1987, the company went public. Since then, the Magic Unicorn Corporation has become one of the most successful companies in the world.
The Magic Unicorn Corporation employs thousands of people around the world. Most of the employees are unicorns, but the company also employs a small number of humans. Humans are hired to do jobs that unicorns cannot or will not do. For example, humans are hired to clean up after unicorns. Humans are also hired to feed the unicorns:eight_spoked_asterisk:
You are very familiar with the information of Chinese cities, such as the attractions, cuisine, and history of Chinese cities. Please introduce the city of Hangzhou. Hangzhou
is the capital of Zhejiang Province in eastern China. It is located at the southern end of the Yangtze River Delta in southeastern China. It is one of the most famous tourist cities in China. It is also known as the "City of Silk", "City of Tea", "City of Flowers" and "City of Lakes". It has a population of 6.5 million people. It is the political, economic, cultural and transportation center of Zhejiang Province. It is also an important industrial base in China. In addition, Hangzhou is also a famous historical and cultural city in China. There are many well-known scenic spots in Hangzhou, such as West Lake, Lingyin Temple, Leifeng Pagoda, Bao'an Temple, Six Harmonies Pagoda, Peak Flying Clouds, etc. Hangzhou is also known for its delicious cuisine. Hangzhou cuisine is one of the eight major cuisines in China. It is characterized by fresh, sweet, sour, salty, and mellow. Hangzhou cuisine is mainly influenced by the local climate and geographical environment. The main ingredients used in Hangzhou cuisine are freshwater fish, shrimp, crab, pork, chicken, duck, beef, vegetables, and fruits. Hangzhou cuisine is divided into three categories: Hangzhou traditional cuisine, Hangzhou new cuisine, and Hangzhou snacks. Hangzhou traditional cuisine is mainly based on Hangzhou's long history and culture. Hangzhou new cuisine is mainly based on Hangzhou's geographical environment. Hangzhou snacks are mainly based on Hangzhou's local customs and habits. Hangzhou cuisine is rich in color, fragrance, taste, and nutrition. Hangzhou cuisine can be divided into two categories: Hangzhou traditional cuisine and Hangzhou new cuisine. Hangzhou traditional cuisine is mainly based on Hangzhou's long:eight_spoked_asterisk:
Reasoning
Question: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now?
Answer: Roger started with 5 balls. 2 cans of 3 each is 6 tennis balls. 5 + 6 = 11. The answer is 11.
Question: The cafeteria had 23 apples. lf they used 20 to make lunch and bought 6 more, how many apples do they have?
Answer: Cafeteria started with 23 apples.
20 apples were used to make lunch. 6 more apples were bought. 23 - 20 = 3. 3 + 6 = 9. The answer is 9.
Question: If you have 4 marbles and I have 3 marbles, how many marbles do we have together?
Answer: 4 + 3 = 7. The answer is 7.:arrow_left:
1.2 Information Extraction Cases
The effectiveness of information extraction is illustrated in the following figure. We tested different instructions for different tasks as well as the same instructions for the same task, and achieved good results for all of them.
Compared to other large models like ChatGPT, as shown in the graph, it can be observed that our model achieves more accurate and comprehensive extraction results. However, we have also identified some extraction errors in ZhiXi. In the future, we will continue to enhance the model's semantic understanding capabilities in both Chinese and English and introduce more high-quality instruction data to improve the model's performance.
1.3 General Ablities Cases
We have selected 8 cases to validate the model's harmlessness, translation ability, comprehension, code capability, knowledge, creative ability, bilingual ability, and reasoning ability.
Dear Hotel Staff,
I am writing to inquire about the possibility of upgrading my reservation to a sea-view room. I have booked a standard room for my upcoming stay, but I would greatly appreciate the opportunity to enjoy the breathtaking views of the ocean from my room.
I understand that sea-view rooms may be more expensive than standard rooms, but I am willing to pay the additional cost if it is possible to upgrade my reservation.
Thank you for considering my request and I look forward to hearing back from you.
Sincerely,
[Your Name]
2.2 Pretraining model weight acquisition and restoration
❗❗❗ Note that in terms of hardware, performing step
2.2
, which involves merging LLaMA-13B with ZhiXI-13B-Diff, requires approximately
100GB
of RAM, with no demand for VRAM (this is due to the memory overhead caused by our merging strategy. For your convenience, we have provided the fp16 weights at this link:
https://huggingface.co/zjunlp/zhixi-13b-diff-fp16
.
fp16 weights require less memory but may slightly impact performance
. We will improve our merging approach in future updates, and we are currently developing a 7B model as well, so stay tuned). For step
2.4
, which involves inference using
ZhiXi
, a minimum of
26GB
of VRAM is required.
1. Download LLaMA 13B and ZhiXi-13B-Diff
Please click
here
to apply for the official pre-training weights of LLaMA from
meta
. In this case, we are using the
13B
version of the model, so you only need to download the
13B
version. Once downloaded, the file directory will be as follows:
:exclamation:Noted. If the download is interrupted, please repeat the command mentioned above. HuggingFace provides the functionality of resumable downloads, allowing you to resume the download from where it was interrupted.
2. Use the conversion script provided by huggingface
To convert the original LLaMA-13B model into the HuggingFace format, you can use the provided script file by HuggingFace, which can be found
here
. Below is the command to run the script (assuming the downloaded original files(LLaMA-13B) are located in
./
and you want the converted files to be stored in
./converted
):
The final complete ZhiXi weights are saved in the
./zhixi
folder.
If you have downloaded the diff weights version in fp16 format, you can obtain them using the following command. Please note that there might be slight differences compared to the weights obtained in fp32 format:
❗NOTE. We do not provide an MD5 for verifying the successful merge of the
ZhiXi-13B
because the weights are divided into six files. We employ the same validation strategy as
Stanford Alpaca
, which involves performing a sum check on the weights (you can refer to this
link
).
If you have successfully merged the files without any errors, it indicates that you have obtained the correct pre-trained model.
2.3 Instruction tuning LoRA weight acquisition
Use the script file we provided, located at
./tools/download.py
, execute the following command to get the LoRA weight (assuming the saved path is located at
./LoRA
):
The final complete weights are saved in the
./LoRA
folder.
2.4 Model Usage Guide
1. Reproduce the results in Section 1
The cases in
Section 1
were all run on V100. If running on other devices, the results may vary. Please run multiple times or change the decoding parameters.
If you want to reproduce the results in section
1.1
(
pretraining cases
), please run the following command (assuming that the complete pre-training weights of
ZhiXi
have been obtained according to the steps in section
2.2
, and the ZhiXi weight is saved in the
./zhixi
folder):
If you want to reproduce the results in section
1.2
(
information extraction cases
), please run the following command (assuming that the LoRA weights of
ZhiXi
have been obtained according to the steps in section
2.3
, and the LoRA weights is saved in the
./lora
folder):
If you want to reproduce the results in section
1.3
(
general ablities cases
), please run the following command (assuming that the LoRA weights of
ZhiXi
have been obtained according to the steps in section
2.3
, and the LoRA weights is saved in the
./lora
folder):
Here is a screenshot of the web-based interaction:
The
instruction
is a required parameter, while
input
is an optional parameter. For general tasks (such as the examples provided in section
1.3
), you can directly enter the input in the
instruction
field. For information extraction tasks (as shown in the example in section
1.2
), please enter the instruction in the
instruction
field and the sentence to be extracted in the
input
field. We provide an information extraction prompt in section
2.5
.
If you want to perform batch testing, please modify the
examples/generate_lora.py
file and update the examples and hyperparameters in the variable
cases
.
2.5 Information Extraction Prompt
For information extraction tasks such as named entity recognition (NER), event extraction (EE), and relation extraction (RE), we provide some prompts for ease of use. You can refer to this
link
for examples. Of course, you can also try using your own prompts.
Here is a
case
where ZhiXi-13B-LoRA is used to accomplish the instruction-based knowledge graph construction task in CCKS2023.
3. Training Details
The following figures illustrates the entire training process and dataset construction. The training process is divided into two stages:
(1) Full pre-training stage. The purpose of this stage is to enhance the model's Chinese language proficiency and knowledge base.
(2) Instruction tuning stage using LoRA. This stage enables the model to understand human instructions and generate appropriate responses.
3.1 Dataset Construction (Pretraining)
In order to enhance the model's understanding of Chinese while preserving its original code and English language capabilities, we did not expand the vocabulary. Instead, we collected Chinese corpora, English corpora, and code corpora. The Chinese corpora were sourced from Baidu Baike, Wudao, and Chinese Wikipedia. The English dataset was sampled from the original English corpus of
LLaMA
, with the exception of the Wikipedia data. The original paper's English Wikipedia data was up until August 2022, and
we additionally crawled data from September 2022 to February 2023, covering a total of six months.
As for the code dataset, due to the low-quality code in the
Pile
dataset, we crawled code data from GitHub and LeetCode. A portion of the data was used for pre-training, while another portion was used for fine-tuning with instructions.
For the crawled datasets mentioned above, we employed a heuristic approach to filter out harmful content. Additionally, we removed duplicate data.
3.2 Training Process (Pretraining)
Detailed data processing code, training code, complete training scripts, and detailed training results can be found in
./pretrain
.
Before training, we need to tokenize the data. We set the maximum length of a single sample to
1024
, while most documents are much longer than this. Therefore, we need to partition these documents.
We designed a greedy algorithm to split the documents, with the goal of ensuring that each sample consists of complete sentences and minimizing the number of segments while maximizing the length of each sample.
Additionally, due to the diversity of data sources, we developed a comprehensive data preprocessing tool that can process and merge data from various sources. Finally, considering the large amount of data, loading it directly into memory would impose excessive hardware pressure. Therefore, we referred to
DeepSpeed-Megatron
and used the
mmap
method to process and load the data. This involves loading the indices into memory and accessing the corresponding data on disk when needed.
Finally, we performed pre-training on 5.5 million Chinese samples, 1.5 million English samples, and 0.9 million code samples. We utilized the transformers'
Trainer
in conjunction with Deepspeed ZeRO3 (it was observed that strategy ZeRO2 had slower speeds in a multi-node, multi-GPU setup). The training was conducted across 3 nodes, with each node equipped with 8 32GB V100 GPUs. The table below showcases our training speeds:
Parameter
Values
micro batch size
20
gradient accumulation
3
global batch size
20*3*24=1440
Time-consuming of a step
260s
3.3 Dataset Construction (Instruction tuning)
In addition to incorporating general capabilities such as reasoning and coding, we have also introduced additional information extraction abilities, including NER (Named Entity Recognition), IE (Information Extraction), and EE (Event Extraction), into the current homogeneous models. It is important to note that many open-source datasets such as the
alpaca dataset
CoT dataset
and
code dataset
are in English. To obtain the corresponding Chinese datasets, we utilized
GPT-4
for translation purposes. There were two approaches used: 1) direct translation of questions and answers into Chinese, and 2) inputting English questions to
GPT-4
and generating Chinese responses. The second approach was employed for general datasets, while the first approach was utilized for datasets like the
CoT dataset
and
code dataset
. These datasets are readily available online.
For information extraction datasets, we used open-source datasets such as
CoNLL
,
ACE
,
CASIS
, and others to construct corresponding English instructions for generating the required training format. For the Chinese part, for NER and EE tasks, we utilized open-source datasets such as
DualEE
,
PEOPLE DAILY
, and others, and then created corresponding Chinese instructions to synthesize the required training format. As for the RE task, we built a dataset called
KG2Instruction
. Specifically, we used Chinese Wikipedia data and BERT for Chinese entity recognition. We then aligned the recognized entities with the Wikipedia index. Due to potential ambiguity (i.e., a Chinese entity may have multiple indexes, such as
apple
referring to both a fruit and a company), we devised a strategy to disambiguate the entities. Subsequently, we used a distantly supervised method to generate possible triplets and applied predefined rules to filter out illegal or incorrect triplets. Finally, with the help of crowdsourcing, we refined the obtained triplets. Following that, we constructed corresponding Chinese instructions to generate the required training format.
In addition, we manually constructed a general Chinese dataset and translated it into English using the second approach. Finally, our data distribution is as follows:
Dataset
Number
COT Datasets (Chinese, English)
202333
General Datasets (Chinese, English)
105216
Code Datasets (Chinese, English)
44688
Information Extraction Datasets (English)
537429
Information Extraction Datasets (Chinese)
486768
Flow diagram of KG2Instruction and other instruction fine-tuning datasets
3.4 Training Process (Instruction tuning)
Currently, most instruction tuning scripts using LoRA are based on
alpaca-lora
, so we will not go into detail here. Detailed instruction tuning parameters and training scripts can be found in
./finetune/lora
.
4. Limitations
Due to time constraints, hardware limitations, and technical reasons, our model has limitations, including but not limited to:
Our intruction tuning process does not involve full tuning. Instead, we use the LoRA approach for instruction tuning.
Our model does not currently support multi-turn conversations.
While we strive to ensure the usefulness, reasonableness, and harmlessness of the model's outputs, toxic outputs may still occur in some scenarios.
The pretraining is not exhaustive. We have prepared a large amount of pretraining data, but it has not been fully trained.
······
5. TODO List
Instruction tuning using full tuning instead of LoRA version is being trained and will be released soon.
New instruction tuning weights using LoRA will be updated shortly.
New models (Llama-7b, Falcon-7b) are being trained (We have limited GPUs!).
New abilities such as molecule and protein generation with
Mol-Instructions
, a large-scale biomolecules instruction dataset for large language models.
supporting llama.cpp
......
6. FAQ
Question: What should I do if the model encounters � during decoding?
Answer: If this symbol appears in the middle of the decoded sentence, we recommend changing the input. If it occurs at the end of the sentence, increasing the output length can resolve the issue.
Question: Why do I get different results with the same decoding parameters?
Answer: It is possible that you have enabled
do_sample=True
. It could also be due to the order of execution. You can try using a for loop to output multiple times with the same decoding parameters and observe that each output is different.
Question: Why is the extraction or answer quality not good?
Answer: Please try changing the decoding parameters.
zhixi-13b-diff huggingface.co is an AI model on huggingface.co that provides zhixi-13b-diff's model effect (), which can be used instantly with this zjunlp zhixi-13b-diff model. huggingface.co supports a free trial of the zhixi-13b-diff model, and also provides paid use of the zhixi-13b-diff. Support call zhixi-13b-diff model through api, including Node.js, Python, http.
zhixi-13b-diff huggingface.co is an online trial and call api platform, which integrates zhixi-13b-diff's modeling effects, including api services, and provides a free online trial of zhixi-13b-diff, you can try zhixi-13b-diff online for free by clicking the link below.
zjunlp zhixi-13b-diff online free url in huggingface.co:
zhixi-13b-diff is an open source model from GitHub that offers a free installation service, and any user can find zhixi-13b-diff on GitHub to install. At the same time, huggingface.co provides the effect of zhixi-13b-diff install, users can directly use zhixi-13b-diff installed effect in huggingface.co for debugging and trial. It also supports api for free installation.