Ниже приведен код для проблемы классификации текста в наборе данных IMDB. Я не могу запустить код, так как он показывает ошибку, приведенную ниже. Пожалуйста, помогите мне с этим. Заранее спасибо.
КОД:
from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Dense, Embedding, Conv1D, GlobalMaxPooling1D
from keras.datasets import imdb
max_features = 5000
maxlen = 100
batch_size = 64
embedding_dims = 16
filters = 128
kernel_size = 3
epochs = 5
(x_train, y_train), (_, _) = imdb.load_data(num_words = max_features)
x_train = sequence.pad_sequences(x_train, maxlen = maxlen)
print(len(x_train))
for sample in x_train :
print(sample)
model = Sequential()
model.add(Embedding(max_features, embedding_dims, input_length = maxlen))
model.add(Conv1D(filters, kernel_size, padding = 'valid', activation = 'relu', strides = 1))
model.add(GlobalMaxPooling1D())
model.add(Dense(128, activation = 'relu'))
model.add(Dense(1, activation = 'sigmoid'))
model.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['acc'])
model.fit(x_train, y_train, batch_size = batch_size, epochs = epochs)
ОШИБКА:
Downloading data from https://s3.amazonaws.com/text-datasets/imdb.npz
---------------------------------------------------------------------------
TimeoutError Traceback (most recent call last)
~\Anaconda3\lib\urllib\request.py in do_open(self, http_class, req, **http_conn_args)
1316 h.request(req.get_method(), req.selector, req.data, headers,
-> 1317 encode_chunked=req.has_header('Transfer-encoding'))
1318 except OSError as err: # timeout error
~\Anaconda3\lib\http\client.py in request(self, method, url, body, headers, encode_chunked)
1228 """Send a complete request to the server."""
-> 1229 self._send_request(method, url, body, headers, encode_chunked)
1230
~\Anaconda3\lib\http\client.py in _send_request(self, method, url, body, headers, encode_chunked)
1274 body = _encode(body, 'body')
-> 1275 self.endheaders(body, encode_chunked=encode_chunked)
1276
~\Anaconda3\lib\http\client.py in endheaders(self, message_body, encode_chunked)
1223 raise CannotSendHeader()
-> 1224 self._send_output(message_body, encode_chunked=encode_chunked)
1225
~\Anaconda3\lib\http\client.py in _send_output(self, message_body, encode_chunked)
1015 del self._buffer[:]
-> 1016 self.send(msg)
1017
~\Anaconda3\lib\http\client.py in send(self, data)
955 if self.auto_open:
--> 956 self.connect()
957 else:
~\Anaconda3\lib\http\client.py in connect(self)
1383
-> 1384 super().connect()
1385
~\Anaconda3\lib\http\client.py in connect(self)
927 self.sock = self._create_connection(
--> 928 (self.host,self.port), self.timeout, self.source_address)
929 self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
~\Anaconda3\lib\socket.py in create_connection(address, timeout, source_address)
726 if err is not None:
--> 727 raise err
728 else:
~\Anaconda3\lib\socket.py in create_connection(address, timeout, source_address)
715 sock.bind(source_address)
--> 716 sock.connect(sa)
717 # Break explicitly a reference cycle
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because connected host has failed to
respond
During handling of the above exception, another exception occurred:
URLError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\keras\utils\data_utils.py in get_file(fname, origin, untar, md5_hash,
file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
221 try:
--> 222 urlretrieve(origin, fpath, dl_progress)
223 except HTTPError as e:
~\Anaconda3\lib\urllib\request.py in urlretrieve(url, filename, reporthook, data)
246
--> 247 with contextlib.closing(urlopen(url, data)) as fp:
248 headers = fp.info()
~\Anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
223
~\Anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
524
--> 525 response = self._open(req, data)
526
~\Anaconda3\lib\urllib\request.py in _open(self, req, data)
542 result = self._call_chain(self.handle_open, protocol, protocol +
--> 543 '_open', req)
544 if result:
~\Anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
502 func = getattr(handler, meth_name)
--> 503 result = func(*args)
504 if result is not None:
~\Anaconda3\lib\urllib\request.py in https_open(self, req)
1359 return self.do_open(http.client.HTTPSConnection, req,
-> 1360 context=self._context, check_hostname=self._check_hostname)
1361
~\Anaconda3\lib\urllib\request.py in do_open(self, http_class, req, **http_conn_args)
1318 except OSError as err: # timeout error
-> 1319 raise URLError(err)
1320 r = h.getresponse()
URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not
properly respond after a period of time, or established connection failed because connected host has
failed to respond>
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
<ipython-input-16-82c1e9073098> in <module>
8 epochs = 5
9
---> 10 (x_train, y_train), (_, _) = imdb.load_data(num_words = max_features)
11
12 x_train = sequence.pad_sequences(x_train, maxlen = maxlen)
~\Anaconda3\lib\site-packages\keras\datasets\imdb.py in load_data(path, num_words, skip_top, maxlen,
seed, start_char, oov_char, index_from, **kwargs)
55 path = get_file(path,
56 origin='https://s3.amazonaws.com/text-datasets/imdb.npz',
---> 57 file_hash='599dadb1135973df5b59232a0e9a887c')
58 with np.load(path) as f:
59 x_train, labels_train = f['x_train'], f['y_train']
~\Anaconda3\lib\site-packages\keras\utils\data_utils.py in get_file(fname, origin, untar, md5_hash,
file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
224 raise Exception(error_msg.format(origin, e.code, e.msg))
225 except URLError as e:
--> 226 raise Exception(error_msg.format(origin, e.errno, e.reason))
227 except (Exception, KeyboardInterrupt):
228 if os.path.exists(fpath):
Exception: URL fetch failure on https://s3.amazonaws.com/text-datasets/imdb.npz: None -- [WinError 10060]
Попытка подключения не удалось, потому что подключенная сторона не ответила должным образом через некоторое время,
или не удалось установить соединение, так как подключенный хост не смог ответить