"Wrong expected output"

I am not able to understand where I am going wrong. Can anyone guide me to the right route or a hint where I might be going wrong??

are my parameters correct???

Please check this thread where the user experienced the same error. If it doesn’t help, let us know.

Best,
Saif.

from what I understood with the thread you sent, my single_Example is incorrect, so the idx initialisation is incorrect? I am understanding right sir??

I don’t know whether your idx initialization is correct or not. Please share your full error.

TypeError Traceback (most recent call last)
in
----> 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!”)

in model(data_x, ix_to_char, char_to_ix, num_iterations, n_a, dino_names, vocab_size, verbose)
80 if j % 2000 == 0:
81
—> 82 print('Iteration: %d, Loss: f' (j, loss) + ‘\n’)
83
84 # The number of dinosaur names to print

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

Kindly send me your code of a model function in a private message so I can check it. Click my name and message.

1 Like

Sent. Please have a look.

Thank you
DP

OK. I got your bug. Please add the below two lines in your code and see what the difference in them. The output will be verbose but you can change the num_iterations from 22001 to 2. But once you find your bug, then revert it to 22001.

print(f'single_example_ix: {len(single_example_ix)}')
print(f'[single_example_ix]: {len([single_example_ix])}')
        

I am getting this error now

single_example_ix: 11
[single_example_ix]: 1

TypeError Traceback (most recent call last)
in
----> 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!”)

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

So, we need to Prepend the list [None] in front of the list of input characters. All characters of single_example_ix. But when we use [], we make the list inside another list which treats it as a single.

I already have prepend [None] with the single_example_ix to the X equation

ok I saw a difference when I removed [ ] from the X equation for single_example_ix

I got this

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]

single_example_ix: 11
[single_example_ix]: 1
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

Check the below example.

Let’s say we have:

input_characters = ['a', 'b', 'c', 'd']

And we do this:

prepended_list = [None] + input_characters
print(prepended_list)

Output is:

[None, 'a', 'b', 'c', 'd']

But, if we do this:

prepended_list = [None] + [input_characters]
print(prepended_list)

Output is:

[None, ['a', 'b', 'c', 'd']]

Do you get the intuition? The second one is prepending the input_characters as a separate list with None, not prepending the each elements of a list.

1 Like

Make sure to have num_iterations = 22001, which you changed for debugging purpose.

num iterations right now it is 2000. I got the prepend list explanation. although still not finding the solution. I will dig my neurons for a while :slight_smile: hopefully I get it.


KeyError Traceback (most recent call last)
in
----> 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!”)

in model(data_x, ix_to_char, char_to_ix, num_iterations, n_a, dino_names, vocab_size, verbose)

Why num_iterations is 2000? Change it back to the original number to get the expected output. Furthermore, you are still using [] with single_example_ix in X.

1 Like

no no I have removed. my single_example_ix has an issue which I understood from other posts that the code I used it is indicating more of dictionary indices where as I need to use word indices.

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]

single_example_ix: 11
[single_example_ix]: 1
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

All tests passed!

can I know why I am still getting wrong output??

isn’t your output the same as the expected output?
Capture

One more thing: remove the print statement which you added in your code for debugging purpose. Otherwise, grader will fail you or give an error.

One more thing: remove the print statement which you added in your code for debugging purpose. Otherwise, grader will fail you or give an error. I will do it sir.

Yes the results are as expected output still wrong output is mentioned ;-(