Look for it as if it was a full path, if not, try local file, if not try in the data directory. Download dataset if it is not present
(dataset, default_dataset, origin)
| 52 | |
| 53 | |
| 54 | def get_dataset_file(dataset, default_dataset, origin): |
| 55 | '''Look for it as if it was a full path, if not, try local file, |
| 56 | if not try in the data directory. |
| 57 | |
| 58 | Download dataset if it is not present |
| 59 | |
| 60 | ''' |
| 61 | data_dir, data_file = os.path.split(dataset) |
| 62 | if data_dir == "" and not os.path.isfile(dataset): |
| 63 | # Check if dataset is in the data directory. |
| 64 | new_path = os.path.join( |
| 65 | os.path.split(__file__)[0], |
| 66 | "..", |
| 67 | "data", |
| 68 | dataset |
| 69 | ) |
| 70 | if os.path.isfile(new_path) or data_file == default_dataset: |
| 71 | dataset = new_path |
| 72 | |
| 73 | if (not os.path.isfile(dataset)) and data_file == default_dataset: |
| 74 | from six.moves import urllib |
| 75 | print('Downloading data from %s' % origin) |
| 76 | urllib.request.urlretrieve(origin, dataset) |
| 77 | |
| 78 | |
| 79 | return dataset |
| 80 | |
| 81 | |
| 82 | def load_data(path="imdb.pkl", n_words=100000, valid_portion=0.1, maxlen=None, |