Suggestion For Model

harshini_sewani: <p>I am currently using a hybrid model using pytorch by hybrid I mean Autoencoder and CNN and here is my model :</p>
<p><strong>convnet(</strong><br>
<strong>(fc_encoder): Sequential(</strong><br>
<strong>(0): Linear(in_features=9950, out_features=200, bias=True)</strong><br>
<strong>)</strong><br>
<strong>(decoder): Sequential(</strong><br>
<strong>(0): Linear(in_features=200, out_features=9950, bias=True)</strong><br>
<strong>)</strong><br>
<strong>(con1): Conv1d(1, 2, kernel_size=(5,), stride=(1,))</strong><br>
<strong>(max1): MaxPool1d(kernel_size=4, stride=4, padding=0, dilation=1, ceil_mode=False)</strong><br>
<strong>(con2): Conv1d(2, 4, kernel_size=(5,), stride=(1,))</strong><br>
<strong>(max2): MaxPool1d(kernel_size=4, stride=4, padding=0, dilation=1, ceil_mode=False)</strong><br>
<strong>(l1): Linear(in_features=2480, out_features=1024, bias=True)</strong><br>
<strong>(drop): Dropout(p=0.5, inplace=False)</strong><br>
<strong>(l2): Linear(in_features=1024, out_features=512, bias=True)</strong><br>
<strong>(l3): Linear(in_features=512, out_features=128, bias=True)</strong><br>
<strong>(l4): Linear(in_features=128, out_features=32, bias=True)</strong><br>
<strong>(l5): Linear(in_features=32, out_features=1, bias=True)</strong><br>
<strong>)</strong></p>
<p>I have some doubts regarding:</p>
<ol>
<li>
<p>I am using one loss function to evaluate my model which is BCELoss. I want to know if hybrid model is implemented do I need to use 2 loss functions? What will happen if I evaluate my model just on one loss function?</p>
</li>
<li>
<p>The second question is if I am changing my learning rate I have a big difference in the ROC curve why this is happening?</p>
</li>
</ol>
<p>Any clarification needed for the shape of the input I can provide.</p>
<p>Thanks in advance <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

harshini_sewani: <p>This is my class to define the model:</p>
<p>class convnet(nn.Module):<br>
def <strong>init</strong>(self,num_inputs=9950):<br>
super(convnet,self).<strong>init</strong>()<br>
self.num_inputs=num_inputs<br>
self.fc_encoder= nn.Sequential(<br>
nn.Linear(num_inputs,200)<br>
)<br>
self.decoder = nn.Sequential(<br>
nn.Linear(200,num_inputs)<br>
)<br>
self.con1=nn.Conv1d(1, 2, 5)<br>
self.max1=nn.MaxPool1d(4)<br>
self.con2=nn.Conv1d(2, 4, 5)<br>
self.max2=nn.MaxPool1d(4)<br>
self.l1=nn.Linear(2480,1024)<br>
self.drop=nn.Dropout(p= 0.5)<br>
self.l2=nn.Linear(1024,512)<br>
self.l3=nn.Linear(512,128)<br>
self.l4=nn.Linear(128,32)<br>
self.l5=nn.Linear(32,1)<br>
def forward(self, x):<br>
x = self.fc_encoder(x)<br>
x = self.decoder(x)<br>
x=x.unsqueeze(1)<br>
x=self.con1(x)<br>
x=self.max1(x)<br>
x=self.con2(x)<br>
x=self.max2(x)<br>
x = x.view(x.size(0), -1)<br>
x=self.l1(x)<br>
x=self.drop(x)<br>
x=self.l2(x)<br>
x=self.l3(x)<br>
x=self.l4(x)<br>
x=self.l5(x)<br>
return torch.sigmoid(x)<br>
m = convnet()<br>
m.to(device)</p>

ptrblck: <p>If I’m not mistaken, you are passing the inputs first to the Autoencoder and pass this output to the CNN.<br>
The code for this looks generally alright and you wouldn’t need to use two losses, if your complete model only returns a single output.</p>
<p>Note that the last linear layers are used without any non-linearly, which could be reduced to a single linear transformation, so you might want to add some activation function between them.</p>
<ol>
<li>
<p>As described, it depends on your use case, but the current model definition would not need two separate loss functions. You could of course use the Autoencoder output to calculate an auxiliary loss, but that’s up to you.</p>
</li>
<li>
<p>The learning rate is a hyperparameter and it is expected that your model performance suffers from a bad learning rate value. E.g. if you set it to an unreasonably high values such as 1000 your model would most likely not converge.</p>
</li>
</ol>
<p>PS: 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=9" title=":wink:" class="emoji" alt=":wink:"></p>

harshini_sewani: <p>Thank you so much for your reply. Reading your answer has really helped me to understand the concepts. I really appreciate your help <img src="https://discuss.pytorch.org/images/emoji/apple/smiley.png?v=12" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"><br>
Yes you are correct first I am passing it to auto encoder and then to CNN. I will add a activation function to my model thank you for the suggestion <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>The reason I got confused in the loss function is because I am getting very high accuracy which seems too good to be true. I am getting accuracy of 0.99% by using learning rate 0.0003 and the ROC as attached below with your experience is it normal to get such high accuracy? Or I am doing something wrong?</p>
<p>I have data set of size 1035 split is 90/10 for training and testing respectively.</p>
<p>Thanks in advance <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/b/0/b025aaea2e015e02766d2c20c42865d71047b80f.png" alt="Capture" data-base62-sha1="p8gJIjWoVbxTCxgc3ELowFTcSyb" width="307" height="379"></p>

ptrblck: <p>You could get such high accuracy values and it of course depends on the data set and used model.<br>
Usually you would split the dataset into three parts:</p>
<ul>
<li>training data, which is only used during the training to update the parameters</li>
<li>validation data, which is often used after each full training epoch, to apply early stopping and for general hyperparameter tuning</li>
<li>test data, which is never touched during training/validation, but one single time, if you end the training and would like to test the final model.</li>
</ul>
<p>In the most careful approach, you should not modify the model or any hyperparameter anymore, as you would be leaking the test error information into the training, after calculating the test error.</p>

harshini_sewani: <p>Thank you so much for sharing your knowledge really helped me a lot.</p>

harshini_sewani: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> Is it normal to have the ROC curve like the image attached above? Usually, whenever I read papers or see over the GitHub they are moreover curvy.<br>
Can you please give your thoughts on that?<br>
I really appreciate your response <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

ptrblck: <p>Often these curves have more points in the plane and are thus “curvier”.<br>
I guess that your predictions might have very specific clusters, such that changing the threshold for the positive/negative predictions doesn’t create a lot of different FPR/TPR points.</p>

harshini_sewani: <p>Okay thank you so much for the clarification <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>