Skip to content

Add synthetic datasets - #5315

Merged
martinwicke merged 9 commits into
tensorflow:masterfrom
z-a-f:add-synthetic-datasets
Dec 13, 2016
Merged

martinwicke merged 9 commits into
tensorflow:masterfrom
z-a-f:add-synthetic-datasets

Conversation

@z-a-f

@z-a-f z-a-f commented Nov 1, 2016 •

Copy link
Copy Markdown

This is only one possible synthetic dataset. Following methods added + sample code:

import tensorflow as tf

# Create synthetic data:
## Generic make_synthetic wrapper routine
circles = tf.contrib.learn.datasets.make_synthetic(name='circles', n_samples=1000, noise=0.1)

Files modified/added:

  • /.gitignore: **/tools/git/gen is not necessary to commit (for dev only)
  • /tensorflow/contrib/learn/python/learn/datasets/__init__.py: Added the support for make_synthetic and split_data
  • /tensorflow/contrib/learn/python/learn/datasets/base.py: Added new method split_into_train_and_test
  • /tensorflow/contrib/learn/python/learn/datasets/synthetic.py: Created a file to hold all synthetic generators

@tensorflow-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@mention-bot

Copy link
Copy Markdown

@zafartahirov, thanks for your PR! By analyzing the history of the files in this pull request, we identified @ilblackdragon, @tensorflower-gardener and @keveman to be potential reviewers.

@z-a-f

z-a-f commented Nov 1, 2016

Copy link
Copy Markdown
Author

Sorry about two commits -- should have rebased it before pushing

@vrv vrv added the awaiting review Pull request awaiting review label Nov 1, 2016
@z-a-f

z-a-f commented Nov 1, 2016

Copy link
Copy Markdown
Author

BTW, an unrelated question, what is TFs and Google's policy on rebasing the commits -- do I have to rebase to the current origin/HEAD before submitting a PR? Also, do I need to squash intermediate (minor) commits? Sorry, I am new to TF contributions, and don't know where to find these answers

@ilblackdragon ilblackdragon left a comment

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.

On your contribution questions:
When we merge in - we are going to squash all commits and rebase it on head, but for this your code needs to be cleanly applied (e.g. right now that would fail).

print('Successfully downloaded', filename, size, 'bytes.')
return filepath

def split_into_train_and_test(dataset, test_ratio=0.3, shuffle=False):

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.

we have this function here - https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/estimators/_sklearn.py#L168 if you want to just pull it out from there to here and refer from _sklearn part - would be great.

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.

I am not sure I understand the comment -- should I pull the splitting routine from the _sklearn completely and place it here, or should I just refer to _sklearn from here.

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.

Pull it out and place it here (and just refer from there).

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.

I have not touched the file in the _sklearn -- There are some compatibility issues, namely:
-- _sklearn._train_test_split expects variable arguments, and uses .take() to extract the values. Current implementation expects base.Dataset as an imput. If I replace it with the implementation in this PR, it will break any other codes.
-- _sklearn._train_test_split returns tuples, while the contrib.learn methods return either base.Dataset or base.Datasets, which are not iterable per se.

I could completely nuke the _sklearn method, but it is potentially dangerous. Please, advise

else:
return DATASETS[name]()

def make_synthetic(name='circles', n_samples=100, noise=None, *args, **kwargs):

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.

let's not have name with default value.

Comment thread .gitignore Outdated
/util/python/python_lib
/pip_test
/_python_build
**/tools/git/gen

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.

hm, is this really needed?

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.

For some reason the gen folder is being generated on my machine, and it is pointing to my .git folder

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'm just not sure it should be in the general .gitignore. You can just add this to your local .git/info/exclude

"""Creates binary synthetic datasets

Args:
name: Name of the dataset to generate (optional, str, default='circles')

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.

usually we write comments like this name: str, name of the dataset to generate.
(the optional and default are easily readable from the function's definition)

- Note that the `noise` parameter uses `numpy.random.normal` and depends on `numpy`'s seed

TODO:
- Support custom seed for replicability

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 would add this now - and set it by default to some number.

TODO:
- Support custom seed for replicability
- Support multiclass datasets
- Need shuffling routine. Currently synthetic datasets are reshuffled to avoid train/test correlation,

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.

nothing to change, but tf.learn automatically shuffle training data when fit is called.

@ilblackdragon ilblackdragon added stat:awaiting response Status - Awaiting response from author and removed awaiting review Pull request awaiting review labels Nov 1, 2016
@z-a-f

z-a-f commented Nov 2, 2016 •

Copy link
Copy Markdown
Author

@ilblackdragon -- Will fix the CL over the weekend

@z-a-f

z-a-f commented Nov 5, 2016

Copy link
Copy Markdown
Author

I have gone through the comments by @ilblackdragon and fixed most of them. The one I didn't touch is in the inline comments for the code.

I have also included some unittests

@z-a-f z-a-f mentioned this pull request Nov 6, 2016
@z-a-f

z-a-f commented Nov 7, 2016

Copy link
Copy Markdown
Author

@ilblackdragon I have covered your reviews (all except one), also included a new routine -- spiral generation, and placed unittests.

@z-a-f

z-a-f commented Nov 10, 2016

Copy link
Copy Markdown
Author

Done with all changes

@ilblackdragon I have removed the train_test_split routine -- I don't think it is required for this PR as it is not used anywhere.

@ilblackdragon ilblackdragon left a comment

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.

Sorry for late reply. Few more comments, otherwise looks good.

# ==============================================================================

"""Module includes reference datasets and utilities to load datasets."""
"""Module includes reference datasets and utilities to load datasets. It also

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.

first line of comments in modules (and functions) should be one line, you rephrase to something like:
Dataset utilities and synthetic/reference datasets.

srcs = ["load_csv_test.py"],
srcs = [
"load_csv_test.py",
"synthetic_test.py"

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.

can you please split this into two tests in build file?
it's preferred to have tests separate to allow better parallelism.

return DATASETS[name](size, test_with_fake_data)
else:
return DATASETS[name]()

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.

nit: two new lines.

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.

what's nit - Unit of entropy? Sorry, was trying to find it, but the only thing comes to mind is "not important thing"?

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.

nit - is "nitpicking", picking to small things. we use it apologize for nitpicking to style (giving Google code style requirements, like 2 lines between functions/classes, spaces etc)

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.

LOL tnx!

# limitations under the License.
# ==============================================================================

"""Module includes reference datasets and utilities to load datasets. It also

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.

here probably should be just Synthetic dataset generators.

if noise is not None:
X += np.random.normal(scale=noise, size=X.shape)
return Dataset(data=X[indices], target=y[indices])

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.

two new lines between functions (and same below)

class SyntheticTest(tf.test.TestCase):
"""Test synthetic dataset generation

TODO (tests):

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.

May be something?

TODO: Added tests for next cases:
   -
   -

we usually use TODO(username) so currently it refers to user 'tests' :)

@z-a-f z-a-f Nov 14, 2016 •

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.

Oh woops! :) I completely removed it - I forgot it was a list for myself for corner cases

@z-a-f

z-a-f commented Nov 27, 2016

Copy link
Copy Markdown
Author

@ilblackdragon Can you please check it again, I submitted the CL

@ilblackdragon

Copy link
Copy Markdown
Contributor

@tensorflow-jenkins Test this please

@z-a-f

z-a-f commented Nov 28, 2016

Copy link
Copy Markdown
Author

Oh snap! I am on it!

@z-a-f

z-a-f commented Nov 28, 2016

Copy link
Copy Markdown
Author

For some reason it passes all the tests on my machine -- going to rebase it to the HEAD, and see if anything new is breaking it. Is there any way I could get the Travis' logs to see what exactly fails?

@martinwicke

Copy link
Copy Markdown
Member

It's a python3 error, and an easy fix. Look at the full log here:
https://ci.tensorflow.org/job/tensorflow-pull-requests-cpu-python3/2439/consoleFull

If you want to check locally, make sure to configure and run using python3.

@z-a-f

z-a-f commented Nov 29, 2016

Copy link
Copy Markdown
Author

@martinwicke Thanks for pointing out the Python 3 issue, it was a minor iteritems problem -- fixed it, hope Jenkins has six installed.

@martinwicke @ilblackdragon That actually raises a question -- is it possible to have tensorflow-devel compiled for both Py2 and Py3 in the same location? Or do I have to maintain two different locations on my machine if I want to test both? In my case I had it compiled for Py2 before, and had to reconfigure and rebuild for Py3 because bazel test --force_python=py3 --host_force_python=py3 --define PYTHON_BIN_PATH=/usr/local/bin/python3 //tensorflow/contrib/learn/python/learn/datasets:synthetic_test was throwing a *.so Symbol not found error. Now I am rebuilding it back to Py2 because all my other scripts are using Py2.

@teamdandelion

Copy link
Copy Markdown

@tensorflow-jenkins Test this please

@z-a-f

z-a-f commented Nov 30, 2016

Copy link
Copy Markdown
Author

OK, I don't think this is something I can fix -- there is a problem with git fetch on the remote machine. Wild guess -- a problem with web-hook?

@martinwicke

Copy link
Copy Markdown
Member

@martinwicke martinwicke added awaiting testing (then merge) and removed stat:awaiting response Status - Awaiting response from author labels Nov 30, 2016
@z-a-f

z-a-f commented Dec 6, 2016

Copy link
Copy Markdown
Author

@danmane I think this once could be merged -- Thank you!

@martinwicke
martinwicke merged commit ca29fa3 into tensorflow:master Dec 13, 2016
@martinwicke

Copy link
Copy Markdown
Member

Thanks for this!

@suiyuan2009

suiyuan2009 commented Dec 13, 2016 •

Copy link
Copy Markdown
Contributor

I got ImportError: cannot import name synthetic when start tensorboard, I'm using the latest code. synthetic.py should be declared in BUILD file.

caisq added a commit to caisq/tensorflow that referenced this pull request Dec 13, 2016
This reverts commit ca29fa3.

Reason for rollback: Broke builds due to errors such as:

File
"/workspace/pip_test/venv/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/__init__.py",
line 29, in <module>
    from tensorflow.contrib.learn.python.learn.datasets import synthetic
    ImportError: cannot import name synthetic
caisq added a commit that referenced this pull request Dec 13, 2016
martinwicke pushed a commit that referenced this pull request Dec 16, 2016
@z-a-f
z-a-f deleted the add-synthetic-datasets branch December 21, 2016 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants