Views
No views yet
1model = FastLanguageModel.get_peft_model(
2 model,
3 r = 16,
4 target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
5 "gate_proj", "up_proj", "down_proj"],
6 lora_alpha = 16,
7 lora_dropout = 0,
8 use_gradient_checkpointing = "unsloth",
9 random_state = 3407,
10 use_rslora = False,
11)1from datasets import load_dataset
2
3def formatting_prompts_func(examples):
4 instructions = "請根據新聞內容,給予合適的新聞標題。"
5 inputs = examples["content"]
6 outputs = examples["title"]
7 texts = []
8 for input, output in zip(inputs, outputs):
9 text = f"### Instruction:\n{instructions}\n\n### Input:\n{input}\n\n### Response:\n{output}" + tokenizer.eos_token
10 texts.append(text)
11 return {"text": texts}
12
13dataset = load_dataset("AWeirdDev/zh-tw-pts-articles-sm", split="train")
14dataset = dataset.map(formatting_prompts_func, batched=True)
news_content = """<新聞內容>"""
# alpaca_prompt = Copied from above
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
inputs = tokenizer(
[
alpaca_prompt.format(
"請根據新聞內容,給予合適的新聞標題。", # instruction
news_content, # input
"", # output - leave this blank for generation!
)
], return_tensors = "pt").to("cuda")
from transformers import TextStreamer
text_streamer = TextStreamer(tokenizer)
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 128)1@misc{Liu2024NewsTitleGeneration,
2 author = {Simon Liu},
3 title = {Simon-Liu/DeepSeek-R1-Distill-Llama-8B-zhtw-news-title-generation-finetune},
4 year = {2024},
5 url = {https://huggingface.co/Simon-Liu/DeepSeek-R1-Distill-Llama-8B-zhtw-news-title-generation-finetune},
6 note = {微調模型用於Fine-Tune練習用途,準確率無法保證}
7}