# Week 1, Assignment 2, Jazz, predict\_and\_sample

**URL:** <https://community.deeplearning.ai/t/week-1-assignment-2-jazz-predict-and-sample/28687>\
**Category:** Sequence Models\
**Tags:** coursera-platform\
**Created:** [August 13, 2021, 7:11pm UTC](https://community.deeplearning.ai/t/week-1-assignment-2-jazz-predict-and-sample/28687 "2021-08-13T19:11:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pooriaaz92](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@Pooriaaz92](https://community.deeplearning.ai/u/Pooriaaz92)\
**Post date:** [August 13, 2021, 7:11pm UTC](https://community.deeplearning.ai/t/week-1-assignment-2-jazz-predict-and-sample/28687/1 "2021-08-13T19:11:48Z")

</div>

Hi guys,

I got this type of error after running the function predict\_and\_sample.

I guess the problem with indices, but I’ve tried axis=0, -1, 1, 2, and all of theses got me an error.

I should mention that before this cell I have no error.

ValueError Traceback (most recent call last)  
 in   
----\> 1 results, indices = predict\_and\_sample(inference\_model, x\_initializer, a\_initializer, c\_initializer)  
2  
3 print(“np.argmax(results[12]) =”, np.argmax(results[12]))  
4 print(“np.argmax(results[17]) =”, np.argmax(results[17]))  
5 print(“list(indices[12:18]) =”, list(indices[12:18]))

in predict\_and\_sample(inference\_model, x\_initializer, a\_initializer, c\_initializer)  
24 pred = inference\_model.predict([x\_initializer, a\_initializer, c\_initializer])  
25 # Step 2: Convert “pred” into an np.array() of indices with the maximum probabilities  
—\> 26 indices = np.argmax(pred, axis=-1)  
27 # Step 3: Convert indices to one-hot vectors, the shape of the results should be (1, )  
28 results = to\_categorical(indices, num\_classes=n\_values)

\< **array\_function** internals\> in argmax(\*args, \*\*kwargs)

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in argmax(a, axis, out)  
1184  
1185 “”"  
 → 1186 return \_wrapfunc(a, ‘argmax’, axis=axis, out=out)  
1187  
1188

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in \_wrapfunc(obj, method, \*args, \*\*kwds)  
56 bound = getattr(obj, method, None)  
57 if bound is None:  
—\> 58 return \_wrapit(obj, method, \*args, \*\*kwds)  
59  
60 try:

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in \_wrapit(obj, method, \*args, \*\*kwds)  
45 except AttributeError:  
46 wrap = None  
—\> 47 result = getattr(asarray(obj), method)(\*args, \*\*kwds)  
48 if wrap:  
49 if not isinstance(result, mu.ndarray):

**ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()**

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [August 13, 2021, 7:48pm UTC](https://community.deeplearning.ai/t/week-1-assignment-2-jazz-predict-and-sample/28687/2 "2021-08-13T19:48:39Z")

</div>

Try resetting the kernel and re-running all of the cells in the notebook.  
Then verify that every output cell passes all of the unit tests.

---

<div class="post-metadata">

**Author:** ![Pooriaaz92](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@Pooriaaz92](https://community.deeplearning.ai/u/Pooriaaz92)\
**Post date:** [August 13, 2021, 8:07pm UTC](https://community.deeplearning.ai/t/week-1-assignment-2-jazz-predict-and-sample/28687/3 "2021-08-13T20:07:13Z")

</div>

I did this many times dear but I still have this error!!  
I just realized that there is still _test\_utils.py_ instead of _public\_tests.py_ though I refresh the Lab. do you have any idea?

---

<div class="post-metadata">

**Author:** ![Pooriaaz92](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@Pooriaaz92](https://community.deeplearning.ai/u/Pooriaaz92)\
**Post date:** [August 13, 2021, 8:13pm UTC](https://community.deeplearning.ai/t/week-1-assignment-2-jazz-predict-and-sample/28687/4 "2021-08-13T20:13:41Z")

</div>

Oh, apparently I got this error after running the cell

# UNIT TEST

inference\_summary = summary(inference\_model)  
comparator(inference\_summary, music\_inference\_model\_out)

* * *

AttributeError Traceback (most recent call last)  
 in   
1 # UNIT TEST  
----\> 2 inference\_summary = summary(inference\_model)  
3 comparator(inference\_summary, music\_inference\_model\_out)

~/work/W1A3/test\_utils.py in summary(model)  
36 result =   
37 for layer in model.layers:  
—\> 38 descriptors = [layer. **class**. **name** , layer.output\_shape, layer.count\_params()]  
39 if (type(layer) == Conv2D):  
40 descriptors.append(layer.padding)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base\_layer.py in output\_shape(self)  
2190 'ill-defined for the layer. ’  
2191 'Use `get_output_shape_at(node_index)` ’  
 → 2192 ‘instead.’ % self.name)  
2193  
2194 @property

**AttributeError: The layer “lstm” has multiple inbound nodes, with different output shapes. Hence the notion of “output shape” is ill-defined for the layer. Use `get_output_shape_at(node_index)` instead.**

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [August 13, 2021, 8:52pm UTC](https://community.deeplearning.ai/t/week-1-assignment-2-jazz-predict-and-sample/28687/5 "2021-08-13T20:52:52Z")

</div>

The “multiple inbound nodes” error has a lot of different causes. Search the Forum for that phrase, and you will find a lot of suggestions.

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [August 13, 2021, 8:53pm UTC](https://community.deeplearning.ai/t/week-1-assignment-2-jazz-predict-and-sample/28687/6 "2021-08-13T20:53:27Z")

</div>

> [@Pooriaaz92](#):
>
> there is still _test\_utils.py_ instead of _public\_tests.py_

New versions of the notebook do not necessarily delete old files you still had in your workspace.

---

<div class="post-metadata">

**Author:** ![Pooriaaz92](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@Pooriaaz92](https://community.deeplearning.ai/u/Pooriaaz92)\
**Post date:** [August 14, 2021, 4:54am UTC](https://community.deeplearning.ai/t/week-1-assignment-2-jazz-predict-and-sample/28687/7 "2021-08-14T04:54:19Z")

</div>

Thanks, I’ll try it.

---

<div class="post-metadata">

**Author:** ![cppiod](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@cppiod](https://community.deeplearning.ai/u/cppiod)\
**Post date:** [March 11, 2024, 1:06am UTC](https://community.deeplearning.ai/t/week-1-assignment-2-jazz-predict-and-sample/28687/8 "2024-03-11T01:06:49Z")

</div>

How it goes afterwards? I got the same error.
