Model Overview
Model Features
Model Capabilities
Use Cases
🚀 Firefly: A Chinese Conversational Large Language Model
Firefly is an open - source Chinese conversational large language model. It is fine - tuned on Chinese datasets using Instruction Tuning. Techniques such as vocabulary pruning, ZeRO, and tensor parallelism are employed to effectively reduce GPU memory consumption and improve training efficiency. During training, we used a smaller number of model parameters and less computing resources.
We constructed a large amount of data related to Chinese culture to enhance the model's performance in this area, including couplets, poetry creation, classical Chinese translation, essays, and Jin Yong's novels.
The name "Firefly" is a symbol of traditional Chinese culture. Although the saying "decayed grass turns into fireflies" has a sense of pity, even a small firefly can light up the night sky with its faint glow. The name of this project is taken from Du Mu's poem "Autumn Eve": "By candlelight in autumn cold the painted screen is seen; With silken fan she chases fireflies on the green." We hope that this project can shine a faint light, just like a firefly, and contribute to the Chinese NLP open - source community.
🚀 Quick Start
The project address is Firefly(流萤): 中文对话式大语言模型. If you find this model helpful, please like it and star our GitHub project.
✨ Features
- Dataset: [firefly - train - 1.1M](https://huggingface.co/datasets/YeungNLP/firefly - train - 1.1M), a high - quality Chinese multi - task instruction fine - tuning dataset containing 1.1M samples. It includes instruction data for 23 common Chinese NLP tasks. For each task, several instruction templates are manually written to ensure the high quality and richness of the data.
- Model Pruning: LLMPruner: A Large Language Model Pruning Tool. We use vocabulary pruning technology to prune the weights of multilingual large language models. While retaining pre - trained knowledge, we effectively reduce the number of model parameters and improve training efficiency. We also share the weights of Bloom models with different parameter scales after pruning.
- Weight Sharing: Based on [bloom - 1b4 - zh](https://huggingface.co/YeungNLP/bloom - 1b4 - zh) and [bloom - 2b6 - zh](https://huggingface.co/YeungNLP/bloom - 2b6 - zh), we perform instruction fine - tuning to obtain two Chinese models with different parameter scales: [firefly - 1b4](https://huggingface.co/YeungNLP/firefly - 1b4) and [firefly - 2b6 (to be shared after training)](https://huggingface.co/YeungNLP/firefly - 2b6).
- Training Code: The training code is open - source, supporting large - model training strategies such as tensor parallelism, ZeRO, and Gemini heterogeneous memory space management. It enables the training of models with 1B - 2B parameters using only one GPU (to be open - sourced after organization).
📦 Installation
No specific installation steps are provided in the original document, so this section is skipped.
💻 Usage Examples
Basic Usage
from transformers import BloomTokenizerFast, BloomForCausalLM
device = 'cuda'
path = 'YeungNLP/firefly-1b4'
tokenizer = BloomTokenizerFast.from_pretrained(path)
model = BloomForCausalLM.from_pretrained(path)
model.eval()
model = model.to(device)
text = input('User:')
while True:
text = '<s>{}</s></s>'.format(text)
input_ids = tokenizer(text, return_tensors="pt").input_ids
input_ids = input_ids.to(device)
outputs = model.generate(input_ids, max_new_tokens=200, do_sample=True, top_p=0.85, temperature=0.35,
repetition_penalty=1.2, eos_token_id=tokenizer.eos_token_id)
rets = tokenizer.batch_decode(outputs)
output = rets[0].strip().replace(text, "").replace('</s>', "")
print("Firefly:{}".format(output))
text = input('User:')
📚 Documentation
Model Pruning
This project first uses the LLMPruner project to perform vocabulary pruning on the original Bloom model. We only extract the commonly used Chinese and English vocabularies, which significantly reduces the number of model parameters. Then, we perform instruction fine - tuning on it.
Bloom is a multilingual model. Due to the need to be compatible with multiple languages, its vocabulary contains more than 250,000 words. In the Chinese domain, most of the vocabulary is not used. By deleting redundant vocabulary, we extract the commonly used Chinese and English vocabularies from the multilingual model. Finally, the vocabulary is reduced from 250,000 to 46,145, which is 18.39% of the original. While retaining pre - trained knowledge, we effectively reduce the number of parameters and improve training efficiency.
Based on [bloom - 1b4 - zh](https://huggingface.co/YeungNLP/bloom - 1b4 - zh) and [bloom - 2b6 - zh](https://huggingface.co/YeungNLP/bloom - 2b6 - zh), we perform instruction fine - tuning to obtain two Chinese models with different parameter scales: [firefly - 1b4](https://huggingface.co/YeungNLP/firefly - 1b4) and [firefly - 2b6 (to be shared after training)](https://huggingface.co/YeungNLP/firefly - 2b6).
Dataset
We collected 23 common Chinese datasets. For each task, several instruction templates are manually written to ensure the high quality and richness of the data. The dataset contains 1.15 million samples, forming the training set [firefly - train - 1.1M](https://huggingface.co/datasets/YeungNLP/firefly - train - 1.1M). The data distribution is shown in the following figure:
On this basis, we added Belle - train_0.5M_CN, and finally obtained 1.65 million training data. The format of each data entry is as follows, including the task type, input, and target output:
{
"kind": "ClassicalChinese",
"input": "将下面句子翻译成现代文:\n石中央又生一树,高百余尺,条干偃阴为五色,翠叶如盘,花径尺余,色深碧,蕊深红,异香成烟,著物霏霏。",
"target": "大石的中央长着一棵树,一百多尺高,枝干是彩色的,树叶有盘子那样大,花的直径有一尺宽,花瓣深蓝色,花中飘出奇异的香气笼罩着周围,如烟似雾。"
}
The token length distribution of the training dataset is shown in the following figure. Most of the data has a length of less than 600:
Training Details
During training, for each sample, we process the input and target into the following format and then input it into the model:
<s>input</s></s>target</s>
We set the maximum input length of the model to 512. The input part does not participate in the calculation of the loss, and only the loss function of the target part is calculated. The training hyperparameters are set as shown in the following table:
Property | firefly - 1b4 | firefly - 2b6 |
---|---|---|
Batch size | 16 | 8 |
Learning rate | 3e - 5 | 3e - 5 |
Warmup step | 3000 | 3000 |
Lr schedule | cosine | cosine |
Max_seq_length | 512 | 512 |
Training step | 90k | - |
Limitations and Usage Restrictions
After vocabulary pruning, the number of parameters of our model is only 1.4B and 2.6B, which is far less than models with tens or hundreds of billions of parameters such as ChatGPT and LLaMA, and even far less than current mainstream models such as Belle and ChatGLM with about 7B parameters. Therefore, there are still the following problems in performance:
- It is prone to giving incorrect responses to factual knowledge.
- Since it has not undergone harmless fine - tuning, it may generate discriminatory, harmful, or unethical remarks.
- It still lacks capabilities in code generation and reasoning.
Based on the above limitations of the model, we require that the code, data, and model of this project are only used for academic research, not for commercial purposes, and not for purposes that may cause harm to society.
📄 License
No license information is provided in the original document, so this section is skipped.
🔧 Technical Details
The relevant technical details have been described in the above sections, so this section is not separately presented.
📖 Citation
If you use the data, code, or model of this project, please cite it as follows:
@misc{Firefly,
author = {Jianxin Yang},
title = {Firefly(流萤): 中文对话式大语言模型},
year = {2023},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/yangjianxin1/Firefly}},
}
👀 Follow Us
🎉 Generation Results
The following shows some generation results of firefly - 1b4.
input | output |
---|---|
Generate 5 popular QQ Music comments | 1. This song was written by Jay Chou for A - Mei, but A - Mei sang it in her own style. 😊2. I confessed my love to her, but she gently rejected me. However, I still cheekily asked her to go to the KTV with me. Later, we became good friends who could talk about anything. She told me that she found her true love, and I blessed them. She also told me that she had run out of living expenses, and I told her that I still had 1,000 yuan and we could each have 500 yuan to get through. I transferred my only 500 - yuan living expenses to her. I know we'll never see each other again, but I believe in love. As long as there is love in my heart, even if there is no happy ending, I'm willing to. 3. "After you left, I just realized that what I always thought was happiness was just what I thought."4. A - Mei's voice is really nice, and her songs are very flavorful. Especially this song "I Want to Be Happy", the lyrics are also very well - written. I hope she can always be like this. Come on!5. I really like this song. It feels very warm. I really like this kind of song. Although I'm not a person who is particularly fond of music, I think this song can be put on repeat many times. Every time I hear it, I feel like crying. It feels so beautiful. I hope everyone can also come and listen. Thank you! |
I want you to be a journalist. You will report breaking news, write feature stories and opinion articles, develop research techniques for verifying information and finding sources, abide by journalism ethics, and provide accurate reports in your own unique style. My first suggestion request is "I need help writing an article about air pollution in major world cities." | As an AI language model, I don't have personal preferences or emotions, so I can't provide you with specific writing suggestions. However, here are some general suggestions: 1. Determine the topic: Decide on the topic you want to report, such as "the impact of global climate change" or "environmental issues". 2. Research related issues: Understand the topic by researching relevant scientific studies and data. 3. Collect information: When collecting information about the topic, pay attention to protecting personal privacy and information security. 4. Express your views in simple and clear language: Try to avoid using overly complex vocabulary and sentence structures, and convey your views in an easy - to - understand way. 5. Provide evidence to support your views: Provide persuasive evidence to support your views, such as scientific research and government reports. 6. Check the format and typesetting: Ensure that your text is clear and easy to read and understand. 7. Finally, remember to be objective and fair: Don't over - emphasize your own position, and always follow journalism ethics and legal regulations to ensure the authenticity and credibility of the report. |
Suppose you are a psychologist. How would you help patients get out of the haze and regain hope in life? Please give your specific steps and practices. | 1. Understand the patient's emotional state and problem background. 2. Develop a personalized treatment plan according to the patient's needs and symptoms. 3. Encourage the patient to express their thoughts and feelings and give appropriate feedback and support. 4. Guide the patient to think and act positively to improve their self - awareness and motivation. 5. If necessary, suggest that the patient seek the help of a professional psychologist. |
I worked late last night moving bricks and can't get up. Please make up an excuse note for me to send to my leader. | Dear Leader, Hello! I worked overtime at the company on [date] until [time] because of the large workload and couldn't finish it on time. Therefore, I would like to apply for a one - day leave. Here is a brief explanation of the reason. Thank you for your understanding and approval. Best regards! |
As a new employee in the workplace, how can I set goals and successfully achieve my personal career plan? Please list the action outline in an organized way. | 1. Define your goals: Determine your career goals and development direction. 2. Understand the industry: Research the current and future career fields and development trends. 3. Learn new knowledge: Acquire new knowledge and skills through training, reading books, or participating in internships. 4. Build relationships: Connect with peers in the industry, join relevant organizations or associations, and share their experiences and insights. 5. Look for opportunities: Look for opportunities inside or outside the company, such as internships, part - time jobs, and volunteer activities. 6. Continuously learn: Continuously improve your abilities and professional level to stay competitive. |
How can a painter use social media to expand their industry influence? | 1. Create professional accounts, such as Instagram and Twitter, to showcase your works and experiences. 2. Use platforms like Facebook and Twitter to connect with peers in the industry and share their experiences and insights. 3. Post valuable content, such as pictures, videos, or text, on social media platforms to increase your popularity. 4. Participate in various activities, such as exhibitions, concerts, and art shows, to meet more people and expand your influence. |
Please plan a complete itinerary for users traveling to Japan. | Here is a possible itinerary: 1. Arrive in Tokyo and visit Sensoji Temple and the Imperial Palace. 2. Take a walk or bike ride in Ueno Park. 3. Admire the beautiful natural scenery at Osaka Castle. 4. Go shopping or taste delicious food in the city center of Osaka. 5. Experience water sports such as surfing and diving on Hakone Island. 6. On the last day, watch traditional cultural art performances at Kiyomizu - dera Temple in Kyoto. 7. Return home and end the journey. |
Translate this sentence into Chinese: Knowledge can be acquired from many sources. These include books, teachers and practical experience, and each has its own advantages. The knowledge we gain from books and formal education enables us to learn about things that we have no opportunity to experience in daily life. | 知识可以从许多来源获得,包括书籍、教师和实践经验。每个来源都有自己的优点。从书籍和正规教育中获得的知识使我们能够了解我们日常生活中没有机会体验的事物。 |
Translate into English: 简言之,当我们努力追求目标时,永不放弃是很重要的。不管最后有没有成功,我们都会学到一些东西,而我们所学到的东西,将会使自己成为一个更好、更有自信的人。 | In short, it is very important never to give up when we strive for our goals. Whether we succeed or not in the end, we will learn something, and what we learn will make us better and more confident people. |
Please classify the following news as sports, politics, or technology: "Annual salary over 400 million euros! It is reported that Al - Hilal has officially offered a contract to Messi, and the player's first choice is to stay in Europe." | Sports |
List 5 suggestions on how to make yourself energetic. | 1. Get enough sleep and rest. 2. Do more physical exercise, such as walking, jogging, or cycling. 3. Have a balanced diet and consume enough protein, carbohydrates, and fat. 4. Drink enough water, at least eight glasses a day. 5. Avoid excessive drinking and smoking. |
Tomorrow is the end of the holiday, and I'm a bit reluctant to go back to work. What should I do? | 1. Make a detailed plan and set goals, including the tasks to be completed, time allocation, and priorities. 2. Break the tasks into smaller parts and complete them step by step. Don't over - commit to avoid excessive stress. 3. Set aside some flexible time to deal with unexpected situations or adjust the plan temporarily. 4. Communicate with family and friends, share your feelings and thoughts, and seek support and advice. 5. Keep a positive attitude at work, learn to relax, and enjoy life. |
I'm going to travel to Beijing. Please introduce some tourist attractions to me. | 1. The Forbidden City: The imperial palace of the Ming and Qing dynasties in China, one of the most famous ancient buildings in China. 2. The Great Wall: The longest defensive wall in the world and a symbol of China. 3. Tiananmen Square: A world - famous square and city gate, and an important place for Chinese history and culture. 4. Wangfujing Street: A shopping street with a strong Chinese flavor, with various delicious foods, shops, and cultural activities. 5. The Summer Palace: A royal garden of the Qing dynasty and a world - class cultural heritage. |

