[solved] Expected tensor for argument #1 'indices' to have scalar type Long; but got CPUDoubleTensor instead (while checking arguments for embedding)

A little bit of context

        dlg_turnwise_embeddings = np.random.random((batch_size, 20, 256))
        dlg_turnwise_embeddings = torch.from_numpy(dlg_turnwise_embeddings)

        if legacy:
            hidden = rnn_model.init_hidden(batch_size)
            # words_emb: batch_size x nef x seq_len
            # sent_emb: batch_size x nef
            words_emb, sent_emb = rnn_model(captions, cap_lens, hidden)
        else:
            words_emb = word_reducer(data_caption_word_embeddings)
            print(data_caption_word_embeddings)
            sent_emb = sent_reducer(data_caption_embeddings)
            # the input to the model is here
            # data caption word embedding
            # this would be changed to data_dialogue_word_embedding
            # words_emb  torch.Size([48, 256, 14])
            # we want the same size for the word and sentence embedding
            # sent_emb  torch.Size([48, 256])

            # TODO: write an LSTM model that outputs the following
            # with size ((batch_size, 256))
            hidden = dlg_encoder.init_hidden(batch_size)
            dlg_entire_embeddings = dlg_encoder(dlg_turnwise_embeddings, 
                                                dlg_turnwise_embeddings.shape,
                                                hidden)

Seems to happen when I do dlg_turnwise_embeddings = torch.from_numpy(dlg_turnwise_embeddings)? Is it as simple as casting it to Long from Double values inside the tensor?

2 Likes

Nevermind figured it out

 |  109         dlg_turnwise_embeddings = np.random.random((batch_size, 20, 256))                                                          
 |>>110         dlg_turnwise_embeddings = np.asarray(dlg_turnwise_embeddings, dtype=int)                                                   
 |+ 111         dlg_turnwise_embeddings = torch.from_numpy(dlg_turnwise_embeddings)                                                        
 |+ 112         if cfg.CUDA:                                                                                                               
 |+ 113             dlg_turnwise_embeddings = dlg_turnwise_embeddings.cuda() 
2 Likes

@dendisuhubdy So, the final solution is to convert the dtype to int?

1 Like