Recently after I update the course materials, there is one notebook called “lesson2-sgd”. However, when I tried the codes inside the notebook. I got the error after I run the code: a = tensor(3.,2); a
with the error: --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-13-440e075cecad> in <module> ----> 1 a = tensor(3.,2); a
TypeError: tensor() takes 1 positional argument but 2 were given
When I checked the notebook, this line of code seems should work without error. I already update my fastai library to 1.0.15 and this error still occurs.
I am not familiar with the notebook, but please check the function signature, this can provide a lot of useful information.
To do so, while having your cursor on the right hand side of the leftmost parentheses, press shift+tab.
tensor( | <---- cursor, here is when you press shift + tab
You could also try executing a cell with only the following in it: ?tensor (one or two question marks - either produces different results).
Based on the code you shared, I do not know what tensor is. It might be a custom function defined in the notebook. Chances are it is a torch.tensor. Many of the torch methods take a tuple for a shape -> in this case tensor((3,2)) might work.
Still, would be great to take a look at the function signature to learn more.
Thanks @radek, here is what I found. This tensor function is from the fastai library. def tensor(x:Any)->Tensor: "Like `torch.as_tensor`, but handle lists too" return torch.tensor(x) if is_listy(x) else as_tensor(x)
Ah great, you’ve done the necessary detective work Yeah, the doc string is not very clear without context, but I would not worry about this too much.
Seems it takes something that is_listy and gives us a pytorch Tensor back. I googled torch.tensor and found this.
Might be the function worked with just 3,2 as input before some changes (seems the library is still being very actively developed!). Based on the additional information I think something like this might work:
torch.tensor([3, 2])
If it does not work, when it blows up, maybe it will give us some additional information.