Simon-Liu/DeepSeek-R1-Distill-Llama-8B-zhtw-news-title-generation-finetune

模型簡介

DeepSeek-R1-Distill-Llama-8B-zhtw-news-title-generation-finetune 是一款基於 DeepSeek-R1-Distill-Llama-8B 的大型語言模型進行 Fine-Tune 讓模型學習如何生成新聞標題。本模型使用了 Unsloth 框架和工具進行 Fine-Tune 優化。


微調(Fine-tuning)

使用 LoRA 進行微調

以下是使用 LoRA 微調模型的範例程式碼:

model = FastLanguageModel.get_peft_model(
    model,
    r = 16,
    target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
                      "gate_proj", "up_proj", "down_proj"],
    lora_alpha = 16,
    lora_dropout = 0,
    use_gradient_checkpointing = "unsloth",
    random_state = 3407,
    use_rslora = False,
)

資料格式化與數據集

我們使用 AWeirdDev/zh-tw-pts-articles-sm 作為範例數據集。

以下是格式化數據集的範例:

from datasets import load_dataset

def formatting_prompts_func(examples):
    instructions = "請根據新聞內容,給予合適的新聞標題。"
    inputs = examples["content"]
    outputs = examples["title"]
    texts = []
    for input, output in zip(inputs, outputs):
        text = f"### Instruction:\n{instructions}\n\n### Input:\n{input}\n\n### Response:\n{output}" + tokenizer.eos_token
        texts.append(text)
    return {"text": texts}

dataset = load_dataset("AWeirdDev/zh-tw-pts-articles-sm", split="train")
dataset = 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)

作者 / Author

Simon Liu
Google GenAI GDE (Google Developer Expert)

如有任何問題或反饋,歡迎透過 Hugging Face 平台或透過 LinkedIn、GitHub 聯絡我。

If you have any questions or feedback, feel free to reach out on the Hugging Face platform or connect with me on LinkedIn or GitHub.


Citation

如果您在研究中使用此模型,請引用如下:

If you use this model in your research, please cite it as follows:

@misc{Liu2024NewsTitleGeneration,
  author = {Simon Liu},
  title = {Simon-Liu/DeepSeek-R1-Distill-Llama-8B-zhtw-news-title-generation-finetune},
  year = {2024},
  url = {https://huggingface.co/Simon-Liu/DeepSeek-R1-Distill-Llama-8B-zhtw-news-title-generation-finetune},
  note = {微調模型用於Fine-Tune練習用途,準確率無法保證}
}
Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support