LLM實作共學讀書會-第六組
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 2/20 Finetuning Large Language Models [TOC] --- ## 課程簡介 - 微調(Fine-tuning)是將現成的大型語言模型(pre-trained large language model (LLM))如ChatGPT客製化到自己的資料和任務上的一種技術,比只利用提示(prompting)更進一步。 - 雖然提示(prompting)可指引語言模型,但微調可以讓模型更貼合資料定義的專門任務,包括調整語調和風格。 - 微調使您能藉由自己的資料專門化既有的語言模型,無需大量資料和運算資源從零訓練語言模型。 - 本課程將涵蓋微調的定義、適用情境、與提示及檢索的差異、ChatGPT所用的指令微調、以及用Python親手微調語言模型的實作。 - 必備知識為Python和基礎深度學習概念。目標是易學的語言模型微調入門。 **課程連結**: https://learn.deeplearning.ai/finetuning-large-language-models/ * Introduction * Why finetune * Where finetuning fits in * Instruction finetuning * Data preparation * Training process * Evaluation and iteration * Consideration on getting started now * Conclusion ## Introduction :::info 這堂課介紹如何微調你自己的模型於特定的應用場景,並說明finetune 及 prompt 之間的好壞差異。 ::: 好的prompt 可以引導模型回應正確,但是在特定領域是pre-trained model 沒有的資料,很可能產生幻覺(Hallucination),或是給予不預期的回應,例如你想要模型回應的更有禮貌、更樂於助人或是更簡潔的回答等。 fine-tuning 可以很好微調語氣(tone)方法,就像chatGPT那樣看廣泛回應不同使用者的問題,但在普遍企業仍希望有自己專屬的模型以及資料進行開發,以應用在特定場景。再者,訓練基石模型(base model)需要大量的數據以及GPU運算資源,我們可以採用現有的LLM並根據自己的數據近一步訓練。 在本課程中,您將學習微調的概念、它如何為您的應用帶來益處、微調的實施方法,以及它與實時工程和增強生成的區別。您將探索如何結合這些技術進行微調,深入了解將GPT-3轉化為遵循指令的聊天GPT的特定微調方法。課程將指導您完成自己大型語言模型的微調過程,包括數據準備、模型訓練及評估,並通過程式碼實踐。本課程適合熟悉Python的學習者,並將通過理解程式碼來深化對深度學習基礎知識的理解,例如神經網絡訓練過程及訓練/測試拆分等概念。 ## Why finetune * Fine-tuning 可以將一般用途的模型如 GPT-3 特化為特定用例,如將 GPT-4 轉換為程式碼完成的 GitHub Copilot。這有點像將全科醫生變成專科醫生 * Fine-tuning 允許模型從遠超過提示所能容納的大量資料中學習。這有助於更正不正確的資訊和「幻覺」(hallucinations) * Prompt engineering 適用於快速原型製作,而 fine-tuning 更適合生產系統。 * 自定義 LLM fine-tuning 的好處包括更好的效能、隱私、成本控制和調節回應的能力 * 課程展示了一個非 fine-tuned LLAMA 模型對提示的糟糕回應,與 fine-tuned LLAMAChat 模型給出的更好回應形成對比 * 課程詳細地講解如何進行 fine-tuning ### What dose finetuning do for the model? * Fine-tuning 使您可以將遠超過提示所能容納的更多資料輸入模型中 * Fine-tuning 使模型可以從資料學習,而不僅僅是透過提示獲得資料的存取權 **案例一**:醫療診斷 ![image](https://hackmd.io/_uploads/S1xnurg2T.png) Prompt: 皮膚過敏、發紅、癢感 左圖:Base Model ->得到簡單的回答 右圖:Finetuned Model -> 依據皮膚科的數據微調 -> 獲得更多細節的診斷 **案例二**:聊天對話 ![image](https://hackmd.io/_uploads/Ske49rg3T.png) prompt: 你的名字是什麼? 左圖:Base Model -> 反問但沒有回答 右圖:Finetuned Model -> 依據用戶資料微調 -> 正確回答姓名 * 引導模型輸出更一致的結果Steers the model to more consistent outputs * 減少幻覺 Reduces hallucinations * 根據特定案例客製化模型 Customizes the model to a specific use case * 過程類似於模型早期的訓練Process is similar to the model's earlier training **Prompt Egineering vs Finetuning** **<center>Prompt Engineering</center>** 優點: * 可以快速上手,不需要資料就可以開始使用 * 前期成本較低 * 不需要技術知識 * 可以透過檢索增強生成(RAG)接入部分資料 缺點: * 只能使用很少量的資料,大量資料無法放入提示中 * 容易「遺忘」提示中的資料 * 容易產生「幻覺」(hallucination),亂捏造資訊 * 檢索增強生成(RAG)可能會取回錯誤的資料 適用情境: * 泛用案例 * 快速原型或概念驗證 **<center>Finetuning</center>** 優點: * 可以使用近乎無限量的資料進行訓練 * 模型可以從資料中學習新的知識 * 可以糾正模型原先學到的錯誤資訊 * 使用小型模型後可以降低成本 * 也可以配合RAG使用 缺點: * 需要大量高品質的訓練資料 * 需要額外的計算資源,前期成本較高 * 需要一定的技術能力,尤其是處理資料的技能 適用情境: * 領域專家級的應用 * 生產環境中的應用 * 需要自訂模型的企業應用 ![image](https://hackmd.io/_uploads/rkyJhSgnT.png) Fine-tuning 自己的大型語言模型(LLM)的好處如下: 效能 * 避免語言模型亂編造資訊(stop hallucinations) * 增加模型穩定一致的輸出(increase consistency) * 減少不需要的資訊(reduce unwanted info) 隱私 * 在自有機房或雲端虛擬私有雲(on-prem or VPC)部屬,避免資料外洩 * 防止資料洩漏與遭到入侵(prevent leakage and breaches) 成本 * 降低每一次請求的成本(lower cost per request) * 提高成本的透明度與控制力(increased transparency and contro!) 可靠度 * 控制服務的上線時間(control uptime) * 降低延遲(lower latency) * 進行調節與審核(moderation) ### ## 實際應用和案例研究 ## 摘要與思維導圖 ## 問題討論與反思

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully