Syntax error in Model definition

The second line in following code is giving syntax error:
class LogisticRegression(nn.Module):
def init (self,in):

Can someone explain why?


I don’t know what assignment this is for. I don’t see any place where you would need to add a LogisticRegression class in the assignment for Course 1, Week 1. Please try to give context to say which assignment you are working on in the future.

In general, though, step one with a syntax error is to make sure you’re reading the error message thoroughly. There should be a carat character, ^, pointing up at the specific place in the line that is causing a problem. If needed, you can google to look up the expected parameters for a function. In this case, you can google for pytorch Module class to find this documentation: Module — PyTorch 1.12 documentation

Thank you Wendy, I’m trying " intro to PyTorch", week 1.

Thanks, but I’m confused, then. There’s no place I see in that assignment where it asks you to define your own code - just to read and run the provided code. Are you just trying this on your own based on what you learned in the “Intro to PyTorch”? If so, I’d suggest taking a closer look at the ExampleModule and try to follow that example. In particular, you might want to use init instead of init, and pass the same parameters that are defined there.

Yes Wendy, I am trying the given piece of code shown in the “Intro to PyTorch” video. I am not getting what you have suggested, both are “init” only?

Anyway I ran it by trial and error method. I found in place of parameter “in”, it should be only i or some other variable name. But the video does show “in”. I am attaching both the screenshots for your perusal.

Ah! I see. You were talking about the video “Intro to PyTorch”. There also happens to be a lab called “Intro to PyTorch”, which is what I thought you were talking about.

In general, I’d suggest using the labs for code examples over the videos. The labs have been tested and should have all dependencies loaded, etc. Videos may just be snippets that don’t contain everything you need or may have typos that were overlooked.

The error you found with the video is interesting, though. It looks like you were getting an error because “in” is a keyword and shouldn’t be used as a variable. In the screenshot you shared from the video, all the other keywords (class, def, super) are green, but “in” is not, which suggests “in” was not recognized as a keyword in the environment they were running in for some reason. I’m not sure how that happened.

Thank you Wendy. I would follow your suggestion of learning from lab. Special acknowledgement for your sincere response which is very crucial for the learners like me.

1 Like