Giter Club home page Giter Club logo

seq2seq's People

Contributors

yanwii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

seq2seq's Issues

RuntimeError: cuda runtime error (59) : device-side assert triggered

RuntimeError: cuda runtime error (59) : device-side assert triggered at /pytorch/torch/lib/THC/generic/THCTensorCopy.c:18
出现这个问题是我改了代码
#words = jieba.lcut(sentence)
words = [word for word in sent]
改动之后没有使用结巴分词,直接用的字符做的输入,这样训练的时候为什么会有上面的错误,谢谢

另外有点问题想请教下:
1 你的代码中对原始数据也就是问答数据进行jieba分词处理,最后是直接对词进行的编码然后输入,我想问的是这种分词与否是否会对结果有影响,为什么?
2 中文数据中的标点符号需要去除吗?

an illegal memory access was encountered

项目下下来简单填了几个answer和question然后跑起来测试,发现可以运行并且效果还不错,就搞了将近2mb的answer和question,在preprocessing阶段通过,开始训练的时候就提示下面的错误了。

THCudaCheck FAIL file=C:/new-builder_3/win-wheel/pytorch/aten/src/ATen/native/cuda/Embedding.cu line=247 error=77 : an illegal memory access was encountered
Traceback (most recent call last):
File "seq2seq.py", line 436, in
seq.train()
File "seq2seq.py", line 210, in train
loss, logits = self.step(inputs, targets, self.max_length)
File "seq2seq.py", line 265, in step
loss.backward()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\torch\tensor.py", line 93, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\torch\autograd_init_.py", line 90, in backward
allow_unreachable=True) # allow_unreachable flag
RuntimeError: cuda runtime error (77) : an illegal memory access was encountered at C:/new-builder_3/win-wheel/pytorch/aten/src/ATen/native/cuda/Embedding.cu:2
47

一脸懵逼,我该怎么办

input_size,output_size,hiden_size该如何设置,什么依据?

我的参数设置:
self.input_size = 100
self.output_size = 1200
self.hidden_size = 1200
self.max_length = 1200
训练时报错:数组越界错误,不知道是什么情况,忘不吝赐教,暂时没深入网络中去,想先跑个例子学习下,问题可能有点无脑
File "/Users/sunwc/Documents/pythonproject/seq2seq-master/seq2seq.py", line 35, in forward
embedded = self.embedding(word_inputs).view(seq_len, 1, -1)
RuntimeError: index out of range at /Users/soumith/code/builder/wheel/pytorch-src/aten/src/TH/generic/THTensorMath.cpp:352

cuda runtime error

, TensorInfo<long, IndexType>, int, int, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2]: block: [0,0,0], thread: [91,0,0] Assertion srcIndex < srcSelectDimSize failed.
/pytorch/torch/lib/THC/THCTensorIndex.cu:279: void indexSelectSmallIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2]: block: [0,0,0], thread: [92,0,0] Assertion srcIndex < srcSelectDimSize failed.
/pytorch/torch/lib/THC/THCTensorIndex.cu:279: void indexSelectSmallIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2]: block: [0,0,0], thread: [93,0,0] Assertion srcIndex < srcSelectDimSize failed.
/pytorch/torch/lib/THC/THCTensorIndex.cu:279: void indexSelectSmallIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2]: block: [0,0,0], thread: [94,0,0] Assertion srcIndex < srcSelectDimSize failed.
/pytorch/torch/lib/THC/THCTensorIndex.cu:279: void indexSelectSmallIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2]: block: [0,0,0], thread: [95,0,0] Assertion srcIndex < srcSelectDimSize failed.
THCudaCheck FAIL file=/pytorch/torch/lib/THC/generic/THCTensorCopy.c line=21 error=59 : device-side assert triggered
Traceback (most recent call last):
File "seq2seq.py", line 453, in
seq.train()
File "seq2seq.py", line 227, in train
loss, logits = self.step(inputs, targets, self.max_length)
File "seq2seq.py", line 259, in step
decoder_input = decoder_input.cuda()
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/variable.py", line 298, in cuda
return CudaTransfer.apply(self, device, async)
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/_functions/tensor.py", line 201, in forward
return i.cuda(async=async)
File "/usr/local/lib/python3.5/dist-packages/torch/_utils.py", line 69, in cuda
return new_type(self.size()).copy
(self, async)
RuntimeError: cuda runtime error (59) : device-side assert triggered at /pytorch/torch/lib/THC/generic/THCTensorCopy.c:21

Expected argument self to have 1

执行:
python3 preprocessing.py
python3 seq2seq.py train
之后,出现:
请问是不是python或pytorch的版本不对?

Traceback (most recent call last):
File "seq2seq.py", line 438, in
seq.train()
File "seq2seq.py", line 213, in train
loss, logits = self.step(inputs, targets, self.max_length)
File "seq2seq.py", line 253, in step
decoder_output, decoder_context, decoder_hidden, decoder_attention = self.decoder(decoder_input, decoder_context, decoder_hidden, encoder_outputs)
File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 224, in call
result = self.forward(*input, **kwargs)
File "seq2seq.py", line 109, in forward
attn_weights = self.attn(rnn_output.squeeze(0), encoder_outputs)
File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 224, in call
result = self.forward(*input, **kwargs)
File "seq2seq.py", line 65, in forward
attn_energies[i] = self.score(hidden, encoder_outputs[i])
File "seq2seq.py", line 76, in score
energy = hidden.dot(energy)
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/variable.py", line 631, in dot
return Dot.apply(self, other)
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/_functions/blas.py", line 211, in forward
return vector1.new((vector1.dot(vector2),))
RuntimeError: Expected argument self to have 1 dimension(s), but has 2 at /pytorch/torch/csrc/generic/TensorMethods.cpp:23020

RuntimeError: cuda runtime error (59) :

在问答集中增加问题后,就报了这个错误。
我就改了这几个参数
self.input_size = 1840
self.output_size = 1840
self.hidden_size = 64
self.max_length = 50
/pytorch/torch/lib/THCUNN/ClassNLLCriterion.cu:57: void cunn_ClassNLLCriterion_updateOutput_kernel(Dtype *, Dtype *, Dtype *, long *, Dtype *, int, int, int, int, long) [with Dtype = float, Acctype = float]: block: [0,0,0], thread: [0,0,0] Assertion t >= 0 && t < n_classes failed.
THCudaCheck FAIL file=/pytorch/torch/lib/THC/generic/THCTensorCopy.c line=18 error=59 : device-side assert triggered
Traceback (most recent call last):
File "seq2seq.py", line 443, in
seq.retrain()
File "seq2seq.py", line 434, in retrain
self.train()
File "seq2seq.py", line 213, in train
loss, logits = self.step(inputs, targets, self.max_length)
File "seq2seq.py", line 253, in step
decoder_output, decoder_context, decoder_hidden, decoder_attention = self.decoder(decoder_input, decoder_context, decoder_hidden, encoder_outputs)
File "/home/liuyong/venv/seq2seq-master/lib/python3.5/site-packages/torch/nn/modules/module.py", line 224, in call
result = self.forward(*input, **kwargs)
File "seq2seq.py", line 105, in forward
attn_weights = self.attn(rnn_output.squeeze(0), encoder_outputs)
File "/home/liuyong/venv/seq2seq-master/lib/python3.5/site-packages/torch/nn/modules/module.py", line 224, in call
result = self.forward(*input, **kwargs)
File "seq2seq.py", line 63, in forward
if USE_CUDA: attn_energies = attn_energies.cuda()
File "/home/liuyong/venv/seq2seq-master/lib/python3.5/site-packages/torch/autograd/variable.py", line 279, in cuda
return CudaTransfer.apply(self, device_id, async)
File "/home/liuyong/venv/seq2seq-master/lib/python3.5/site-packages/torch/autograd/_functions/tensor.py", line 151, in forward
return i.cuda(async=async)
File "/home/liuyong/venv/seq2seq-master/lib/python3.5/site-packages/torch/_utils.py", line 66, in cuda
return new_type(self.size()).copy
(self, async)

expected tensor [5798 x 100] and src [600 x 100]

这个是什么错误 好奇怪的错误
While copying the parameter named encoder.embedding.weight, whose dimensions in the model are torch.Size([5798, 100]) and whose dimensions in the checkpoint are torch.Size([600, 100]), ...
inconsistent tensor size, expected tensor [5798 x 100] and src [600 x 100] to have the same number of elements, but got 579800 and 60000 elements respectively

运行train 时报错

C:\ProgramData\Anaconda3\envs\torch\python.exe E:/hyx/seq2seq-master/seq2seq.py train
C:\ProgramData\Anaconda3\envs\torch\lib\site-packages\torch\nn\modules\rnn.py:54: UserWarning: dropout option adds dropout after all but last recurrent layer, so non-zero dropout expects num_layers greater than 1, but got dropout=0.05 and num_layers=1
"num_layers={}".format(dropout, num_layers))
Error(s) in loading state_dict for seq2seq:
size mismatch for encoder.embedding.weight: copying a param with shape torch.Size([600, 100]) from checkpoint, the shape in current model is torch.Size([14, 100]).
size mismatch for decoder.embedding.weight: copying a param with shape torch.Size([1600, 100]) from checkpoint, the shape in current model is torch.Size([15, 100]).
size mismatch for decoder.out.weight: copying a param with shape torch.Size([1600, 200]) from checkpoint, the shape in current model is torch.Size([15, 200]).
size mismatch for decoder.out.bias: copying a param with shape torch.Size([1600]) from checkpoint, the shape in current model is torch.Size([15]).
No model!
E:/hyx/seq2seq-master/seq2seq.py:68: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
return F.softmax(attn_energies).unsqueeze(0).unsqueeze(0)
E:/hyx/seq2seq-master/seq2seq.py:110: UserWarning: Implicit dimension choice for log_softmax has been deprecated. Change the call to include dim=X as an argument.
output = F.log_softmax(self.out(torch.cat((rnn_output, context), 1)))
E:/hyx/seq2seq-master/seq2seq.py:266: UserWarning: torch.nn.utils.clip_grad_norm is now deprecated in favor of torch.nn.utils.clip_grad_norm_.
torch.nn.utils.clip_grad_norm(self.encoder.parameters(), clip)
E:/hyx/seq2seq-master/seq2seq.py:267: UserWarning: torch.nn.utils.clip_grad_norm is now deprecated in favor of torch.nn.utils.clip_grad_norm_.
torch.nn.utils.clip_grad_norm(self.decoder.parameters(), clip)
Traceback (most recent call last):
File "E:/hyx/seq2seq-master/seq2seq.py", line 436, in
seq.train()
File "E:/hyx/seq2seq-master/seq2seq.py", line 210, in train
loss, logits = self.step(inputs, targets, self.max_length)
File "E:/hyx/seq2seq-master/seq2seq.py", line 271, in step
return loss.data[0] / target_length, decoder_outputs
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
新手一脸蒙蔽。。。是哪里不对呢

替换了自己的数据之后会报错

/Users/xufan/anaconda3/python.app/Contents/lib/python3.6/site-packages/torch/nn/modules/rnn.py:54: UserWarning: dropout option adds dropout after all but last recurrent layer, so non-zero dropout expects num_layers greater than 1, but got dropout=0.01 and num_layers=1
  "num_layers={}".format(dropout, num_layers))
/Users/xufan/Desktop/itemq/seq2seq.py:70: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
  return F.softmax(attn_energies).unsqueeze(0).unsqueeze(0)
/Users/xufan/Desktop/itemq/seq2seq.py:112: UserWarning: Implicit dimension choice for log_softmax has been deprecated. Change the call to include dim=X as an argument.
  output = F.log_softmax(self.out(torch.cat((rnn_output, context), 1)))
/Users/xufan/Desktop/itemq/seq2seq.py:268: UserWarning: torch.nn.utils.clip_grad_norm is now deprecated in favor of torch.nn.utils.clip_grad_norm_.
  torch.nn.utils.clip_grad_norm(self.encoder.parameters(), clip)
/Users/xufan/Desktop/itemq/seq2seq.py:269: UserWarning: torch.nn.utils.clip_grad_norm is now deprecated in favor of torch.nn.utils.clip_grad_norm_.
  torch.nn.utils.clip_grad_norm(self.decoder.parameters(), clip)
--------------------------------------------------
epoch: 0
    loss: 0.0017108917236328125
    target:[3, 1]
    output:[3, 1]
    per-time: 1.0286190509796143
--------------------------------------------------
epoch: 2
    loss: 2.617159684499105
    target:[4, 5, 6, 7, 8, 1]
    output:[3, 1, 1, 1, 1, 1]
    per-time: 0.9947419166564941
--------------------------------------------------
epoch: 4
    loss: 4.294578552246094
    target:[12, 13, 14, 15, 16, 12, 17, 1]
    output:[3, 1, 5, 15, 1, 1, 1, 1]
    per-time: 1.1878671646118164
Traceback (most recent call last):
  File "/Users/xufan/Desktop/itemq/train.py", line 4, in <module>
    seq.train()
  File "/Users/xufan/Desktop/itemq/seq2seq.py", line 212, in train
    loss, logits = self.step(inputs, targets, self.max_length)
  File "/Users/xufan/Desktop/itemq/seq2seq.py", line 253, in step
    loss += self.criterion(decoder_output, target_variable[di])
  File "/Users/xufan/anaconda3/python.app/Contents/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/Users/xufan/anaconda3/python.app/Contents/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 209, in forward
    return F.nll_loss(input, target, weight=self.weight, ignore_index=self.ignore_index, reduction=self.reduction)
  File "/Users/xufan/anaconda3/python.app/Contents/lib/python3.6/site-packages/torch/nn/functional.py", line 1871, in nll_loss
    ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: Assertion `cur_target >= 0 && cur_target < n_classes' failed.  at ../aten/src/THNN/generic/ClassNLLCriterion.c:92

batch size

the batch size seems not work and can only be set to 1

Traceback (most recent call last): File "seq2seq.py", line 441, in <module> seq.train() File "seq2seq.py", line 211, in train inputs, targets = self.next(1, shuffle=False) File "seq2seq.py", line 193, in next inputs = Variable(torch.LongTensor(inputs)).transpose(1, 0).contiguous() RuntimeError: given sequence has an invalid size of dimension 2: 0

这个错误是什么意思呢?
Traceback (most recent call last):
File "seq2seq.py", line 441, in
seq.train()
File "seq2seq.py", line 211, in train
inputs, targets = self.next(1, shuffle=False)
File "seq2seq.py", line 193, in next
inputs = Variable(torch.LongTensor(inputs)).transpose(1, 0).contiguous()
RuntimeError: given sequence has an invalid size of dimension 2: 0

no model错误

C:\ProgramData\Anaconda3\envs\torch\python.exe E:/hyx/seq2seq-master/seq2seq.py train
C:\ProgramData\Anaconda3\envs\torch\lib\site-packages\torch\nn\modules\rnn.py:54: UserWarning: dropout option adds dropout after all but last recurrent layer, so non-zero dropout expects num_layers greater than 1, but got dropout=0.05 and num_layers=1
"num_layers={}".format(dropout, num_layers))
Error(s) in loading state_dict for seq2seq:
size mismatch for encoder.embedding.weight: copying a param with shape torch.Size([600, 100]) from checkpoint, the shape in current model is torch.Size([14, 100]).
size mismatch for decoder.embedding.weight: copying a param with shape torch.Size([1600, 100]) from checkpoint, the shape in current model is torch.Size([15, 100]).
size mismatch for decoder.out.weight: copying a param with shape torch.Size([1600, 200]) from checkpoint, the shape in current model is torch.Size([15, 200]).
size mismatch for decoder.out.bias: copying a param with shape torch.Size([1600]) from checkpoint, the shape in current model is torch.Size([15]).
No model!
还有下面的报错
Traceback (most recent call last):
File "E:/hyx/seq2seq-master/seq2seq.py", line 436, in
seq.train()
File "E:/hyx/seq2seq-master/seq2seq.py", line 210, in train
loss, logits = self.step(inputs, targets, self.max_length)
File "E:/hyx/seq2seq-master/seq2seq.py", line 271, in step
return loss.data[0] / target_length, decoder_outputs
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
怎么调都不对,求指点~~

用自己的文本总会出现 index out of range

Traceback (most recent call last):
File "seq2seq.py", line 439, in
seq.train()
File "seq2seq.py", line 210, in train
loss, logits = self.step(inputs, targets, self.max_length)
File "seq2seq.py", line 236, in step
encoder_outputs, encoder_hidden = self.encoder(input_variable, encoder_hidden)
File "/home/zy/anaconda3/envs/pytchar/lib/python3.7/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "seq2seq.py", line 35, in forward
embedded = self.embedding(word_inputs).view(seq_len, 1, -1)
File "/home/zy/anaconda3/envs/pytchar/lib/python3.7/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/home/zy/anaconda3/envs/pytchar/lib/python3.7/site-packages/torch/nn/modules/sparse.py", line 110, in forward
self.norm_type, self.scale_grad_by_freq, self.sparse)
File "/home/zy/anaconda3/envs/pytchar/lib/python3.7/site-packages/torch/nn/functional.py", line 1110, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: index out of range at /opt/conda/conda-bld/pytorch_1535493744281/work/aten/src/TH/generic/THTensorMath.cpp:352

No model error

我在执行 python seq2seq.py train 的时候遇到了下面的错误,请问应该如何解决?

(py365) ubuntu@i-o9tnhsxb:~/chatbot/seq2seq$ python seq2seq.py train
While copying the parameter named encoder.embedding.weight, whose dimensions in the model are torch.Size([14, 100]) and whose dimensions in the checkpoint are torch.Size([600, 100]), ...
inconsistent tensor size, expected tensor [14 x 100] and src [600 x 100] to have the same number of elements, but got 1400 and 60000 elements respectively at /pytorch/torch/lib/TH/generic/THTensorCopy.c:86
No model!
Illegal instruction (core dumped)

preprocessing的问题

你好,我用自己的数据在preprocessing运行时,在第43行就停止运行了,应该是self.vocab的错误,是需要我自己对他进行产生我需要的编码吗

your data is empty

i`m sorry to trouble you ,but had you noticed that your data is empty.
such as : ./data/supplementvovab.txt

这数据是怎么准备,

数据按问题,答案放到两个文件中,训练时报错
Assertion `cur_target >= 0 && cur_target < n_classes' failed.
网上查的,是label 设置不对?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.