Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab1 part 2: Batch definition to create training examples issue #120

Open
OnigiriJack opened this issue Apr 8, 2023 · 1 comment
Open

Comments

@OnigiriJack
Copy link

I could pass the test with my code and the solution code however the next code block always fails with the following:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
[<ipython-input-71-5b7b68580807>](https://n4nxjj8wuum-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20230406-060150-RC00_522300627#) in <cell line: 4>()
      4 for i, (input_idx, target_idx) in enumerate(zip(np.squeeze(x_batch), np.squeeze(y_batch))):
      5     print("Step {:3d}".format(i))
----> 6     print("  input: {} ({:s})".format(input_idx, repr(idx2char[input_idx])))
      7     print("  expected output: {} ({:s})".format(target_idx, repr(idx2char[target_idx])))

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

MY code (spoiler: not as elegant)

   input_batch = np.array([])
   output_batch = np.array([])
   for x in range(batch_size):
   slice_end = idx[x] + seq_length
   input_batch = np.append(input_batch, vectorized_songs[idx[x]:slice_end])
   output_batch = np.append(output_batch, vectorized_songs[idx[x] + 1: slice_end + 1])`
@brabiei21
Copy link

It's been a while so I hope this is helpful. input_idx and target_idx are floats so you need to cast them into integers.

for i, (input_idx, target_idx) in enumerate(zip(np.squeeze(x_batch), np.squeeze(y_batch))):
    input_idx = int(input_idx)
    target_idx = int(target_idx)
    print(input_idx, target_idx)
    print("Step {:3d}".format(i))
    print("  input: {} ({:s})".format(input_idx, repr(idx2char[input_idx])))
    print("  expected output: {} ({:s})".format(target_idx, repr(idx2char[target_idx])))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants