Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[joss] feature request: accessible utility to import a dataset #19

Closed
hbaniecki opened this issue Nov 24, 2021 · 4 comments
Closed

[joss] feature request: accessible utility to import a dataset #19

hbaniecki opened this issue Nov 24, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@hbaniecki
Copy link
Contributor

hbaniecki commented Nov 24, 2021

openjournals/joss-reviews#3934

This package has good documentation. Going through the examples I came up with a feature request, which would greatly benefit introducing newcomers and prototyping code.

I like the first example in README to be straightforward and copy-paste ready, which is not the case here (looking at missing code ...).

How about implementing some import_dataset(url) / download(url) functionality in utils or Dataset that would, for example, download the dataset .zip file and unpack it (sample code) so that one can load the data into exemplary code:

from pyss3 import SS3

Dataset.import_dataset("https://github.com/sergioburdisso/pyss3/blob/master/examples/datasets/movie_review.zip")
x_train, y_train = Dataset.load_from_files("movie_review/train")
x_test, y_test = Dataset.load_from_files("movie_review/test")

clf = SS3()
clf.fit(x_train, y_train)
y_pred = clf.predict(x_test)

Implementation details and naming may vary, but it would be nice to easily run code from README.

@sergioburdisso sergioburdisso added the enhancement New feature or request label Nov 24, 2021
@sergioburdisso
Copy link
Owner

Hi again @hbaniecki!

Wow, this is an amazing idea 👏👏👏

What do you think if adding a method called load_from_url() to the Dataset class, which would do the same thing as the current Dataset.load_from_files() but instead of loading the dataset from disk, it will do it from an URL, as you suggested.

Perhaps load_from_url() should take two arguments, load_from_url(url, folder=None), first the url from which to download the zipped dataset and secondly, an optional argument called something like folder that let the user to specify a particular folder to use from inside the zipped dataset. The example would end up being something like:

from pyss3 import SS3

x_train, y_train = Dataset.load_from_url("https://url/to/movie_review.zip", "train")
x_test, y_test = Dataset.load_from_url("https://url/to/movie_review.zip", "test")

clf = SS3()
clf.fit(x_train, y_train)
y_pred = clf.predict(x_test)

What do you think?
(Again, thank you for this suggestion, I think it is an awesome idea 💪😎👍)

@hbaniecki
Copy link
Contributor Author

hbaniecki commented Nov 25, 2021

Thanks! If the data won't be saved on disk and only loaded into x_train, y_train etc. then load_from_url(url, folder=None) makes perfect sense.

sergioburdisso added a commit that referenced this issue Dec 4, 2021
Now datasets can be directly loaded via a given url, not only from disk.
To achieve this, two methods have been added to ``Dataset`` class:

 - ``Dataset.load_from_url(...)``
 - ``Dataset.load_from_url_multilabel(...)``

These methods download and extract the zip file (given by the  url)
into the system's temporary folder and then calls
``Dataset.load_from_files()`` to load it
(or ``Dataset.load_from_files_multilabel()``, respectively).

Note: If the same url is used consecutively, the already downloaded
files will be used as a cache (to avoid downloading and extracting
them again).

Resolves: #19
sergioburdisso added a commit that referenced this issue Dec 4, 2021
sergioburdisso added a commit that referenced this issue Dec 4, 2021
@sergioburdisso
Copy link
Owner

sergioburdisso commented Dec 4, 2021

Hi @hbaniecki! sorry for the delay, I just had to wait for the weekend to get down on this. I've added the suggested methods and also updated the README.md. Just check it out and let me know if everthing is OK 💪 🤓 👍

Below I'm pasting the commit message that marked this issue as closed:

Now datasets can be directly loaded via a given url, not only from disk.
To achieve this, two methods have been added to Dataset class:

  • Dataset.load_from_url(...)
  • Dataset.load_from_url_multilabel(...)

These methods download and extract the zip file (given by the url)
into the system's temporary folder and then call
Dataset.load_from_files() to load it
(or Dataset.load_from_files_multilabel(), respectively).

Note: If the same url is used consecutively, the already downloaded
files will be used as a cache (to avoid downloading and extracting
them again).

@hbaniecki
Copy link
Contributor Author

No worries. Thanks! Works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants