小型(7B 及以下)、生产就绪的微调法学硕士,适用于各种有用的任务。
支持的任务:释义、改变段落语气、从对话中生成摘要和主题,检索增强 QA(WIP) 。
我们在量化 3B 和 7B 模型上微调 LoRA。 3B 模型针对特定任务进行微调,而 7B 模型针对所有任务进行微调。
目标是能够在非常适度的消费级硬件上微调和使用所有这些模型。
pip install llm-toys
如果没有启用 CUDA 的 GPU,可能无法工作
如果您在使用bitsandbytes时遇到“已安装的bitsandbytes版本是在没有GPU支持的情况下编译的”,请查看此处bitsandbytes-foundation/bitsandbytes#112
或尝试
cp <path_to_your_venv>/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cpu.so <path_to_your_venv>/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda117.so
请注意,我们使用的是源目录中的转换器和 pef 包,而不是已安装的包。 4位bitsandbytes量化仅适用于变压器和peft的主要分支。一旦 Transformers 版本 4.31.0 和 peft 版本 0.4.0 发布到 pypi,我们将使用发布的版本。
模型 | 尺寸 | 任务 | 科拉布 |
---|---|---|---|
llm-toys/RedPajama-INCITE-Base-3B-v1-释义音 | 3B | 释义、语气变化 | 笔记本 |
llm-toys/RedPajama-INCITE-Base-3B-v1-对话-摘要-主题 | 3B | 对话总结和话题生成 | 笔记本 |
llm-toys/falcon-7b-释义-语气-对话-摘要-主题 | 7B | 释义、语气变化、对话摘要和话题生成 | 笔记本 |
from llm_toys . tasks import Paraphraser
paraphraser = Paraphraser ()
paraphraser . paraphrase ( "Hey, can yuo hepl me cancel my last order?" )
# "Could you kindly assist me in canceling my previous order?"
paraphraser . paraphrase ( "Hey, can yuo hepl me cancel my last order?" , tone = "casual" )
# "Hey, could you help me cancel my order?"
paraphraser . paraphrase ( "Hey, can yuo hepl me cancel my last order?" , tone = "professional" )
# "I would appreciate guidance on canceling my previous order."
paraphraser . paraphrase ( "Hey, can yuo hepl me cancel my last order?" , tone = "witty" )
# "Hey, I need your help with my last order. Can you wave your magic wand and make it disappear?"
from llm_toys . tasks import SummaryAndTopicGenerator
summary_topic_generator = SummaryAndTopicGenerator ()
summary_topic_generator . generate_summary_and_topic (
"""
#Person1#: I'm so excited for the premiere of the latest Studio Ghibli movie!
#Person2#: What's got you so hyped?
#Person1#: Studio Ghibli movies are pure magic! The animation, storytelling, everything is incredible.
#Person2#: Which movie is it?
#Person1#: It's called "Whisper of the Wind." It's about a girl on a magical journey to save her village.
#Person2#: Sounds amazing! I'm in for the premiere.
#Person1#: Great! We're in for a visual masterpiece and a heartfelt story.
#Person2#: Can't wait to be transported to their world.
#Person1#: It'll be an unforgettable experience, for sure!
""" . strip ()
)
# {"summary": "#Person1# is excited for the premiere of the latest Studio Ghibli movie.
# #Person1# thinks the animation, storytelling, and heartfelt story will be unforgettable.
# #Person2# is also excited for the premiere.",
# "topic": "Studio ghibli movie"}
from llm_toys . tasks import GeneralTaskAssitant
from llm_toys . config import TaskType
gta = GeneralTaskAssitant ()
gta . complete ( TaskType . PARAPHRASE_TONE , "Hey, can yuo hepl me cancel my last order?" )
# "Could you assist me in canceling my previous order?"
gta . complete ( TaskType . PARAPHRASE_TONE , "Hey, can yuo hepl me cancel my last order?" , tone = "casual" )
# "Hey, can you help me cancel my last order?"
gta . complete ( TaskType . PARAPHRASE_TONE , "Hey, can yuo hepl me cancel my last order?" , tone = "professional" )
# "I would appreciate if you could assist me in canceling my previous order."
gta . complete ( TaskType . PARAPHRASE_TONE , "Hey, can yuo hepl me cancel my last order?" , tone = "witty" )
# "Oops! Looks like I got a little carried away with my shopping spree. Can you help me cancel my last order?"
chat = """
#Person1#: I'm so excited for the premiere of the latest Studio Ghibli movie!
#Person2#: What's got you so hyped?
#Person1#: Studio Ghibli movies are pure magic! The animation, storytelling, everything is incredible.
#Person2#: Which movie is it?
#Person1#: It's called "Whisper of the Wind." It's about a girl on a magical journey to save her village.
#Person2#: Sounds amazing! I'm in for the premiere.
#Person1#: Great! We're in for a visual masterpiece and a heartfelt story.
#Person2#: Can't wait to be transported to their world.
#Person1#: It'll be an unforgettable experience, for sure!
""" . strip ()
gta . complete ( TaskType . DIALOGUE_SUMMARY_TOPIC , chat )
# {"summary": "#Person1# tells #Person2# about the upcoming Studio Ghibli movie.
# #Person1# thinks it's magical and #Person2#'s excited to watch it.",
# "topic": "Movie premiere"}
释义和语气变化:包含段落及其释义版本,以及休闲、专业、诙谐等不同语气的段落。用于模仿来改写和改变段落的语气。数据是使用 gpt-35-turbo 生成的。还从 quora 问题和squad_2 数据集中选取了一小部分训练段落样本。
对话摘要和主题生成:包含对话及其摘要和主题。训练数据是来自 Dialogsum 数据集训练分割的约 1k 条记录。它还包含来自开发组的约 20 个样本。在采样中优先考虑具有较长摘要和主题的数据点。请注意,最终训练数据中的一些(~30)主题是手动编辑的,因为原始标记的主题只是一个单词,描述性不够。
查看所有选项
python llm_toys/train.py --help
训练释义和语气变化模型
python llm_toys/train.py
--task_type paraphrase_tone
--model_name meta-llama/Llama-2-7b
--max_length 128
--batch_size 8
--gradient_accumulation_steps 1
--learning_rate 1e-4
--num_train_epochs 3
--eval_ratio 0.05
在制品
对 Dialogsum 测试分组中的 500 条记录进行评估。
# llm-toys/RedPajama-INCITE-Base-3B-v1-dialogue-summary-topic
{ "rouge1" : 0.453 , "rouge2" : 0.197 , "rougeL" : 0.365 , "topic_similarity" : 0.888 }
# llm-toys/falcon-7b-paraphrase-tone-dialogue-summary-topic
{ 'rouge1' : 0.448 , 'rouge2' : 0.195 , 'rougeL' : 0.359 , 'topic_similarity' : 0.886 }