Spaces:
Runtime error
Runtime error
File size: 2,545 Bytes
387a8a0 fcfe249 387a8a0 fcfe249 387a8a0 fcfe249 387a8a0 fcfe249 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
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 |