open LLM
1.0.0
该存储库包含代码,该代码证明了拥抱面孔库的使用用于零击文本分类和文本生成。它包括用于分类的BART的示例和用于文本生成的GPT-2。
ZeroShotInference类:用于处理零击文本分类和文本生成的类。 main.py :用于文本分类和文本生成的ZeroShotInference类的示例用法。
要运行此代码,您需要安装拥抱面孔变形金刚库及其依赖项。您可以安装它们:
pip install transformers torch此示例使用Facebook Bart大型模型(Bart-Large-MNLI)根据给定的候选标签对文本进行分类。
from transformers import pipeline
class ZeroShotInference :
def __init__ ( self , task , pre_trained_model ):
self . model = pre_trained_model
self . task = task
self . pipe = pipeline ( task = self . task , model = self . model )
def classify_text ( self , text , candidate_labels ):
result = self . pipe ( text , candidate_labels )
return result示例用法:
text = "I love to play video games"
candidate_labels = [ 'hobby' , 'habit' , 'adventure' , 'boredom' , 'business' ]
task = "zero-shot-classification"
model = "facebook/bart-large-mnli"
zero_short_inference = ZeroShotInference ( task , model )
result = zero_short_inference . classify_text ( text , candidate_labels )
print ( result ) # Output: {'sequence': 'I love to play video games', 'labels': ['hobby', 'habit', 'adventure', 'business', 'boredom'], 'scores': [0.8799885511398315, 0.09845343977212906, 0.016700521111488342, 0.0031407771166414022, 0.0017165272729471326]}此示例使用GPT-2根据给定的提示来生成文本。
def generate_text ( self , prompt , max_length = 100 , temperature = 0.7 ):
output = self . pipe ( prompt , max_length = max_length , do_sample = True , temperature = temperature , truncation = True )
return output [ 0 ][ 'generated_text' ]示例用法:
prompt = "I was doing coding last night"
model_2 = "gpt2"
task_2 = "text-generation"
zero_shot_infernece_2 = ZeroShotInference ( task_2 , model_2 )
result_2 = zero_shot_infernece_2 . generate_text ( prompt )
print ( result_2 )该模型使用量化技术进行有效的推理,减少内存使用情况并使用BitsAndBytesConfig加速响应时间
对于hf_token,我已经从拥抱面生成了令牌
此任务旨在微调使用7B变体生成教学文本的Mistral模型。它涉及在特定数据集上训练模型,然后使用它根据给定的提示来生成教学文本。
微调Mistral指示7B项目利用Mistral模型(一种大规模的语言模型)来生成教学文本。通过在包含教学文本的数据集上微调模型,目标是创建一个能够生成连贯和有益指令的专门模型。
欢迎对该项目的贡献。请随意分叉存储库,进行更改并提交拉动请求。您还可以打开问题以建议改进或报告错误。