Guest User

Untitled

a guest
Jul 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. for i in range(int(len(all_text_chars)/SEQUENCE_LENGTH)):
  2.  
  3. #Get next sequence of length 57 as input.
  4. X_sequence = all_text_chars[i*SEQUENCE_LENGTH:(i+1)*SEQUENCE_LENGTH]
  5.  
  6. # Convert the above sequence to the integer mapping using our mapping dictionary.
  7. X_sequence_ix = [char_to_ix[value] for value in X_sequence]
  8.  
  9. # Create a skeleton for the input sequence:
  10. # we create a 2d numpy matrix which has a feature array of 94
  11. # long for each of the 57 characters in sequence.
  12. # This way we basically one hot encode our sequences.
  13. input_sequence = np.zeros((SEQUENCE_LENGTH, NUMBER_FEATURES))
  14.  
  15. # The one hot encoding process: we replace a zero with a one
  16. # on a position in the input sequence which corresponds with the index
  17. # of a character in our converted array!
  18. for j in range(SEQUENCE_LENGTH):
  19. input_sequence[j][X_sequence_ix[j]] = 1.
  20.  
  21. # For each spot in X (which stands for each sequence) we
  22. # fill in our one hot encoded array!
  23. X[i] = input_sequence
  24.  
  25. #Same for y!
  26. y_sequence = all_text_chars[i*SEQUENCE_LENGTH+1:(i+1)*SEQUENCE_LENGTH+1]
  27.  
  28. y_sequence_ix = [char_to_ix[value] for value in y_sequence]
  29.  
  30. target_sequence = np.zeros((SEQUENCE_LENGTH, NUMBER_FEATURES))
  31.  
  32. for j in range(SEQUENCE_LENGTH):
  33. target_sequence[j][y_sequence_ix[j]] = 1.
  34.  
  35. y[i] = target_sequence
Add Comment
Please, Sign In to add comment