Yun-Tao Chen
    • 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

      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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
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
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

    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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # RNN 筆記 - 損失函數與反向傳遞演算法 Ref 吳尚鴻教授上課影片 from Youtube: https://www.youtube.com/watch?v=2btuy_-Fw3c&list=PLlPcwHqLqJDkVO0zHMqswX1jA9Xw7OSOK Ref LaTeX Math Symbols: http://web.ift.uib.no/Teori/KURS/WRK/TeX/symALL.html 本篇討論 RNN 是怎麼 train 的! ## Cost Function of Vanilla RNNs - Parameters to learn: ${\Theta = \{ W^{(k)}, U^{(k)}\}_k}$ (bias terms omitted) - Maximum likelihood: ${argmin_{\Theta}C(\Theta) \\= argmin_{\Theta}-logP(X|\Theta) \\= argmin_{\Theta}-\sum_{n,t}logP(y^{(n,t)}|x^{(n,t)},...,x^{(n,1)},\Theta) \\=argmin_{\Theta}-\sum_{(n,t)}C^{(n,t)} (\Theta) }$ - $y^{(t)}$ depends only on $x^{(1)},x^{(2)},...,x^{(t)}$ C 代表 Cost 作為神經網路的 Loss function 這個 Loss function 除了看不同的 data point "n" 以外,也要看時間維度上不同的 "t" 來計算 P 代表 Probability 是一個 on given Weight $\Theta$ 的條件下的條件機率 **Cost function 跟一般的 NN 使用的差異不大,只是多了一個時間維度 t** ## Backpropogation Through Time (BPTT) SGD: 先隨機猜參數 "Theta" 然後去計算 partial sum of Losses 乘以 Learning Rate "eta" 再去更新參數 $\Theta^{(s+1)} \leftarrow \Theta^{(s)} - \eta\bigtriangledown_\Theta\sum_{(n,t)}C^{(n,t)}(\Theta^{(s)})$ 為求簡化 notation of Loss 的表示法,改以 c 來表示如下: $c^{(n,t)} = C^{(n,t)}(\Theta^{(s)})$ 目標是去計算 $\dfrac{\partial{c^{(n,t)}}}{\partial{U_{i,j}^{(k)}}}$ and $\dfrac{\partial{c^{(n,t)}}}{\partial{W_{i,j}^{(k)}}}$ 複習一下參數的定義: U 影響的是時間維度的 gradient W 影響的是神經網路"層與層之間"空間維度的 gradient ![](https://i.imgur.com/C0vVfdH.png) W 部分跟一般的神經網路相同,先不贅述 這次我們要特別來探討 U 上面的 error signal 在 **forward pass** 的階段: 除了原本就有的網路架構上 forward pass 之外,多了 "Forward Pass Through Time" ![](https://i.imgur.com/ehdl7Fh.png) We can get all second term starting from the most shallow layer and ==earliest time== 同理 Backward Pass 的階段也多了 "Backward Pass Through Time" ![](https://i.imgur.com/3txaTos.png) 上圖中 - 藍色部分: 目前層的 a 會影響到深一層的所有 z $a^{(k,t)}$ 會影響到 $a^{(k+1,t)}$ - 紅色部分: 目前層的 a 會影響到同一層,但在下一個時間的所有 z $a^{(k,t)}$ 會影響到 $a^{(k,t+1)}$ 化簡式子: ![](https://i.imgur.com/dSRP5qv.png) 結論: - 把所有深層的 W 跟 error signal 算好,然後從深層走回淺層 - 把所有最新時間點的 U 跟 error signal 算好,然後從最新時間點往回走 把以上兩者結果相加後,經過 activation function 微分後的 gradient 值,即為該神經元更新參數之依據 實務上,對於同一個 sequence n 來講 forward pass 可以 shared ![](https://i.imgur.com/CgSs6HA.png) forward pass: 從左下走到右上 對於每一個時間點的 Loss 都可以分別算 error signal 時間點 1 的 error signal 沿著綠色走 時間點 2 的 error signal 沿著藍色走 時間點 3 的 error signal 沿著紅色走 backward pass 全部算出來後: 對於 W(1) 來講,把三個 error signal 全部加起來,乘上 forward pass 算出的結果,得到對於整個 sequence 需更新的參數組合

    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