Skip to content

Added Restricted Boltzmann machines - #1200

Closed
ynd wants to merge 66 commits into
scikit-learn:masterfrom
ynd:rbm
Closed

ynd wants to merge 66 commits into
scikit-learn:masterfrom
ynd:rbm

Conversation

@ynd

@ynd ynd commented Oct 2, 2012

Copy link
Copy Markdown

RBMs are a state-of-the-art generative model. They've been used to win the Netflix challenge [1] and in record breaking systems for speech recognition at Google [2] and Microsoft. This pull request adds a class for Restricted Boltzmann Machines (RBMs) to scikits-learn. The code is both easy to read and efficient.

[1] http://techblog.netflix.com/2012/04/netflix-recommendations-beyond-5-stars.html
[2] http://research.google.com/pubs/archive/38130.pdf

@mblondel

mblondel commented Oct 3, 2012

Copy link
Copy Markdown
Member

That's great! How hard would it be to support scipy sparse matrices too? We're trying to avoid adding new classes that can only operate with numpy arrays...

@glouppe

glouppe commented Oct 3, 2012

Copy link
Copy Markdown
Contributor

Great addition indeed! What would be convenient is to define a RBMClassifier class from your RBM. There is several ways to do that, but the most straightforward would be to encode both X and y into the visible units and then to train your RBM. For predictions, clamp the values of X on the visible units (but let the visible units of y free), then let the machine stabilize and finally output the values at the visible units corresponding to y as the final predictions. Actually this strategy can even be used for multi-output problems.

Also, do you intend to handle missing values? (since you motivate your PR with Netflix)

Comment thread sklearn/rbm.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In scikit-learn, we are used to put a trailing underscore to all fitted attributes (self.W_).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In scikit-learn, we are used to put a trailing underscore to all fitted
attributes (self.W_).

In addition, we know try to avoid single-letter variable names. Can you
find a more explicit name?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PCA, a related attribute is components_.

@pprett

pprett commented Oct 3, 2012

Copy link
Copy Markdown
Member

Thanks for the contribution - I'm super excited - can't wait to see this merged to master!

Comment thread sklearn/rbm.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this changes anything, but wouldn't it be better to output 0. if x < -30 and 1. if x > 30? Also, since this very particular function is at the core of the algorithm, a Cython version may be a better choice.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't depend on the object state so it can changed to a function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we have logistic sigmoid in sklearn.utils.extmath?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe call it logistic_sigmoid as sigmoid just refers to the shape....

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 @amueller. Drives me nuts when people around here simply call this "the sigmoid". :) The logistic function is its proper name.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@amueller

amueller commented Oct 3, 2012

Copy link
Copy Markdown
Member

@glouppe Afaik classification with RBMs basically doesn't work. Is there any particular reason you want it? Usually throwing the representation into a linear SVM is way better.

I'm a bit surprised that so many people want an RBM. I though we kind of didn't want "deep learning" stuff...
If I knew that I would have contributed one of my implementations ^^

An example would be great. Is there any application where we can demo that this works?
Maybe extracting features from digits and then classify? I guess that would train a while, though :-/

If we do include an RBM, it should definitely implement both CD1 and PCD.

Comment thread sklearn/rbm.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't h be sampled here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h is sampled for the persistent gibbs chain. For computing the learning statistics, by deriving the log probability w.r.t. the parameters you get a difference between free energy derivatives. Which results in using the mean field of the h's (see http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf page 64). When computing the learning statistics, it's mathematically valid and better to use the mean-field because it adds less noise to learning.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amueller Yoshua's book doesn't mention this AFAIK but this technique (replacing a sample with its expectation in a formula) is known as "Rao-Blackwellization", and it's trivial to demonstrate that it's still an unbiased estimator but with lower variance than the original sample-based estimate. See, for example, this tutorial.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dwf cool, I had somehow overlooked of that proof :).

On Wed, Oct 3, 2012 at 5:54 PM, David Warde-Farley <[email protected]

wrote:

In sklearn/rbm.py:

  •    v_pos: array-like, shape (n_samples, n_visibles)
    
  •    Returns
    

  •    pseudo_likelihood: array-like, shape (n_samples,), optional
    
  •        Pseudo Likelihood estimate for this batch.
    
  •    References
    

  •    [1] Tieleman, T. Training Restricted Boltzmann Machines using
    
  •        Approximations to the Likelihood Gradient. International Conference
    
  •        on Machine Learning (ICML) 2008
    
  •    """
    
  •    h_pos = self.mean_h(v_pos)
    
  •    v_neg = self.sample_v(self.h_samples)
    
  •    h_neg = self.mean_h(v_neg)
    

@amueller https://github.com/amueller Yoshua's book doesn't mention
this AFAIK but this technique (replacing a sample with its expectation in a
formula) is known as "Rao-Blackwellization", and it's trivial to
demonstrate that it's still an unbiased estimator but with lower variance
than the original sample-based estimate. See, for example, this tutorialhttp://www.cs.ubc.ca/%7Enando/papers/ita2010.pdf
.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1200/files#r1756078.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 10/03/2012 10:47 PM, Yann N. Dauphin wrote:

In sklearn/rbm.py:

  •    v_pos: array-like, shape (n_samples, n_visibles)
    
  •    Returns
    

  •    pseudo_likelihood: array-like, shape (n_samples,), optional
    
  •        Pseudo Likelihood estimate for this batch.
    
  •    References
    

  •    [1] Tieleman, T. Training Restricted Boltzmann Machines using
    
  •        Approximations to the Likelihood Gradient. International Conference
    
  •        on Machine Learning (ICML) 2008
    
  •    """
    
  •    h_pos = self.mean_h(v_pos)
    
  •    v_neg = self.sample_v(self.h_samples)
    
  •    h_neg = self.mean_h(v_neg)
    

h is sampled for the persistent gibbs chain. For computing the
learning statistics, by deriving the log probability w.r.t. the
parameters you get a difference between free energy derivatives. Which
results in using the mean field of the h's (see
http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf
http://www.iro.umontreal.ca/%7Ebengioy/papers/ftml_book.pdf page
64). When computing the learning statistics, it's mathematically valid
and better to use the mean-field because it adds less noise to learning.

—
Reply to this email directly or view it on GitHub
https://github.com/scikit-learn/scikit-learn/pull/1200/files#r1755979.

Thanks for the explanation. Makes sense as long as it is sampled again
for the MCMC chain as you do below.

@amueller

amueller commented Oct 3, 2012

Copy link
Copy Markdown
Member

I just saw that you do implement persistent CD. I guess having only this is fine.

@weilinear

Copy link
Copy Markdown
Member

Maybe we have have a pipeline connecting rbm and linearsvc to for an example and compare the result to using raw feature :)

Comment thread sklearn/rbm.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just call this learning_rate?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, this would be consistent with SGDClassifier.

@glouppe

glouppe commented Oct 3, 2012

Copy link
Copy Markdown
Contributor

@amueller Well, I was suggesting that because it nearly comes from free. It would have shown how RBM could be used in a stand-alone way, as a pure generative model. But I agree that using a RBM to generate features and then to feed them to another classifier is probably a better idea in terms of end accuracy.

I'm a bit surprised that so many people want an RBM. I though we kind of didn't want "deep learning" stuff...
If I knew that I would have contributed one of my implementations ^^

It happens that I came into the machine learning world through RBMs :) That's why I appreciate that model, though it's purely subjective.

@amueller

amueller commented Oct 3, 2012

Copy link
Copy Markdown
Member

@glouppe I also came to machine learning via RBMs and I really dislike them and I am convinced they don't work - though it's purely subjective ;)

@amueller

amueller commented Oct 3, 2012

Copy link
Copy Markdown
Member

@ynd Great job by the way! Looks very good :)

@glouppe

glouppe commented Oct 3, 2012

Copy link
Copy Markdown
Contributor

@amueller Haha :-) Actually, my experience with RBMs is limited to Netflix and to image datasets, were I found accuracy to be quite decent. However I confess that adjusting all the hyperparameters is a real nightmare. Maybe that's the reason why switched to ensemble methods?

@jaquesgrobler

Copy link
Copy Markdown
Member

Nice job on this. I actually worked a bit with @genji on a sklearn version of this.. In this case, it could be good if he could have a look at this. well done!

@GaelVaroquaux

Copy link
Copy Markdown
Member

@glouppe Afaik classification with RBMs basically doesn't work. Is there any
particular reason you want it? Usually throwing the representation into a
linear SVM is way better.

OK, we'll need an example showing this, hopefully with a pipeline.

@GaelVaroquaux

Copy link
Copy Markdown
Member

I'm a bit surprised that so many people want an RBM. I though we kind of didn't
want "deep learning" stuff...
If I knew that I would have contributed one of my implementations ^^

We're growing, I guess.

@amueller: if you have good implementation, you can probably give good
advice/good review on this PR. I have found that the best way to get good
code was to keep the good ideas from different codebases developed
independently.

@GaelVaroquaux

Copy link
Copy Markdown
Member

Nice job on this. I actually worked a bit with @genji on a sklearn version of
this..

You should give a pointer to the codebase.

@ogrisel

ogrisel commented Oct 3, 2012

Copy link
Copy Markdown
Member

It would be great if someone could benchmark this implementation against @dwf's gist: https://gist.github.com/359323 both in terms of CPU time till convergence, memory usage and ability to generate feature suitable for feeding to a linear classifier such as sklearn.linear_model.LinearSVC for instance. The dataset to use for this bench could be a subset of mnist (e.g. 2 digits such as 0 versus 8) to make it faster to evaluate.

@ogrisel

ogrisel commented Oct 3, 2012

Copy link
Copy Markdown
Member

BTW @ynd great to see you contributing to sklearn. I really enjoyed your NIPS presentation last year. Also it would be great to submit a sklearn version of your numpy CAE that includes the sampling trick in another PR :)

@ogrisel

ogrisel commented Oct 3, 2012

Copy link
Copy Markdown
Member

Nice job on this. I actually worked a bit with @genji on a sklearn version of this..

We would indeed appreciate @genji inputs on reviewing this PR and maybe point to common implementation pitfalls to avoid.

@amueller

amueller commented Oct 3, 2012

Copy link
Copy Markdown
Member

oh @ynd I didn't recognize you from picture. I think we talked quite a while at your poster last nips. After that, my lab started working on constrastive auto encoders! Your work is really interesting!

Comment thread sklearn/rbm.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to avoid acronyms so RestrictedBolzmannMachine sounds better.

Also, we may want to bootstrap the neural_network module.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, esp. if Contractive Autoencoders are to follow.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also thinking of the multi-layer perceptron, if @amueller feels motivated :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know, I should really look into that again... motivation level... not that high ;)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 'neural_network', or 'neural' module sounds really good.

@ogrisel Yes, Contractive Autoencoders are to follow! :)

@amueller There's a nice paper this year that makes MLPs much simpler to use, they show how to automatically tune the learning rate (http://arxiv.org/pdf/1206.1106v1). That only leaves the n_components hyper-parameter!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 'neural_network', or 'neural' module sounds really good.

@ogrisel https://github.com/ogrisel Yes, Contractive Autoencoders
are to follow! :)

@amueller https://github.com/amueller There's a nice paper this year
that makes MLPs much simpler to use, they show how to automatically
tune the learning rate (http://arxiv.org/pdf/1206.1106v1). That only
leaves the n_components hyper-parameter!

—

I saw the paper but didn't try it out yet. Have you given it a try?
By the way, that look a lot like RPROP, which we often use
(but is a lot less heuristic).

Do you think that would also be interesting for the SGD module?

@amueller

Copy link
Copy Markdown
Member

Thanks a lot for picking this up. Sorry we didn't work harder on merging it. It seems we are all a bit swamped right now. I'm certain it will go in the next release, though ;)

@vene

vene commented Apr 15, 2013

Copy link
Copy Markdown
Member

Wow, actually yesterday I was thinking that after the conference deadline
passes (which was last night) I wanna come back to this PR!

A while back in a local file, I hacked up a momentum implementation on top
of this code, it did seem to speed up convergence a lot on mnist,
interesting?

On Tue, Apr 16, 2013 at 5:27 AM, Andreas Mueller
[email protected]:

Thanks a lot for picking this up. Sorry we didn't work harder on merging
it. It seems we are all a bit swamped right now. I'm certain it will go in
the next release, though ;)

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1200#issuecomment-16409345
.

@amueller

Copy link
Copy Markdown
Member

@vene I would rather not add any features and merge this asap. It has been sitting around way to long! Do you have any idea what is still missing?

@vene

vene commented Apr 17, 2013

Copy link
Copy Markdown
Member

IIRC I was not pleased with the example when it was moved to the digits
dataset instead of mnist, as the dataset is very small and the components
don't look that meaningful. I tried toying around with the params to no
avail.

On Tue, Apr 16, 2013 at 6:37 PM, Andreas Mueller
[email protected]:

@vene https://github.com/vene I would rather not add any features and
merge this asap. It has been sitting around way to long! Do you have any
idea what is still missing?

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1200#issuecomment-16435278
.

@vene

vene commented Apr 17, 2013

Copy link
Copy Markdown
Member

Also there is a failing common test because of the way random_state is used.

@ogrisel

ogrisel commented Apr 18, 2013

Copy link
Copy Markdown
Member

@vene I you can come up with a quick PR vs this branch and show how that impacts the convergence speed and quality on mnist that sounds interesting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor parameters should not be mutated during fit and that holds for random_state as well. Please change this line to:

self.random_state_ = check_random_state(self.random_state)

or

random_state = check_random_state(self.random_state)

and then pass the random_state local variable explicitly as an argument to the subsequent private methods.

@amueller

amueller commented May 6, 2013

Copy link
Copy Markdown
Member

I'm very inclined to fix the travis tests and merge. Having "not completely satisfying example filters" doesn't justify delaying this PR any longer.

@vene

vene commented May 6, 2013

Copy link
Copy Markdown
Member

Probably a good idea, any speedups / new features can be added later.

On Mon, May 6, 2013 at 6:39 PM, Andreas Mueller [email protected]:

I'm very inclined to fix the travis tests and merge. Having "not
completely satisfying example filters" doesn't justify delaying this PR any
longer.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1200#issuecomment-17473458
.

@amueller

amueller commented May 6, 2013

Copy link
Copy Markdown
Member

Does any one have strong reasons not to merge this? (after fixing the random state issue)

@GaelVaroquaux

Copy link
Copy Markdown
Member

Some implicit castings: (I have a version numpy that purposely fails when
casting rules can induce problems)

======================================================================
FAIL: Doctest: sklearn.neural_network.rbm.BernoulliRBM
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/doctest.py", line 2201, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for
sklearn.neural_network.rbm.BernoulliRBM
  File "/home/varoquau/dev/scikit-learn/sklearn/neural_network/rbm.py",
line 31, in BernoulliRBM
----------------------------------------------------------------------
File "/home/varoquau/dev/scikit-learn/sklearn/neural_network/rbm.py",
line 78, in sklearn.neural_network.rbm.BernoulliRBM
Failed example:
    model.fit(X)  # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1289, in __run
        compileflags, 1) in test.globs
      File "", line
1, in 
        model.fit(X)  # doctest: +ELLIPSIS
      File
"/home/varoquau/dev/scikit-learn/sklearn/neural_network/rbm.py", line
320, in fit
        pl_batch = self._fit(X[inds[minibatch::n_batches]])
      File
"/home/varoquau/dev/scikit-learn/sklearn/neural_network/rbm.py", line
252, in _fit
        v_pos *= lr
    TypeError: Cannot cast ufunc multiply output from dtype('float64') to
dtype('int64') with casting rule 'same_kind'
>>  raise self.failureException(self.format_failure(>  instance at 0x9529a70>.getvalue()))
    
----------------------------------------------------------------------

@GaelVaroquaux

Copy link
Copy Markdown
Member

Some implicit castings: (I have a version numpy that purposely fails when
casting rules can induce problems)

I have fixed that in the pr_1200 branch on my github (it was preventing
me from reviewing this PR). Please pull/cherry-pick

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the above paragraph can be much shortened. I don't see how it is useful to the end user.

@GaelVaroquaux

Copy link
Copy Markdown
Member

Does any one have strong reasons not to merge this?

Plenty. I am doing a quick review, and it is not ready. The review will
come in later, but I am convinced that there still is some work to be
done here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.random_state cannot be a rng object, because it would mean modifying the input parameter. You need to create a shadow self.random_state_ object, as done in the other learners.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or better, pass the random state as an argument to the method.
On May 7, 2013 6:33 AM, "Gael Varoquaux" [email protected] wrote:

In sklearn/neural_network/rbm.py:

  •    Compute the element-wise binomial using the probabilities p.
    
  •    Parameters
    

  •    x: array-like, shape (M, N)
    
  •    Notes
    

  •    This is equivalent to calling numpy.random.binomial(1, p) but is
    
  •    faster because it uses in-place operations on p.
    
  •    Returns
    

  •    x_new: array-like, shape (M, N)
    
  •    """
    
  •    p[self.random_state.uniform(size=p.shape) < p] = 1.
    

self.random_state cannot be a rng object, because it would mean modifying
the input parameter. You need to create a shadow self.random_state_ object,
as done in the other learners.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1200/files#r4102207
.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or better, pass the random state as an argument to the method.

+1. But the random_state attribute should not be modified anyhow.

@GaelVaroquaux

Copy link
Copy Markdown
Member

I have made a few minor changes on my pr_1200 branch.

A few general comments (it seems that this PR lack a bit of polish and I
am not convinced that it is mergeable from a user stand point):

The docs contain a lot of math, but lack intuitive messages. Most
importantly, the RBM section does not tell me why and when I should be
using RBMs.

Examples are not linked to in the docs. The docs do not have a figure.
They feel a bit more like a page from a textbook. For instance the remark
on 'Deep neural networks that are notoriously difficult to train from
scratch can be simplified by initializing each layer’s weights with the
weights of an RBM.' What is a user going to do with this remark: we don't
have deep neural networks in scikit-learn. There is too much maths and
not enough intuitions/practical advice.

The only example is not a 'plot_' example. It does not help understanding
how the RBM work nor does it demonstrate their benefits on the rendered
docs. It also takes ages to run. This long run time is strong suboptimal,
as there is a grid-search object that refits the RBM many times with
unchanged parameters. To make it faster, I have hardcoded some values
obtained by a grid search. I also added some plotting.

I am also worried about the amount of methods of the object. Have we
checked for redundancy in the names of the methods? I see a Gibbs
sampling method. Other objects also have sampling methods. We should make
sure that the names and signature of these methods are compatible.

As a side note, after playing with this code, I am not terribly impressed
by deep learning as black-box learners. :P

@larsmans

larsmans commented May 6, 2013

Copy link
Copy Markdown
Member

(Please disregard previous comment)

I agree with @GaelVaroquaux that there are far too many public methods.

@dwf

dwf commented May 6, 2013

Copy link
Copy Markdown
Member

I haven't been following this all that closely, but the narrative docs appear to disagree with the implementation. The implementation uses stochastic maximum likelihood, which uses an unbiased estimator of the maximum likelihood gradient, not contrastive divergence (which the documentation seems to be describing). If the primary utility to scikit-learn users is that of feature extraction, I'd question whether an SML-based implementation is a good choice. CD tends to learn better features.

As a side note, after playing with this code, I am not terribly impressed by deep learning as black-box learners. :P

We'll make a believer out of you yet Gael!

@vene

vene commented May 7, 2013

Copy link
Copy Markdown
Member

The implementation uses stochastic maximum likelihood, which uses an unbiased estimator
of the maximum likelihood gradient, not contrastive divergence (which the documentation
seems to be describing).

Is not Persistent CD a synonym for SML? In the "SML Learning" section I described the CD algorithm first and then PCD as a variation, because I found it difficult to justify PCD by itself without contrasting with CD. If I am factually incorrect could you please push me in the right direction?

There is too much maths and not enough intuitions/practical advice.

I tried to push the maths as far down as possible and to lead with intuitions, but I don't know any more intuitions than what I put down. I agree the docs are lacking but I really don't know what to write to improve them. As a black-box learner RBMs should just be used in a simple pipeline before a classifier and hope for the best.

The figure plotted by the example should indeed be in the docs. I was very unsatisfied with the way the example looks on the digit dataset, compared to it looking good on mnist, I tried to find good values but failed. I was thinking whether it would be better to use mnist and keep it as a pregenerated example.

@amueller

amueller commented May 7, 2013

Copy link
Copy Markdown
Member

Ok, I'll try to work on docs and interfaces. First I want to have a look at @jnothman's grid-search work, though...

@GaelVaroquaux

Copy link
Copy Markdown
Member

Ok, I'll try to work on docs and interfaces.

The most worrying thing is the example: I haven't been convinced that it
does better than a K-means to extract mid-level features.

G

@amueller

amueller commented May 7, 2013

Copy link
Copy Markdown
Member

I don't think that you can say that it is better than k-means in general.
Showing that RBMs work needs a large dataset and tuning. We can try on MNIST.

I don't think the goal of the example should be to show that it works well, ratherit should be how to use it.
The literature shows that there are cases in which it works. Reproducing them (in particular using just a CPU) is non-trivial and time-consuming.

@GaelVaroquaux

Copy link
Copy Markdown
Member

Showing that RBMs work needs a large dataset and tuning. We can try on
MNIST.

That must cost an arm and a leg!

I don't think the goal of the example should be to show that it works
well, ratherit should be how to use it.

Indeed. I think that the example on my pr_1200 branch does that, however when I see it, I cannot help thinking of k-means.

The literature shows that there are cases in which it works.

The older I get, the less I trust the literature :)

Reproducing them (in particular using just
a CPU) is non-trivial and time-consuming.

We should do a quick check to see if this implementation can be sped up: I find it slow on a simple problem.

@vene

vene commented May 7, 2013

Copy link
Copy Markdown
Member

The older I get, the less I trust the literature :)

Totally understandable, but maybe this shouldn't be used as an argument
against merging. It seems that people are interested in trying these kind
of models. I think it's better to provide it, and make it obvious how easy
it is to replace it with something simpler by giving it the same API and
letting people see by themselves that for many problems, KMeans or Random
Projections extract better features than complicated and slow
architectures. If users manage to use it well, that's great! If users use
it wrongly, it's not much different than if they misuse any other of our
estimators, is it?

We should do a quick check to see if this implementation can be sped up: I
find it slow on a simple problem.

An algorithmic speedup would be momentum, in this case.

@amueller, I'd love to help with what I can (maybe API cleanup) but I might
step on your toes if you're on this, especially since the branch is @ynd's
at the moment. What could I do?

@GaelVaroquaux

Copy link
Copy Markdown
Member

The older I get, the less I trust the literature :)

Totally understandable, but maybe this shouldn't be used as an argument
against merging.

Agreed. I am not voting against a merge in the long run. I think that
they are still a few minor improvements to be done before a merge.

We should do a quick check to see if this implementation can be sped up: I
find it slow on a simple problem.

An algorithmic speedup would be momentum, in this case.

OK, that would be fantastic, but if it requires a lot of work, we should
maybe do it in a 2nd PR.

@amueller

amueller commented May 7, 2013

Copy link
Copy Markdown
Member

@vladn feel free to go ahead, preferably in a second pr to master, i think. this is not my highest priority but i want to get it done soonish..

Vlad Niculae [email protected] schrieb:

The older I get, the less I trust the literature :)

Totally understandable, but maybe this shouldn't be used as an argument
against merging. It seems that people are interested in trying these
kind
of models. I think it's better to provide it, and make it obvious how
easy
it is to replace it with something simpler by giving it the same API
and
letting people see by themselves that for many problems, KMeans or
Random
Projections extract better features than complicated and slow
architectures. If users manage to use it well, that's great! If users
use
it wrongly, it's not much different than if they misuse any other of
our
estimators, is it?

We should do a quick check to see if this implementation can be sped
up: I
find it slow on a simple problem.

An algorithmic speedup would be momentum, in this case.

@amueller, I'd love to help with what I can (maybe API cleanup) but I
might
step on your toes if you're on this, especially since the branch is
@ynd's
at the moment. What could I do?


Reply to this email directly or view it on GitHub:
#1200 (comment)

Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

@vene

vene commented May 9, 2013

Copy link
Copy Markdown
Member

Moved to PR #1954, closing this one.
Posting here so people get pinged.
@dwf, could you help me understand the PCD-SML issue discussed above?

@vene vene closed this May 9, 2013
@dwf

dwf commented May 10, 2013

Copy link
Copy Markdown
Member

Sure, I need to have a closer look at the narrative docs.

On Thu, May 9, 2013 at 10:23 AM, Vlad Niculae [email protected]:

Moved to PR #1954#1954,
closing this one.
Posting here so people get pinged.
@dwf https://github.com/dwf, could you help me understand the PCD-SML
issue discussed above?

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1200#issuecomment-17666810
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.