Kernel Regularization & Adam Algorithm Combined

Hello guys,

I am Menelaos Gkikas from Greece. I faced 1 last problem in Week’s 3 assignment and that is the last exercise where we are quested to program the neural network with kernel regularization and then compile it with Adam.

Even though pieces from class materials were very exact, here the model is entitled None - how can that happen with a model? - and when I simply type what I know there’s the error message invalid syntax.

I have also attached a screenshot. Should the lambda after the regularization be typed “l” or “L”?

I would appreciate a response from someone who knows the problem.

Thanks
M

Hi @Menelaos_Gkikas

There is a syntax error in your code and appears to be due to a closing bracket. That part of the code is not included in the screenshot.

Also, the l must be in lowercase in lamda.

Hope it helps! Feel free to ask if you need further assistance.

1 Like

Hi @Menelaos_Gkikas ,

syntaxError usually associated with mismatch of brackets, so you need to check the line of code just before the pointing arrow marked here.
After you have amended the error, do remember to rerun the code from start. It is always helpful to do a clean run by clicking the kernel tab at the top of the menu bar, and select ‘Restart & Clear all output’ from the dropdown menu.

Hello guys,

I just tried to reposition the position of brackets and nothing happens.

I have attached the code, you will probably delete it cos it’s part of the solution, but please tell me what’s wrong for I run similar pieces earlier in this lab and it was OK.

I would appreciate your timely response

Best
M

Hi @Menelaos_Gkikas ,

There is mis-match of brackets in Sequential(). Here is the Keras reference doc on Sequential Model, check your code against the doc.

Hello Kic,

The code you show me in the doc is different from the lectures, no names of models and no kernels in regularization.

I repositioned the code and I have attached what I did but it still hits error.

Please explain the mistake in my own example of code and not other documents.

Thanks
M

Hello Kic,

As I wait for your reply, I have to say I am a decent and reliable student, but should I pose this question at ChatGPT to find out where we might both be mistaken?

Best
M

Hello guys,

I figured out the solution. In demand for the alchemist…!

I have to report advices were somewhat misleading.

Putting the case in ChatGPT, it states, wrongly put by all sample codes inspired by the mentor - that since there is kernel we need double parentheses and not aligning the brackets. There have been many more examples not aligned and still function. Finally, the next parentheses are put next to None and not below.

The corrected commands are portrayed in the screenshot.

Now in terms of the keras website, the docs there and the advice, these are some on the inexplicable mysteries of life…! English poetry!

Thanks a lot!
M

Hi @Menelaos_Gkikas ,

It is good that you have resolved the issue on your own power. I am not checking message constantly, so there are times I do not see your message until I log on to the system again.
The regularizers.l2() is a API function call, that is why there has to be a (). the same with, tf.keras.layers.Dense(). But in your original code, the call to rf.keras.layers.Dense has only the open bracket, without the closing bracket. That is what trigger the syntax error.
The link to the reference doc is to show various options on what the sequential model looks like. If your dense layer involves call to the regularizer, then you have to go further into the doc.

Thanks Kic.

Then I guess you used confusing notations.

As I Googled translate the terms, brackets are these: [ ]
This is parenthesis: ()

It’s the same term Tom Mosher used in his private messages on the same topic to explain the double parentheses due to kernels.

Hi @Menelaos_Gkikas ,

Brackets is the general term. I used that term ‘brackets’ in my earlier reply as we only have the ‘syntaxError’ message to work on without seeing your actual code.

Below is an image of more brackets.