蝦想承為工程師
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • 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 Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    ## 介紹 Transformer 架構 Transformer 由 Vaswani 等人在 2017 年提出,原始的 Transformer 模型由一個編碼器(Encoder)和一個解碼器(Decoder)組成。無論是 Encoder 還是 Decoder,其基本單元都是多頭自注意力機制(Multi-Head Self-Attention)和前饋神經網路(Position-wise Feed-Forward Network)組成的子層,並透過殘差連接和 Layer Normalization 做穩定訓練。 兩者的差別在於,Decoder 與 Encoder 連接時多了一個交叉注意力(Cross-Attention)子層,用於在解碼時關注編碼器的輸出,此外,Decoder 中的自注意力採用了遮罩機制(Masked Self-Attention),以避免模型在生成時看到未來的單詞,確保第 $i$ 個位置只能查看前面 $i-1$ 的輸出,若想更清楚了解細節請看 [Transformer](https://hackmd.io/@lcaMuWOwR1Ox5o5yeTEupA/ryMKua8H0) 這篇文章。 ![image](https://hackmd.io/_uploads/Bk79n6ISA.png) ## Encoder-Only 架構 Encoder-Only 模型只使用 Transformer 的編碼器,不含解碼器。這類模型在處理輸入時採用雙向自注意力機制,讓每個詞彙能同時關注序列中左側和右側的上下文,由於不涉及生成過程,Encoder-Only 模型的自注意力層不需要遮罩未來訊息,可以充分學習整個序列的語意關係,這使得它對語境的理解更加透徹,能捕捉句子中每個詞的完整上下文。 Encoder-Only 架構專注於對輸入文本的理解和表示,因此特別適合需要從整段文字中提取資訊或判斷屬性的任務。 ### Encoder-Only 應用情境 #### 文本分類: * 情感分析(Sentiment Analysis):判斷用戶評論或社交媒體貼文的情感(正面、中立或負面)。 * 新聞分類:將新聞文章自動分配到不同的主題(政治、科技、體育等)。 * 垃圾郵件檢測(Spam Detection):識別電子郵件是否為垃圾郵件。 * 法律文本與醫學文本分類:對法律文件、醫學報告進行特定類別的歸類。 #### 序列標註: * 命名實體識別(NER, Named Entity Recognition):從句子中識別出人名、地名、組織名等實體。 * 詞性標註(POS Tagging):標記單詞的詞性,如名詞、動詞、形容詞等。 * 語法分析(Syntactic Parsing):構建句子的語法樹,標記主詞、動詞、賓語等。 ## Decoder-Only 架構 Decoder-Only 模型只包含 Transformer 的解碼器。Decoder-Only 架構的每一層同樣包含多頭注意力機制和前饋網路,不同之處在於自注意力機制帶有遮罩,在 Decoder 的自注意力層中,每個單詞只能關注它之前已出現的單詞,無法觀看後面的未來詞彙,這種單向(自回歸)注意力確保模型按照從左到右的順序逐步生成文本,模型在生成第 $i$ 個詞時只能利用第 $1$ 到第 $i-1$ 個詞的信息,此形式也被稱為「Autoregressive」。 Decoder-Only 模型的最大優勢在於,它以語言模型的方式進行預訓練(預測下一個詞),它對語言的統計特性和用詞連貫性學習充分,生成文本的流暢度極高。另外,大規模的 Decoder-Only 模型展現出令人驚奇的泛化能力和零樣本或少樣本學習(Zero-shot 或 Few-shot)能力,即使只以「預測下一詞」任務進行預訓練,模型也隱含學會了總結、翻譯、問答甚至推理等各種技能。 ### Decoder-Only 應用情境 #### 開放式文本生成(Open-ended Text Generation) * 文章續寫:根據開頭一段文字,讓模型自動擴展內容,如新聞撰寫、小說創作等。 * 故事創作:根據簡單的故事設定(例如人物、背景、情節),讓 AI 自動編寫完整的故事段落。 #### 對話系統(Conversational AI) * 客戶服務:如 ChatGPT、企業客服機器人。 * 智能助手:如 Siri、Google Assistant,處理用戶查詢。 * 開放式聊天:如 AI 角色扮演對話、聊天伴侶。 #### 程式碼補全與生成(Code Completion & Code Generation) * 自動補全程式碼(如 GitHub Copilot):根據已有程式碼的部分,完成缺失部分。 * 從自然語言生成程式碼:例如「請寫一個 Python 函數來計算斐波那契數列」,模型直接輸出程式碼。 ## Encoder-Decoder 架構 Encoder-Decoder 模型結合了編碼器和解碼器兩部分架構,也稱 Seq2Seq 模型。這類架構最初即用於機器翻譯等任務,Transformer 原始論文的模型包含6層編碼器和6層解碼器,Encoder 先對輸入序列進行編碼,把每個輸入token轉換為包含語意資訊的向量表示;Decoder 隨後根據 Encoder 輸出的向量,生成目標序列(如文字)。 Encoder-Decoder 架構的關鍵在於交叉注意力(Cross-Attention) 機制,Decoder的每一層通常包含三個子層:第一個是遮罩自注意力,第二個是交叉注意力,第三個是前饋網路,其中交叉注意力子層的 Query 來自 Decoder 前一層的輸出,而 Key/Value 則來自 Encoder 的輸出,交叉注意力讓 Decoder 在生成每個詞時,都能動態查詢編碼器輸出的資訊,聚焦於輸入序列中與當前要生成詞相關的部分,從而生成更準確的內容。 ### Encoder-Decoder 應用情境 #### 機器翻譯(Machine Translation, MT) * 通用機器翻譯:如 Google 翻譯、DeepL,支援多語言翻譯。 * 字幕翻譯:即時將影片字幕從一種語言轉換為另一種語言。 #### 問答生成(Question Answering, QA) * 閱讀理解(Reading Comprehension):如 SQuAD(Stanford Question Answering Dataset)。 * 客服自動回應:如 AI 問答機器人。 * 智能搜索系統:從文件或數據庫中提取正確答案。 ## 總結 ![image](https://hackmd.io/_uploads/rkVfcKNjJl.png)

    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
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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