Spaces:
Runtime error
Runtime error
import keras_nlp | |
MODEL_NAME = "gemma2_instruct_2b_en" | |
LORA_WEIGHT_PATH = "ice_breaking_challenge/models/gemma2_it_2b_icebreaking.lora.h5" | |
def load_model_with_lora(model_name:str = MODEL_NAME, lora_weight_path: str = LORA_WEIGHT_PATH): | |
""" | |
Keras κΈ°λ° λͺ¨λΈ λ‘λ λ° LoRA κ°μ€μΉ μ μ© | |
Args: | |
model_name (str): λ‘λν λͺ¨λΈμ μ΄λ¦ | |
lora_weight_path (str): μ μ©ν LoRA κ°μ€μΉ νμΌμ κ²½λ‘ | |
Returns: | |
keras_nlp.models.GemmaCausalLM: λ‘λλ λͺ¨λΈ | |
""" | |
model = keras_nlp.models.GemmaCausalLM.from_preset(model_name) | |
model.backbone.load_lora_weights(lora_weight_path) | |
question_crawling="λμ μ΄λ° μ μ μΌν λ λμμ΄ λΌ!?" | |
answer_crawling="λλκ³ μΆμ΄νλ λ§μ? μ£Όλ³ μ¬λλ€μ κ·Έλ§ νΌμ£ΌλΌκ³ νκΈ°λ νμ§λ§, λ΄κ° ν΄λΌμ΄μΈνΈλ‘λΆν° λμ λ²κ³ μ νλ κ²μ΄ μλλΌ μ‘°κΈμ΄λΌλ λ μ±κ²¨μ£Όκ³ μ νλ λ§μμ κ°μ‘μ λ κ²°κ΅ λμ λΈλλκ° ν¨μ¬ λ μ»€μ§ μ μλ€λ λ―Ώμμ΄ μλ€." | |
input_text = f"{question_crawling} {answer_crawling}" | |
print(model.generate(input_text, max_length=512)) | |
return model | |
# def template_setting(df:pd.DataFrame, is_test:bool) -> np.ndarray: | |
# template_input=""" | |
# <instruction> | |
# Using the text: {question_crawling} {answer_crawling}, create a new multiple-choice question with 4 answer options. | |
# """ | |
# template_output=""" | |
# <Response> | |
# {question_generated} | |
# {multiple_choice_generated} | |
# {answer_generated} | |
# """ | |
# template=template_input+'\n'+template_output | |
# inputs = np.array(df.apply(lambda row: template.format( | |
# question_crawling=row['question_crawling'], | |
# answer_crawling=row['answer_crawling'], | |
# question_generated=row['question_generated'] if not is_test else "", | |
# multiple_choice_generated=row['multiple_choice_generated'] if not is_test else "", | |
# answer_generated=row['answer_generated'] if not is_test else "").strip(), axis=1)) | |
# outputs = np.array(df.apply(lambda row: template_output.format( | |
# question_generated=row['question_generated'], | |
# multiple_choice_generated=row['multiple_choice_generated'], | |
# answer_generated=row['answer_generated']).strip(), axis=1)) | |
# combined_array = np.column_stack((inputs, outputs)) | |
# return combined_array |