AIM2021
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
        • 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 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
      • 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 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
    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 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
    # 機器學習 101(Machine Learning 101)第一部分:基礎 ## 神經網路(Neural Network) 從外部來看,神經網絡只是一個函數。因此,它可以接受輸入並產生輸出。這個函數是高度參數化的,這是非常重要的。 其中一些參數是我們自己設置的。這些參數稱為超參數,可以看作是我們的神經網絡的配置。然而,大多數參數是網絡固有的,我們無法直接控制。 要理解為什麼這些很重要,我們需要看看內部。 一個簡單的神經網絡通常由一組隱藏層組成,每個隱藏層包含許多神經元,圖中標記為黃色。輸入層標記為藍色。 ![Neural Network](https://i.imgur.com/mahpUR6.png) 在上面的配置中,輸入是大小為 4 的向量 X,輸出是大小為 3 的向量 Y。 正如您在圖片中看到的那樣,一層中的每個神經元與下一層中的每個神經元都存在連接¹。每個這樣的連接實際上都是一個參數或權重。在這個例子中,我們已經有 94 個額外的權重參數。在更大的網絡中,可以有更多的量級。這些權重將定義網絡的行為方式以及將輸入轉換為所需輸出的能力。 ## 神經元 Neuron 在解釋整個網絡如何用於轉換數據之前,我們需要進一步放大。 來看看單個神經元: ![Neuron](https://i.imgur.com/TlYFXAd.png) 每個神經元的輸入是前一層每個神經元輸出的加權和。具體來說,會像這樣: ![](https://i.imgur.com/oHYfLdr.png) 這裏,我們加了一個稱為誤差值( bias ),它為神經元提供了一個輸入的總和: ![](https://i.imgur.com/V01epml.png) ![](https://i.imgur.com/0oB0u08.png) ## 激勵函數 Activation Function 然後藉由套用激勵函數的東西在神經元內轉換輸入信號,表示為σ。名稱,激勵函數,源於這樣一個事實,如果輸入信號z足夠大,這個函數通常被設計為讓信號通過神經元,但如果z不是,則限制神經元的輸出。如果刺激足夠強,我們可以將其視為神經元放電或活躍。 更重要的是,激勵函數為網絡增加了非線性,這在嘗試有效地擬合網絡時很重要(通過擬合網絡,我的意思是訓練網絡以產生我們想要的輸出)。沒有它,網絡將只是其輸入的線性組合。 經常使用稱為整流線性單元或 ReLU 的激勵函數(或其變體)。ReLU 很簡單: ![](https://i.imgur.com/ytRW7OR.png) ![](https://i.imgur.com/OKV2S1f.png) 從圖中可以看出,它們都依照上面描述的方式運行:如果訊號夠大,它們就會讓訊號通過,否則就限制它。 最後,在對 z 套用激勵函數後,得到 σ(z),我們得到了神經元的輸出。 或者以向量形式表示:在將激活函數應用於向量z 後,得到σ(z)(該函數應用於向量z中的每個元素)我們得到了該層中所有神經元的輸出。 ## Feed Forward 前饋 目前講解了我們如何將整個神經網絡(即“函數”)來用數據 x 獲得輸出 y = f(x)。 我們只是通過網路中的每一層神經元提供數據。這就是所謂的 **前饋**。 它的工作原理: 輸入 x 並從第一個隱藏層(hidden layer)開始。 * 對於當前層 n 中的每個神經元,取前一層 n - 1 中每個連接神經元的輸出的加權總和。添加誤差值並使用激勵函數。 * 再來以第 n 層的輸出值作為輸入,輸入第 n + 1 層,現在逐層進行,直到到達最後一層。 * 這些神經元的輸出將給出y。 來看一個簡單的例子: ![](https://i.imgur.com/v9XLQaJ.png) 假設我們在所有層中都選擇了 sigmoid 函數當作我們的 Activation Function: ![](https://i.imgur.com/k7no9iZ.png) 現在讓我們逐層、逐個神經元,計算這個網絡將在輸入向量 x = [2 3] 上給出的輸出 y。 ![](https://i.imgur.com/GgJyoq0.png) 因此,該網絡在輸入 x = [2 3] 上產生輸出 y = [0.7122574322957417 0.5330975738715015 ]。 如果我們很幸運,或者我們剛好很擅長設置初始權重和誤差值,這可能就是我們想要的輸入輸出。 但更有可能的是,它根本不是我們想要的輸入輸出。 如果是後者,我們可以調整權重和誤差值,一直到得到我們想要的輸出。 讓我們花點時間思考一下為什麼神經網絡是這樣設計的,以及為什麼可能需要調整權重和誤差值才能使網絡的行為更符合我們的預期。 ## 神經網路的表達能力 網絡的 **高參數化** 使其非常有能力模仿幾乎任何函數。 如果我們想要模仿的函數比權重和誤差值的組合能表達得更為複雜,我們可以再建立一個更大的網絡(更深和/或更寬),這將讓我們可以加入更多參數,進而讓網絡接近我們想要模擬的函數。 另外要注意,通過建立神經網絡的方式,我們可以自由選擇 **輸入** 的任何維度和 **輸出** 的任何維度。 神經網絡通常被設計為降低維度(降維)—— 也就是 **將高維度空間裡的點映射到低維度空間裡的點** 。這是典型的 **數據分類(Classification of data)**。我將在本文末尾用一個例子來回答這個問題。 現在考慮每個神經元中發生的情況:σ( Wx+b) —— 也就是我們將來自前一層的訊號提供給激勵函數,但我們要先對其進行縮放和轉譯。 那麼,把參數縮放和轉換成函數有什麼意義呢?想一想。 簡單起見,讓我們看看當我們將輸入縮放到函數時會發生什麼情況。 這是把未縮放的輸入套用 sigmoid 函數的樣子,也就是 **σ(x)**: ![](https://i.imgur.com/MP7blQg.png) 如果我們將輸入縮放 5 倍,即 **σ(5x)** ,則結果如下所示。 如你所見,並且可能已經猜到,縮放輸入會在 x 軸上壓縮或擴展函數。 ![](https://i.imgur.com/G3DiZRv.png) 最後,如果輸入值加上常數項就代表我們在 x 軸上進行平移、移動函數。這是 **σ(5x - 4)**: ![](https://i.imgur.com/HF4WvXF.png) 因此,藉由將輸入縮放和轉換為激勵函數,我們可以移動和伸縮它。 還要記住,一層的輸出是下一層的輸入。也就是說,在 L 層中產生的曲線(例如上面的任何一條)將被縮放和平移,然後再饋送到 L+1 層中的激勵函數。 所以現在我們需要問,縮放和平移 L 層函數的輸出是什麼意思? 縮放只代表改變了該訊號的幅度,也就是沿著 y 軸拉伸或壓縮它。 平移代表沿 x 軸移動它。 那麼這為我們帶來了什麼? 儘管上面的討論並沒有證明任何事情,但它強烈表明,通過改變神經網絡的權重和誤差值,我們可以根據我們的喜好以非線性方式拉伸和轉換輸入值(甚至單個向量分量)。 還要考慮到網絡的深度會讓權重在不同的尺度上運行,並對總函數有不同的貢獻(影響) —— 也就是説越早期的權重會越大規模的改變總函數,而最後輸出層前一層的權重則影響到較細節的部分。 這為神經網絡提供了非常高的表現力,但代價是需要調整大量參數。幸運的是,我們不必手動調整它。我們可以讓網路自我調整,讓輸出更接近我們的期待。這是通過稱為梯度下降和反向傳播的過程完成的,也就是這系列下一篇文章的主題,第 2 部分:梯度下降和反向傳播。 ## 現在,要怎麼讓函數有智慧? 我們已經得出結論,神經網絡可以模擬從向量 x 到另一個向量 y 的映射(函數)。在這一點上,可以公平地問:這對我們有什麼幫助? 使用神經網絡的一種非常常見的方法是對以前從未見過的數據進行分類。因此,在結束這篇已經很長的文章之前,我將簡要介紹一個分類的實際示例。我們將在後面的文章中回到一個例子。 在編寫神經網絡時,通常面臨的首要任務之一是對手寫數字進行分類(類似於機器學習中的“Hello World”)。對於這項任務,有一個包含 60 000 張手寫數字圖像的數據集,稱為MNIST 數據集。分辨率為 28 x 28,每個像素中的顏色是 0 到 255 之間的灰度值。數據集被標記,這意味著它指定了每個圖像代表的數字。 ![](https://i.imgur.com/7XL3cZ7.png) 如果我們將每個圖像展平——即,將圖像的每一行排成一條長線——我們將得到一個大小為 28 x 28 = 784 的向量。此外,我們將灰度值標準化為 0 到 1 之間的範圍。現在它如果我們可以將這個向量x提供給神經網絡並作為輸出得到一個大小為 10的y向量,告訴網絡認為輸入代表的數字(即輸出向量的每個元素告訴網絡給出的概率),那就太好了圖像是零,一,二,...,九)。由於 MNIST 數據集被標記,我們可以訓練這個網絡,這基本上意味著:自動調整權重和偏差。很酷的是,如果訓練得當,網絡將能夠對手寫數字的圖像進行分類它以前從未見過——以聲明方式編程是非常困難的。 這怎麼可能? 我將嘗試用總結性的思考來解釋這一點:每個輸入向量x可以看作是 784 維空間中的一個點。想想看。長度為 3 的向量表示 3D 中的一個點。長度為 784 的向量則表示 784D 中的一個點。由於每個像素值都在 0 和 1 之間歸一化,我們知道該數據集的所有點都位於單位立方體內,即在所有 784 個軸上都在 0 和 1 之間。可以合理地認為,代表數字 N 的所有點在這個空間中都非常靠近。例如,數字 2 的所有圖像將在某個子空間中彼此靠近,並且所有 7:s 將靠近但位於不同的子空間中。在設計這個網絡時,我們決定輸出應該是一個大小為 10 的向量,其中每個分量都是一個概率。這意味著輸出是 10 維單位立方體中的一個點。我們的神經網絡將 728D 立方體中的點映射到 10D 立方體中的點。 現在,在這種特殊情況下擬合網絡的真正含義是使用我們的神經網絡函數在 784D 輸入空間中找到這些子空間,並以它們在 10D 中清晰可分離的方式變換(縮放、平移)它們。例如:我們希望數字 7 的所有輸入(但它們可能略有不同)輸出向量 y,其中表示數字 7 的分量接近 1,所有其他 9 個分量接近 0。 我傾向於將擬合過程視為圍繞這些子空間³的收縮包裹表面(超平面)。如果我們不把這些表面收縮包裝得太硬(這會導致過度擬合),網絡尚未看到的數字很可能會最終出現在正確的子空間中——換句話說,網絡會然後能夠說:“嗯,我以前從未見過這個數字,但它在我認為是數字 7 的子空間內”。 這有點酷! 好的,這將用於介紹。歡迎反饋! 現在,在本系列的下一篇文章中,您將了解如何訓練神經網絡,第 2 部分:梯度下降和反向傳播。 ## Activation Function

    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 Google 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