Error in week 1 assignment 2 last exercise

HERE IS THE ERROR ATTACHED

j =  0 idx =  0
single_example = turiasaurus
single_example_chars ['t', 'u', 'r', 'i', 'a', 's', 'a', 'u', 'r', 'u', 's']
single_example_ix [20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19]
 X =  [None, [20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19]] 
 Y =        [[20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19], 0] 

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-28-725c093d6b91> in <module>
----> 1 parameters, last_name = model(data.split("\n"), ix_to_char, char_to_ix, 22001, verbose = True)
      2 
      3 assert last_name == 'Trodonosaurus\n', "Wrong expected output"
      4 print("\033[92mAll tests passed!")

<ipython-input-27-5d42bbabaea5> in model(data_x, ix_to_char, char_to_ix, num_iterations, n_a, dino_names, vocab_size, verbose)
     82         if j % 2000 == 0:
     83 
---> 84             print('Iteration: %d, Loss: %f' % (j, loss) + '\n')
     85 
     86             # The number of dinosaur names to print

TypeError: only size-1 arrays can be converted to Python scalars

PLEASE HELP TO SORT IT OUT

Hi @Pulkit ,

Have you found the solution yet? Let’s know if we could help.

1 Like

I didnt get the solution please help

Hi @Pulkit ,

Looking at the part of the code you posted here, it is provided for you. So the problem is not where the print statement is. I suspect there is problem else where. So for start, just to make sure your execution environment is clean and the kernel is healthy, do the following:

  1. refresh the kernel and clear all output
  2. rerun code from start

I already tried it
Shall I share my code?

START CODE HERE

{ Adhering to the honour code policy, your code has been removed }

END CODE HERE

here is the code

Please only share your code if a mentor asks you to send it via a direct message.

The error means that your code has an incorrect data size for either “loss” or “j”.

“loss” comes from your “curr_loss” value returned from “optimize()”.

So perhaps there is an error in one of the arguments you’re passing to optimize().

SIR checked it already all the parameters are in correct order

I believe this is from trying to pass the single_example_ix into array format

Hi @Pulkit ,

Post the optimize() section of the code in a DM to me. I will have a look for you.

Hi @Pulkit ,

The code for optimize() looks fine. I just checked your code posted here, these two lines are not necessary, and they might be the cause of the problem:
X = [None] + [char_to_ix[ch] for ch in examples[idx]]
Y = X[1:] + [char_to_ix["\n"]]

remove them, then rerun your code from start to see if that makes a difference.

Yeah I already did that too but it makes no difference , I have even shared the code for optimize to you please have a look

Hi @Pulkit ,

There could only be two places that are causing problem, they are the loss and curr_loss. Your code for optimize() looks fine to me, and all the utility functions are provided.

Here is a couple of suggestions to check:

  1. parameters passed to get_initial_loss()
  2. parameters passed to smooth()

Also what are the outputs printed

SIR I have dm you the full code please kindly check and resolve as I am not able to figure it out

Hi @Pulkit,

I have had a look at the code for model(), and I could not find anything unusual. It could be the case of cleaning up the execution environment to get the right answers. So, refresh the kernel and clear all output, rerun the code from start.

Just to get some idea if you are on the right track. Here is the output generated to track progress:

j = 0 idx = 0
single_example = turiasaurus
single_example_chars [‘t’, ‘u’, ‘r’, ‘i’, ‘a’, ‘s’, ‘a’, ‘u’, ‘r’, ‘u’, ‘s’]
single_example_ix [None, 20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19]
X = [None, 20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19]
Y = [20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19, 0]

Iteration: 0, Loss: 23.087336

Nkzxwtdmfqoeyhsqwasjkjvu
Kneb
Kzxwtdmfqoeyhsqwasjkjvu
Neb
Zxwtdmfqoeyhsqwasjkjvu
Eb
Xwtdmfqoeyhsqwasjkjvu

j = 1535 idx = 1535
j = 1536 idx = 0
Iteration: 2000, Loss: 27.884160

Liusskeomnolxeros
Hmdaairus
Hytroligoraurus
Lecalosapaus
Xusicikoraurus
Abalpsamantisaurus
Tpraneronxeros

Iteration: 4000, Loss: 25.901815

Mivrosaurus
Inee
Ivtroplisaurus
Mbaaisaurus
Wusichisaurus
Cabaselachus
Toraperlethosdarenitochusthiamamumamaon

Iteration: 6000, Loss: 24.608779

Onwusceomosaurus
Lieeaerosaurus
Lxussaurus
Oma
Xusteonosaurus
Eeahosaurus
Toreonosaurus

Iteration: 8000, Loss: 24.070350

Onxusichepriuon
Kilabersaurus
Lutrodon
Omaaerosaurus
Xutrcheps
Edaksoje
Trodiktonus

Iteration: 10000, Loss: 23.844446

Onyusaurus
Klecalosaurus
Lustodon
Ola
Xusodonia
Eeaeosaurus
Troceosaurus

Iteration: 12000, Loss: 23.291971

Onyxosaurus
Kica
Lustrepiosaurus
Olaagrraiansaurus
Yuspangosaurus
Eealosaurus
Trognesaurus

Iteration: 14000, Loss: 23.382338

Meutromodromurus
Inda
Iutroinatorsaurus
Maca
Yusteratoptititan
Ca
Troclosaurus

Iteration: 16000, Loss: 23.224544

Meusspanchodtashuarhiaspantaxia
Indaa
Iuspsauhosaurus
Macacosaurus
Yusoconikaulrit
Cacasoceimurus
Trrasaurus

Iteration: 18000, Loss: 22.904954

Pivrrong
Llecanosaurus
Myssocilindus
Peeaishidanagtallsaurus
Ytrong
Eg
Trojichus

Iteration: 20000, Loss: 23.005394

Nkytrohelosaurus
Lolaagosaurus
Lyusochosaurus
Necakson
Yussangosaurus
Eiagosaurus
Trodon

Iteration: 22000, Loss: 22.728886

Onustreofkelus
Llecagosaurus
Mystolojmiaterltasaurus
Ola
Yuskeolongus
Eiacosaurus
Trodonosaurus

Sir already done multiple times but same error

How far did you manage to get to, are you able to get any output?

Sir all the tests before this exercise were passed

Hi @Pulkit ,

What output did you manage to get from running this exercise? Check that against the output I posted here. If you are not getting those output, use print statement for debugging.