小编Har*_*ett的帖子

在 keras.preprocessing.text 中使用 Tokenizer 时内存不足

我想使用 keras 构建一个 RNN 模型来对句子进行分类。

我尝试了以下代码:

docs = []
with open('all_dga.txt', 'r') as f:
    for line in f.readlines():
        dga_domain, _ = line.split(' ')
        docs.append(dga_domain)

t = Tokenizer()
t.fit_on_texts(docs)
encoded_docs = t.texts_to_matrix(docs, mode='count')
print(encoded_docs)
Run Code Online (Sandbox Code Playgroud)

但得到了一个内存错误。似乎我无法将所有数据加载到内存中。这是输出:

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    encoded_docs = t.texts_to_matrix(docs, mode='count')
  File "/home/yurzho/anaconda3/envs/deepdga/lib/python3.6/site-packages/keras/preprocessing/text.py", line 273, in texts_to_matrix
    return self.sequences_to_matrix(sequences, mode=mode)
  File "/home/yurzho/anaconda3/envs/deepdga/lib/python3.6/site-packages/keras/preprocessing/text.py", line 303, in sequences_to_matrix
    x = np.zeros((len(sequences), num_words))
MemoryError
Run Code Online (Sandbox Code Playgroud)

如果有人熟悉 keras,请告诉我如何预处理数据集。

提前致谢!

python nlp classification keras rnn

3
推荐指数
1
解决办法
2242
查看次数

使用 ssh 时如何避免输入公钥密码

如果我想使用密码,我可以这样做:

`sshpass -f <(printf '%s\n' your_password) ssh user@hostname`
Run Code Online (Sandbox Code Playgroud)

但 sshpass 似乎不适用于公钥。我尝试了以下命令但失败了:

`sshpass -f <(printf '%s\n' your_passphrase) ssh -o PreferredAuthentications=publickey user@hostname`
Run Code Online (Sandbox Code Playgroud)

有什么好的办法吗?

linux ssh sshpass

2
推荐指数
1
解决办法
9562
查看次数

标签 统计

classification ×1

keras ×1

linux ×1

nlp ×1

python ×1

rnn ×1

ssh ×1

sshpass ×1