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模型(一種大規模的語言模型)來生成教學文本。通過在包含教學文本的數據集上微調模型,目標是創建一個能夠生成連貫和有益指令的專門模型。
歡迎對該項目的貢獻。請隨意分叉存儲庫,進行更改並提交拉動請求。您還可以打開問題以建議改進或報告錯誤。