joshuacwnewton
    • 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 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

    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
    ### API Proposal to add Gibbs sampling to LDA This enhancement was recently brought up in a meeting between a few of sklearn's core maintainers and students in the MLH Fellowship. @parthivc and I have expressed interest, and @thomasjpfan recommended some starting points for proposing API changes. ### Parameter changes From what I can tell, replacing Variational Bayes (VB) with a collapsed Gibbs sampler (CGS) shouldn't require any additional parameters. <sup>[[1, page 3]](http://mlg.eng.cam.ac.uk/teaching/4f13/1112/lect10.pdf)</sup> I've compared the current parameters in [`sklearn.LatentDirichletAllocation`](https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.LatentDirichletAllocation.html) with the parameters used by @hannawallach in her excellent [Python 2.7 implementation](https://github.com/hannawallach/python-lda/blob/master/src/lda.py). (I believe this link is what was referred to earlier by @amueller.) I couldn't find any new parameters that need to be added, and many existing parameters can be directly reused. <details> <summary>Table hidden, click to show</summary> **Note:** Certain parameters are used by sklearn, but are absent in hannahwallach's implementation. I've grouped these into 3 categories: 1. Parameters that are specific to Variational Bayes, whether online or batch. 2. Parameters that are related to sklearn’s use of perplexity for checking LDA model convergence. 3. Parameters related to sklearn core functionality (e.g. partial_fit, random_state, parallel processing, output verbosity) I believe parameters of the 1st type are unnecessary for Gibbs sampling. Parameters of the 2nd and 3rd type, though, could be reused. | Name (sklearn’s LDA w/VB) | Name (@hannawallach’s LDA w/Gibbs) | Description | | ------------------------------------------------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | | `n_components` (default: `n_components=10`) | `T` (default: `T=100`) | Number of topics. | | `doc_top_prior` (default: `doc_top_prior=1/n_components`) | `alpha` (default: `alpha=0.1`) | Prior of document topic distribution theta (θ). In [[3]](https://papers.nips.cc/paper/3902-online-learning-for-latent-dirichlet-allocation.pdf), this is called alpha (α). | | `topic_word_prior` (default: `topic_top_prior=1/n_components`) | `beta` (default: `beta=0.01`) | Prior of the topic word distribution beta (β). In [[3]](https://papers.nips.cc/paper/3902-online-learning-for-latent-dirichlet-allocation.pdf), this is called eta (η). | | `learning_method` | N/A <sup>[1]</sup> | Method used to update `_component`. (‘batch’ or ‘online’) | | `learning_decay` | N/A <sup>[1]</sup> | A parameter that controls learning rate in the online learning method. In the literature, this is called kappa (κ). | | `learning_offset` | N/A <sup>[1]</sup> | A (positive) parameter that downweights early iterations in online learning. In the literature, this is called tau_0 (τ<sub>0</sub>). | | `max_iter` (default: `max_iter=10`) | `S` (default: `S=1000`) | “The maximum number of iterations.” (sklearn) // “The number of Gibbs sampling iterations." (@hannawallach) | | `batch_size` | N/A <sup>[1]</sup> | Number of documents to use in each EM iteration. Only used in online learning. | | `evaluate_every` | N/A <sup>[2]</sup> | How often to evaluate perplexity. | | `total_samples` | N/A <sup>[3]</sup> | Total number of documents. Only used in the partial_fit method. | | `perp_tol` | N/A <sup>[2]</sup> | Perplexity tolerance in batch learning. Only used when evaluate_every is greater than 0. | | `mean_change_tol` | N/A <sup>[1]</sup> | Stopping tolerance for updating document topic distribution in E-step. | | `max_doc_update_iter` | N/A <sup>[1]</sup> | Max number of iterations for updating document topic distribution in the E-step. | | `n_jobs` | N/A <sup>[3]</sup> | The number of jobs to use in the E-step. | | `verbose` | N/A <sup>[3]</sup> | Verbosity level. | | `random_state` | N/A <sup>[3]</sup> | Pass an int for reproducible results across multiple function calls. | | `X` | `corpus` | Document word matrix. | | `weight` | N/A <sup>[1]</sup> | Weight, rho (ρ). Used internally, and is a function of `learning_offset` and `learning_decay`. | </details> ### R's implementation As well, I've taken a look at R's implementation ([`lda.collapsed.gibbs.sampler`](https://www.rdocumentation.org/packages/lda/versions/1.4.2/topics/lda.collapsed.gibbs.sampler)) to see if they've included any additional parameters. There are a few that seem useful to add, but they don't seem to be absolutely necessary. <details> <summary>Table hidden, click to show</summary> | Name | Description | | ---- | ----------- | | `burnin` | A scalar integer indicating the number of Gibbs sweeps to consider as burn-in (i.e., throw away) | | `compute.log.likelihood` | A scalar logical which when TRUE will cause the sampler to compute the log likelihood of the words (to within a constant factor) after each sweep over the variables. The log likelihood for each iteration is stored in the log.likelihood field of the result. This is useful for assessing convergence, but slows things down a tiny bit. | </details> ### Other details There are a few API details I'm unclear on: * Whether to keep online/batch VB as an alternative. _(A parameter `method` could be added with options `{'bayes', 'gibbs'}` for backwards compatibility. Then, parameters specific to Variational Bayes could be left as optional keyword parameters. The descriptions for these parameters could be amended to specifically mention VB.)_ * Default values for `n_components`, `max_iter`, and the priors. _(There are some differences between sklearn's LDA w/VB and hannahwallach's LDA w/CGS, as listed in the first table.)_ * The discussion above mentions Cython, but @thomasjpfan mentioned the possibility of a pure Python/NumPy implementation. I'd love to hear thoughts on this before proceeding. :)

    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