Repository navigation
Conversation
|
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... |
|
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 Also, do you intend to handle missing values? (since you motivate your PR with Netflix) |
There was a problem hiding this comment.
In scikit-learn, we are used to put a trailing underscore to all fitted attributes (self.W_).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
In PCA, a related attribute is components_.
|
Thanks for the contribution - I'm super excited - can't wait to see this merged to master! |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This method doesn't depend on the object state so it can changed to a function.
There was a problem hiding this comment.
Shouldn't we have logistic sigmoid in sklearn.utils.extmath?
There was a problem hiding this comment.
maybe call it logistic_sigmoid as sigmoid just refers to the shape....
There was a problem hiding this comment.
+1 @amueller. Drives me nuts when people around here simply call this "the sigmoid". :) The logistic function is its proper name.
|
@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... An example would be great. Is there any application where we can demo that this works? If we do include an RBM, it should definitely implement both CD1 and PCD. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
@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,), optionalPseudo Likelihood estimate for this batch.
References
[1] Tieleman, T. Training Restricted Boltzmann Machines usingApproximations to the Likelihood Gradient. International Conferenceon 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.
There was a problem hiding this comment.
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,), optionalPseudo Likelihood estimate for this batch.
References
[1] Tieleman, T. Training Restricted Boltzmann Machines usingApproximations to the Likelihood Gradient. International Conferenceon 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.
|
I just saw that you do implement persistent CD. I guess having only this is fine. |
|
Maybe we have have a pipeline connecting rbm and linearsvc to for an example and compare the result to using raw feature :) |
There was a problem hiding this comment.
maybe just call this learning_rate?
There was a problem hiding this comment.
+1, this would be consistent with SGDClassifier.
|
@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.
It happens that I came into the machine learning world through RBMs :) That's why I appreciate that model, though it's purely subjective. |
|
@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 ;) |
|
@ynd Great job by the way! Looks very good :) |
|
@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? |
|
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! |
OK, we'll need an example showing this, hopefully with a pipeline. |
We're growing, I guess. @amueller: if you have good implementation, you can probably give good |
You should give a pointer to the codebase. |
|
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 |
|
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! |
There was a problem hiding this comment.
We try to avoid acronyms so RestrictedBolzmannMachine sounds better.
Also, we may want to bootstrap the neural_network module.
There was a problem hiding this comment.
+1, esp. if Contractive Autoencoders are to follow.
There was a problem hiding this comment.
I was also thinking of the multi-layer perceptron, if @amueller feels motivated :)
There was a problem hiding this comment.
Yeah, I know, I should really look into that again... motivation level... not that high ;)
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
|
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 ;) |
|
Wow, actually yesterday I was thinking that after the conference deadline A while back in a local file, I hacked up a momentum implementation on top On Tue, Apr 16, 2013 at 5:27 AM, Andreas Mueller
|
|
@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? |
|
IIRC I was not pleased with the example when it was moved to the digits On Tue, Apr 16, 2013 at 6:37 PM, Andreas Mueller
|
|
Also there is a failing common test because of the way |
|
@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. |
There was a problem hiding this comment.
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.
|
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. |
|
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]:
|
|
Does any one have strong reasons not to merge this? (after fixing the random state issue) |
|
Some implicit castings: (I have a version numpy that purposely fails when ======================================================================
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()))
----------------------------------------------------------------------
|
I have fixed that in the pr_1200 branch on my github (it was preventing |
There was a problem hiding this comment.
I think that the above paragraph can be much shortened. I don't see how it is useful to the end user.
Plenty. I am doing a quick review, and it is not ready. The review will |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 isfaster 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
.
There was a problem hiding this comment.
Or better, pass the random state as an argument to the method.
+1. But the random_state attribute should not be modified anyhow.
|
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 The docs contain a lot of math, but lack intuitive messages. Most Examples are not linked to in the docs. The docs do not have a figure. The only example is not a 'plot_' example. It does not help understanding I am also worried about the amount of methods of the object. Have we As a side note, after playing with this code, I am not terribly impressed |
|
(Please disregard previous comment) I agree with @GaelVaroquaux that there are far too many public methods. |
|
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.
We'll make a believer out of you yet Gael! |
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?
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. |
|
Ok, I'll try to work on docs and interfaces. First I want to have a look at @jnothman's grid-search work, though... |
The most worrying thing is the example: I haven't been convinced that it G |
|
I don't think that you can say that it is better than k-means in general. I don't think the goal of the example should be to show that it works well, ratherit should be how to use it. |
That must cost an arm and a leg!
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 older I get, the less I trust the literature :)
We should do a quick check to see if this implementation can be sped up: I find it slow on a simple problem. |
Totally understandable, but maybe this shouldn't be used as an argument
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 |
Agreed. I am not voting against a merge in the long run. I think that
OK, that would be fantastic, but if it requires a lot of work, we should |
|
@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:
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet. |
|
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]:
|
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