Tuple of Tensors
I recently asked one part of this question. I am building a chatbot, and there is a function that makes the problems. The function is given below:
def variable_from_sentence(sentence):
  vec, length = indexes_from_sentence(sentence)
  inputs = [vec]
  lengths_inputs = [length]
  if hp.cuda:
    batch_inputs = Variable(torch.stack(torch.Tensor(inputs),1).cuda())
  else:
    batch_inputs = Variable(torch.stack(torch.Tensor(inputs),1))
  return batch_inputs, lengths_inputs

But when I try to run the chatbot code , it gives me this error:

stack(): argument 'tensors' (position 1) must be tuple of Tensors, not tensor

For that reason, I fixed the function like this:
def variable_from_sentence(sentence):
  vec, length = indexes_from_sentence(sentence)
  inputs = [vec]
  lengths_inputs = [length]
  if hp.cuda:
    batch_inputs = torch.stack(inputs, 1).cuda()
  else:
    batch_inputs = torch.stack(inputs, 1)
  return batch_inputs, lengths_inputs

But it still gives me error, and the error is like this:

TypeError: expected Tensor as element 0 in argument 0, but got list

What should I do now in this situation?

Since the vec and length are both integers, you can use torch.tensor directly:
def variable_from_sentence(sentence):
    vec, length = indexes_from_sentence(sentence)
    inputs = [vec]
    lengths_inputs = [length]
    if hp.cuda:
        batch_inputs = torch.tensor(inputs, device='cuda')
    else:
        batch_inputs = torch.tensor(inputs)
    return batch_inputs, lengths_inputs

