'tensor' object is not callable pytorch

kahroba: <pre><code>The following code snippet gives the "tensor 'object is not callable" error.
</code></pre>
<p>I think it’s related to the “final_edge_index” tensor.</p>
<p>def forward(self, src, tgt, src_mask, tgt_mask,final_edge_index,batch):<br>
“Take in and process masked src and target sequences.”<br>
memory = self.encoder(self.src_embed(src), src_mask)<br>
output = self.decoder(self.tgt_embed(tgt), memory, src_mask, tgt_mask,final_edge_index,batch)<br>
return output</p>
<p>The value of this tensor is equal to:<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/9/e930765120312040b5348559683f8d616d84c09a.png" data-download-href="https://discuss.pytorch.org/uploads/default/e930765120312040b5348559683f8d616d84c09a" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/e/9/e930765120312040b5348559683f8d616d84c09a.png" alt="image" data-base62-sha1="xgT4YQPfnIJCY0bpFw8iKz8nhXA" width="690" height="113" data-dominant-color="434548"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1002×165 12.8 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>tensor([[[26., 15.],<br>
[28., 19.]],</p>
<pre><code>    [[28., 19.],
     [26., 15.]]], grad_fn=&lt;PermuteBackward&gt;)
</code></pre>

ptrblck: <p>Based on the error message you are trying to call a tensor as a function via:</p>
<pre><code class="lang-python">x = torch.tensor(1.)
x(1)
&gt; TypeError: 'Tensor' object is not callable
</code></pre>
<p>but it’s unclear where exactly this is happening based on your code and screenshot.<br>
Could you add a minimal executable code snippet to reproduce the issue?<br>
Also, you can post code snippets by wrapping them into three backticks ```, which makes debugging easier <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=10" title=":wink:" class="emoji" alt=":wink:"></p>

kahroba: <p>thanks for your response .<br>
On line 28 of the code below the corresponding error occurs<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/c/0c29767d4ccc020a5636d902ea1dd0b486e9e85b.png" data-download-href="https://discuss.pytorch.org/uploads/default/0c29767d4ccc020a5636d902ea1dd0b486e9e85b" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/c/0c29767d4ccc020a5636d902ea1dd0b486e9e85b_2_690x98.png" alt="image" data-base62-sha1="1JAyVFKC9WXyadZvkk1u224b58L" width="690" height="98" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/c/0c29767d4ccc020a5636d902ea1dd0b486e9e85b_2_690x98.png, https://discuss.pytorch.org/uploads/default/optimized/3X/0/c/0c29767d4ccc020a5636d902ea1dd0b486e9e85b_2_1035x147.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/0/c/0c29767d4ccc020a5636d902ea1dd0b486e9e85b.png 2x" data-dominant-color="303739"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1085×155 29.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

kahroba: <p>As you said I mistakenly called a tensor as a function<br>
The problem was solved by converting self.tgt_embed (tgt) to self.tgt_embed<br>
thanks</p>