Error related at nn.Embedding

I’m coding Encoder-Decoder model.

Encounterd a bug.Is anyone there to solve my problem?

Pass the input data to embedding, but not work.

class Encoder_Decoder(nn.Module):
    def __init__(self, input_size, output_size, dumb):
        super(Encoder_Decoder, self).__init__()
        self.embed_input = nn.Embedding(input_size, dumb, padding_idx=-1),
        self.embed_target = nn.Embedding(output_size, dumb, padding_idx=-1),

        self.lstm1 = nn.LSTMCell(dumb, dumb),
        self.linear1 = nn.Linear(dumb, output_size)

    def forward(self, input_lines ,target_lines):
        global all_loss
        
        print("input_lines", input_lines)
        for input_sentence_words in input_lines:
            print("input_sentence_words",input_sentence_words)
            print("type", input_sentence_words.type())

            input_k = self.embed_input(input_sentence_words)
            print(input_k)
            h = self.lstm1(input_k)
            print(h)
        return all_loss

Around optimizer

model = Encoder_Decoder(ev, jv, demb)
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
device = torch.device('cuda:0')
model = model.to(device)

Output


input_lines tensor([[   3,    3,   50,  338,  817,  756,  348,   52,  249,  516],
        [ 665,  478,   11,  339,   11,  169,   46,    6,  784,   58],
        [ 666,  479,  730,  340,    3,  183,  150,    3,    6,  517],
        [ 667,   88,  207,   61,  314,  164,   69,  636,   29,   11],
        ............................................................  
        [ 672,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1],
        [  15,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1],
        [ 849,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1]], device='cuda:0')

input_sentence_words tensor([   3,    3,   50,  338,  817,  756,  348,   52,  249,  516], device='cuda:0')
type torch.cuda.LongTensor

Error message

Traceback (most recent call last):
  File "pytorch.py", line 74, in <module>
    loss = model(Transposed_input, Transposed_target)
  File "/home/-----/.pyenv/versions/3.6.3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "pytorch.py", line 42, in forward
    input_k = self.embed_input(input_sentence_words)
TypeError: 'tuple' object is not callable

all source code

Thank you for reading.

you put comma at the end, so it is a tuple

1 Like

Thank you!!!

It work.