Open In Colab

Open In Colab

CNN Language Model

The following was developed by Harini Appansrinivasan, NYU as part of an assignment submission.

import numpy as np
from numpy import array
import keras as K
import tensorflow as tf
from keras.models import Model
from keras.models import Sequential
from keras.layers.convolutional import Conv1D, MaxPooling1D
from keras.layers import Activation, Flatten, Dense
from keras.layers import Conv1D, MaxPooling1D, Dropout

# split input sequence into inputs X of size = n_steps and targets Y with the subsequent integer after each X
def split_sequence(sequence, n_steps):
    X, y = list(), list()
    for i in range(len(sequence)):
        end_ix = i + n_steps                                     # find the end of this pattern
        if end_ix > len(sequence)-1:                             # condition to check if we are beyond the input sequence
            break
        seq_x, seq_y = sequence[i:end_ix], sequence[end_ix]      # gather input and output parts of the pattern
        X.append(seq_x)
        y.append(seq_y)
    return array(X), array(y)

data = 'Chios island is crescent or kidney shaped, 50 km (31 mi) long from north to south, and 29 km (18 mi) at its widest, covering an area of 842.289 km2 (325.210 sq mi).[2] The terrain is mountainous and arid, with a ridge of mountains running the length of the island. The two largest of these mountains, Pelineon (1,297 m (4,255 ft)) and Epos (1,188 m (3,898 ft)), are situated in the north of the island. The center of the island is divided between east and west by a range of smaller peaks, known as Provatas.'

# creating a vocabulary of unique characters
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
print('data has %d characters, %d unique.' % (data_size, vocab_size))

# creating a dictionary, mapping characters to index and index to characters
char_to_ix = { ch:i for i,ch in enumerate(chars) }
print(char_to_ix)
ix_to_char = { i:ch for i,ch in enumerate(chars) }
print(ix_to_char)
seq_length = 25        # number of characters in each input sequence from which the next char is predicted
data_tokens = [char_to_ix[ch] for ch in list(data)]               # convert all characters in data string into t tokens
X_tokens, y_tokens = split_sequence(data_tokens, seq_length)      # split into samples, inputs X and targets y
for i in range(len(X_tokens)):   
    print(X_tokens[i], y_tokens[i])                                 # summarize the split input and target tokens
num_samples = X_tokens.shape[0]
print(X_tokens.shape)     # shape of tokenized input array with sequence length = 25
print(y_tokens.shape)     # shape of tokenized target array
print(num_samples)        # total number of inputs to the CNN
print(seq_length)         # number of characters in each input sequence from which the next char is predicted
print(vocab_size)         # total number of unique characters, ie, number of output classes
# function to one-hot encode the data for each unique class k=vocab_size
def onehot_encoding(data):
  if (len(data.shape)==2):
    onehot_data = np.zeros((data.shape[0] * data.shape[1], data.max()+1), dtype=int)   # a 3D array of 0's
    onehot_data[np.arange(data.shape[0] * data.shape[1]), data.flatten()] = 1          # replace 0 with 1 at that index of the original array
    onehot_data = onehot_data.reshape(data.shape[0], data.shape[1], vocab_size)        # reshape into [num_samples, seq_length, vocab_size] format
  elif (len(data.shape)==1):
    onehot_data = np.zeros((data.shape[0], data.max()+1), dtype=int)                   # a 2D array of 0's
    onehot_data[np.arange(data.shape[0]), data.flatten()] = 1                          # replace 0 with 1 at that index of the original array
    onehot_data = onehot_data.reshape(data.shape[0], vocab_size)                       # reshape into [num_samples, vocab_size] format
  return onehot_data
X_onehot = onehot_encoding(X_tokens)  # one-hot encode the inputs
X_onehot.shape                        # shape = [num_samples, seq_length, vocab_size]
y_onehot = onehot_encoding(y_tokens)  # one-hot encode the targets
y_onehot.shape                        # shape = [num_samples, vocab_size]
data has 508 characters, 43 unique.
{'7': 0, 'c': 1, ')': 2, 'i': 3, 'h': 4, 'p': 5, 'T': 6, 'f': 7, '(': 8, 'C': 9, '[': 10, '.': 11, 'a': 12, 'b': 13, 't': 14, 'l': 15, '1': 16, ',': 17, '0': 18, 'u': 19, 'k': 20, 'n': 21, 's': 22, 'v': 23, 'r': 24, 'E': 25, '9': 26, '8': 27, 'P': 28, 'e': 29, '2': 30, 'q': 31, 'd': 32, 'g': 33, '3': 34, 'm': 35, 'w': 36, ' ': 37, ']': 38, '4': 39, '5': 40, 'y': 41, 'o': 42}
{0: '7', 1: 'c', 2: ')', 3: 'i', 4: 'h', 5: 'p', 6: 'T', 7: 'f', 8: '(', 9: 'C', 10: '[', 11: '.', 12: 'a', 13: 'b', 14: 't', 15: 'l', 16: '1', 17: ',', 18: '0', 19: 'u', 20: 'k', 21: 'n', 22: 's', 23: 'v', 24: 'r', 25: 'E', 26: '9', 27: '8', 28: 'P', 29: 'e', 30: '2', 31: 'q', 32: 'd', 33: 'g', 34: '3', 35: 'm', 36: 'w', 37: ' ', 38: ']', 39: '4', 40: '5', 41: 'y', 42: 'o'}
[ 9  4  3 42 22 37  3 22 15 12 21 32 37  3 22 37  1 24 29 22  1 29 21 14
 37] 42
[ 4  3 42 22 37  3 22 15 12 21 32 37  3 22 37  1 24 29 22  1 29 21 14 37
 42] 24
[ 3 42 22 37  3 22 15 12 21 32 37  3 22 37  1 24 29 22  1 29 21 14 37 42
 24] 37
[42 22 37  3 22 15 12 21 32 37  3 22 37  1 24 29 22  1 29 21 14 37 42 24
 37] 20
[22 37  3 22 15 12 21 32 37  3 22 37  1 24 29 22  1 29 21 14 37 42 24 37
 20] 3
[37  3 22 15 12 21 32 37  3 22 37  1 24 29 22  1 29 21 14 37 42 24 37 20
  3] 32
[ 3 22 15 12 21 32 37  3 22 37  1 24 29 22  1 29 21 14 37 42 24 37 20  3
 32] 21
[22 15 12 21 32 37  3 22 37  1 24 29 22  1 29 21 14 37 42 24 37 20  3 32
 21] 29
[15 12 21 32 37  3 22 37  1 24 29 22  1 29 21 14 37 42 24 37 20  3 32 21
 29] 41
[12 21 32 37  3 22 37  1 24 29 22  1 29 21 14 37 42 24 37 20  3 32 21 29
 41] 37
[21 32 37  3 22 37  1 24 29 22  1 29 21 14 37 42 24 37 20  3 32 21 29 41
 37] 22
[32 37  3 22 37  1 24 29 22  1 29 21 14 37 42 24 37 20  3 32 21 29 41 37
 22] 4
[37  3 22 37  1 24 29 22  1 29 21 14 37 42 24 37 20  3 32 21 29 41 37 22
  4] 12
[ 3 22 37  1 24 29 22  1 29 21 14 37 42 24 37 20  3 32 21 29 41 37 22  4
 12] 5
[22 37  1 24 29 22  1 29 21 14 37 42 24 37 20  3 32 21 29 41 37 22  4 12
  5] 29
[37  1 24 29 22  1 29 21 14 37 42 24 37 20  3 32 21 29 41 37 22  4 12  5
 29] 32
[ 1 24 29 22  1 29 21 14 37 42 24 37 20  3 32 21 29 41 37 22  4 12  5 29
 32] 17
[24 29 22  1 29 21 14 37 42 24 37 20  3 32 21 29 41 37 22  4 12  5 29 32
 17] 37
[29 22  1 29 21 14 37 42 24 37 20  3 32 21 29 41 37 22  4 12  5 29 32 17
 37] 40
[22  1 29 21 14 37 42 24 37 20  3 32 21 29 41 37 22  4 12  5 29 32 17 37
 40] 18
[ 1 29 21 14 37 42 24 37 20  3 32 21 29 41 37 22  4 12  5 29 32 17 37 40
 18] 37
[29 21 14 37 42 24 37 20  3 32 21 29 41 37 22  4 12  5 29 32 17 37 40 18
 37] 20
[21 14 37 42 24 37 20  3 32 21 29 41 37 22  4 12  5 29 32 17 37 40 18 37
 20] 35
[14 37 42 24 37 20  3 32 21 29 41 37 22  4 12  5 29 32 17 37 40 18 37 20
 35] 37
[37 42 24 37 20  3 32 21 29 41 37 22  4 12  5 29 32 17 37 40 18 37 20 35
 37] 8
[42 24 37 20  3 32 21 29 41 37 22  4 12  5 29 32 17 37 40 18 37 20 35 37
  8] 34
[24 37 20  3 32 21 29 41 37 22  4 12  5 29 32 17 37 40 18 37 20 35 37  8
 34] 16
[37 20  3 32 21 29 41 37 22  4 12  5 29 32 17 37 40 18 37 20 35 37  8 34
 16] 37
[20  3 32 21 29 41 37 22  4 12  5 29 32 17 37 40 18 37 20 35 37  8 34 16
 37] 35
[ 3 32 21 29 41 37 22  4 12  5 29 32 17 37 40 18 37 20 35 37  8 34 16 37
 35] 3
[32 21 29 41 37 22  4 12  5 29 32 17 37 40 18 37 20 35 37  8 34 16 37 35
  3] 2
[21 29 41 37 22  4 12  5 29 32 17 37 40 18 37 20 35 37  8 34 16 37 35  3
  2] 37
[29 41 37 22  4 12  5 29 32 17 37 40 18 37 20 35 37  8 34 16 37 35  3  2
 37] 15
[41 37 22  4 12  5 29 32 17 37 40 18 37 20 35 37  8 34 16 37 35  3  2 37
 15] 42
[37 22  4 12  5 29 32 17 37 40 18 37 20 35 37  8 34 16 37 35  3  2 37 15
 42] 21
[22  4 12  5 29 32 17 37 40 18 37 20 35 37  8 34 16 37 35  3  2 37 15 42
 21] 33
[ 4 12  5 29 32 17 37 40 18 37 20 35 37  8 34 16 37 35  3  2 37 15 42 21
 33] 37
[12  5 29 32 17 37 40 18 37 20 35 37  8 34 16 37 35  3  2 37 15 42 21 33
 37] 7
[ 5 29 32 17 37 40 18 37 20 35 37  8 34 16 37 35  3  2 37 15 42 21 33 37
  7] 24
[29 32 17 37 40 18 37 20 35 37  8 34 16 37 35  3  2 37 15 42 21 33 37  7
 24] 42
[32 17 37 40 18 37 20 35 37  8 34 16 37 35  3  2 37 15 42 21 33 37  7 24
 42] 35
[17 37 40 18 37 20 35 37  8 34 16 37 35  3  2 37 15 42 21 33 37  7 24 42
 35] 37
[37 40 18 37 20 35 37  8 34 16 37 35  3  2 37 15 42 21 33 37  7 24 42 35
 37] 21
[40 18 37 20 35 37  8 34 16 37 35  3  2 37 15 42 21 33 37  7 24 42 35 37
 21] 42
[18 37 20 35 37  8 34 16 37 35  3  2 37 15 42 21 33 37  7 24 42 35 37 21
 42] 24
[37 20 35 37  8 34 16 37 35  3  2 37 15 42 21 33 37  7 24 42 35 37 21 42
 24] 14
[20 35 37  8 34 16 37 35  3  2 37 15 42 21 33 37  7 24 42 35 37 21 42 24
 14] 4
[35 37  8 34 16 37 35  3  2 37 15 42 21 33 37  7 24 42 35 37 21 42 24 14
  4] 37
[37  8 34 16 37 35  3  2 37 15 42 21 33 37  7 24 42 35 37 21 42 24 14  4
 37] 14
[ 8 34 16 37 35  3  2 37 15 42 21 33 37  7 24 42 35 37 21 42 24 14  4 37
 14] 42
[34 16 37 35  3  2 37 15 42 21 33 37  7 24 42 35 37 21 42 24 14  4 37 14
 42] 37
[16 37 35  3  2 37 15 42 21 33 37  7 24 42 35 37 21 42 24 14  4 37 14 42
 37] 22
[37 35  3  2 37 15 42 21 33 37  7 24 42 35 37 21 42 24 14  4 37 14 42 37
 22] 42
[35  3  2 37 15 42 21 33 37  7 24 42 35 37 21 42 24 14  4 37 14 42 37 22
 42] 19
[ 3  2 37 15 42 21 33 37  7 24 42 35 37 21 42 24 14  4 37 14 42 37 22 42
 19] 14
[ 2 37 15 42 21 33 37  7 24 42 35 37 21 42 24 14  4 37 14 42 37 22 42 19
 14] 4
[37 15 42 21 33 37  7 24 42 35 37 21 42 24 14  4 37 14 42 37 22 42 19 14
  4] 17
[15 42 21 33 37  7 24 42 35 37 21 42 24 14  4 37 14 42 37 22 42 19 14  4
 17] 37
[42 21 33 37  7 24 42 35 37 21 42 24 14  4 37 14 42 37 22 42 19 14  4 17
 37] 12
[21 33 37  7 24 42 35 37 21 42 24 14  4 37 14 42 37 22 42 19 14  4 17 37
 12] 21
[33 37  7 24 42 35 37 21 42 24 14  4 37 14 42 37 22 42 19 14  4 17 37 12
 21] 32
[37  7 24 42 35 37 21 42 24 14  4 37 14 42 37 22 42 19 14  4 17 37 12 21
 32] 37
[ 7 24 42 35 37 21 42 24 14  4 37 14 42 37 22 42 19 14  4 17 37 12 21 32
 37] 30
[24 42 35 37 21 42 24 14  4 37 14 42 37 22 42 19 14  4 17 37 12 21 32 37
 30] 26
[42 35 37 21 42 24 14  4 37 14 42 37 22 42 19 14  4 17 37 12 21 32 37 30
 26] 37
[35 37 21 42 24 14  4 37 14 42 37 22 42 19 14  4 17 37 12 21 32 37 30 26
 37] 20
[37 21 42 24 14  4 37 14 42 37 22 42 19 14  4 17 37 12 21 32 37 30 26 37
 20] 35
[21 42 24 14  4 37 14 42 37 22 42 19 14  4 17 37 12 21 32 37 30 26 37 20
 35] 37
[42 24 14  4 37 14 42 37 22 42 19 14  4 17 37 12 21 32 37 30 26 37 20 35
 37] 8
[24 14  4 37 14 42 37 22 42 19 14  4 17 37 12 21 32 37 30 26 37 20 35 37
  8] 16
[14  4 37 14 42 37 22 42 19 14  4 17 37 12 21 32 37 30 26 37 20 35 37  8
 16] 27
[ 4 37 14 42 37 22 42 19 14  4 17 37 12 21 32 37 30 26 37 20 35 37  8 16
 27] 37
[37 14 42 37 22 42 19 14  4 17 37 12 21 32 37 30 26 37 20 35 37  8 16 27
 37] 35
[14 42 37 22 42 19 14  4 17 37 12 21 32 37 30 26 37 20 35 37  8 16 27 37
 35] 3
[42 37 22 42 19 14  4 17 37 12 21 32 37 30 26 37 20 35 37  8 16 27 37 35
  3] 2
[37 22 42 19 14  4 17 37 12 21 32 37 30 26 37 20 35 37  8 16 27 37 35  3
  2] 37
[22 42 19 14  4 17 37 12 21 32 37 30 26 37 20 35 37  8 16 27 37 35  3  2
 37] 12
[42 19 14  4 17 37 12 21 32 37 30 26 37 20 35 37  8 16 27 37 35  3  2 37
 12] 14
[19 14  4 17 37 12 21 32 37 30 26 37 20 35 37  8 16 27 37 35  3  2 37 12
 14] 37
[14  4 17 37 12 21 32 37 30 26 37 20 35 37  8 16 27 37 35  3  2 37 12 14
 37] 3
[ 4 17 37 12 21 32 37 30 26 37 20 35 37  8 16 27 37 35  3  2 37 12 14 37
  3] 14
[17 37 12 21 32 37 30 26 37 20 35 37  8 16 27 37 35  3  2 37 12 14 37  3
 14] 22
[37 12 21 32 37 30 26 37 20 35 37  8 16 27 37 35  3  2 37 12 14 37  3 14
 22] 37
[12 21 32 37 30 26 37 20 35 37  8 16 27 37 35  3  2 37 12 14 37  3 14 22
 37] 36
[21 32 37 30 26 37 20 35 37  8 16 27 37 35  3  2 37 12 14 37  3 14 22 37
 36] 3
[32 37 30 26 37 20 35 37  8 16 27 37 35  3  2 37 12 14 37  3 14 22 37 36
  3] 32
[37 30 26 37 20 35 37  8 16 27 37 35  3  2 37 12 14 37  3 14 22 37 36  3
 32] 29
[30 26 37 20 35 37  8 16 27 37 35  3  2 37 12 14 37  3 14 22 37 36  3 32
 29] 22
[26 37 20 35 37  8 16 27 37 35  3  2 37 12 14 37  3 14 22 37 36  3 32 29
 22] 14
[37 20 35 37  8 16 27 37 35  3  2 37 12 14 37  3 14 22 37 36  3 32 29 22
 14] 17
[20 35 37  8 16 27 37 35  3  2 37 12 14 37  3 14 22 37 36  3 32 29 22 14
 17] 37
[35 37  8 16 27 37 35  3  2 37 12 14 37  3 14 22 37 36  3 32 29 22 14 17
 37] 1
[37  8 16 27 37 35  3  2 37 12 14 37  3 14 22 37 36  3 32 29 22 14 17 37
  1] 42
[ 8 16 27 37 35  3  2 37 12 14 37  3 14 22 37 36  3 32 29 22 14 17 37  1
 42] 23
[16 27 37 35  3  2 37 12 14 37  3 14 22 37 36  3 32 29 22 14 17 37  1 42
 23] 29
[27 37 35  3  2 37 12 14 37  3 14 22 37 36  3 32 29 22 14 17 37  1 42 23
 29] 24
[37 35  3  2 37 12 14 37  3 14 22 37 36  3 32 29 22 14 17 37  1 42 23 29
 24] 3
[35  3  2 37 12 14 37  3 14 22 37 36  3 32 29 22 14 17 37  1 42 23 29 24
  3] 21
[ 3  2 37 12 14 37  3 14 22 37 36  3 32 29 22 14 17 37  1 42 23 29 24  3
 21] 33
[ 2 37 12 14 37  3 14 22 37 36  3 32 29 22 14 17 37  1 42 23 29 24  3 21
 33] 37
[37 12 14 37  3 14 22 37 36  3 32 29 22 14 17 37  1 42 23 29 24  3 21 33
 37] 12
[12 14 37  3 14 22 37 36  3 32 29 22 14 17 37  1 42 23 29 24  3 21 33 37
 12] 21
[14 37  3 14 22 37 36  3 32 29 22 14 17 37  1 42 23 29 24  3 21 33 37 12
 21] 37
[37  3 14 22 37 36  3 32 29 22 14 17 37  1 42 23 29 24  3 21 33 37 12 21
 37] 12
[ 3 14 22 37 36  3 32 29 22 14 17 37  1 42 23 29 24  3 21 33 37 12 21 37
 12] 24
[14 22 37 36  3 32 29 22 14 17 37  1 42 23 29 24  3 21 33 37 12 21 37 12
 24] 29
[22 37 36  3 32 29 22 14 17 37  1 42 23 29 24  3 21 33 37 12 21 37 12 24
 29] 12
[37 36  3 32 29 22 14 17 37  1 42 23 29 24  3 21 33 37 12 21 37 12 24 29
 12] 37
[36  3 32 29 22 14 17 37  1 42 23 29 24  3 21 33 37 12 21 37 12 24 29 12
 37] 42
[ 3 32 29 22 14 17 37  1 42 23 29 24  3 21 33 37 12 21 37 12 24 29 12 37
 42] 7
[32 29 22 14 17 37  1 42 23 29 24  3 21 33 37 12 21 37 12 24 29 12 37 42
  7] 37
[29 22 14 17 37  1 42 23 29 24  3 21 33 37 12 21 37 12 24 29 12 37 42  7
 37] 27
[22 14 17 37  1 42 23 29 24  3 21 33 37 12 21 37 12 24 29 12 37 42  7 37
 27] 39
[14 17 37  1 42 23 29 24  3 21 33 37 12 21 37 12 24 29 12 37 42  7 37 27
 39] 30
[17 37  1 42 23 29 24  3 21 33 37 12 21 37 12 24 29 12 37 42  7 37 27 39
 30] 11
[37  1 42 23 29 24  3 21 33 37 12 21 37 12 24 29 12 37 42  7 37 27 39 30
 11] 30
[ 1 42 23 29 24  3 21 33 37 12 21 37 12 24 29 12 37 42  7 37 27 39 30 11
 30] 27
[42 23 29 24  3 21 33 37 12 21 37 12 24 29 12 37 42  7 37 27 39 30 11 30
 27] 26
[23 29 24  3 21 33 37 12 21 37 12 24 29 12 37 42  7 37 27 39 30 11 30 27
 26] 37
[29 24  3 21 33 37 12 21 37 12 24 29 12 37 42  7 37 27 39 30 11 30 27 26
 37] 20
[24  3 21 33 37 12 21 37 12 24 29 12 37 42  7 37 27 39 30 11 30 27 26 37
 20] 35
[ 3 21 33 37 12 21 37 12 24 29 12 37 42  7 37 27 39 30 11 30 27 26 37 20
 35] 30
[21 33 37 12 21 37 12 24 29 12 37 42  7 37 27 39 30 11 30 27 26 37 20 35
 30] 37
[33 37 12 21 37 12 24 29 12 37 42  7 37 27 39 30 11 30 27 26 37 20 35 30
 37] 8
[37 12 21 37 12 24 29 12 37 42  7 37 27 39 30 11 30 27 26 37 20 35 30 37
  8] 34
[12 21 37 12 24 29 12 37 42  7 37 27 39 30 11 30 27 26 37 20 35 30 37  8
 34] 30
[21 37 12 24 29 12 37 42  7 37 27 39 30 11 30 27 26 37 20 35 30 37  8 34
 30] 40
[37 12 24 29 12 37 42  7 37 27 39 30 11 30 27 26 37 20 35 30 37  8 34 30
 40] 11
[12 24 29 12 37 42  7 37 27 39 30 11 30 27 26 37 20 35 30 37  8 34 30 40
 11] 30
[24 29 12 37 42  7 37 27 39 30 11 30 27 26 37 20 35 30 37  8 34 30 40 11
 30] 16
[29 12 37 42  7 37 27 39 30 11 30 27 26 37 20 35 30 37  8 34 30 40 11 30
 16] 18
[12 37 42  7 37 27 39 30 11 30 27 26 37 20 35 30 37  8 34 30 40 11 30 16
 18] 37
[37 42  7 37 27 39 30 11 30 27 26 37 20 35 30 37  8 34 30 40 11 30 16 18
 37] 22
[42  7 37 27 39 30 11 30 27 26 37 20 35 30 37  8 34 30 40 11 30 16 18 37
 22] 31
[ 7 37 27 39 30 11 30 27 26 37 20 35 30 37  8 34 30 40 11 30 16 18 37 22
 31] 37
[37 27 39 30 11 30 27 26 37 20 35 30 37  8 34 30 40 11 30 16 18 37 22 31
 37] 35
[27 39 30 11 30 27 26 37 20 35 30 37  8 34 30 40 11 30 16 18 37 22 31 37
 35] 3
[39 30 11 30 27 26 37 20 35 30 37  8 34 30 40 11 30 16 18 37 22 31 37 35
  3] 2
[30 11 30 27 26 37 20 35 30 37  8 34 30 40 11 30 16 18 37 22 31 37 35  3
  2] 11
[11 30 27 26 37 20 35 30 37  8 34 30 40 11 30 16 18 37 22 31 37 35  3  2
 11] 10
[30 27 26 37 20 35 30 37  8 34 30 40 11 30 16 18 37 22 31 37 35  3  2 11
 10] 30
[27 26 37 20 35 30 37  8 34 30 40 11 30 16 18 37 22 31 37 35  3  2 11 10
 30] 38
[26 37 20 35 30 37  8 34 30 40 11 30 16 18 37 22 31 37 35  3  2 11 10 30
 38] 37
[37 20 35 30 37  8 34 30 40 11 30 16 18 37 22 31 37 35  3  2 11 10 30 38
 37] 6
[20 35 30 37  8 34 30 40 11 30 16 18 37 22 31 37 35  3  2 11 10 30 38 37
  6] 4
[35 30 37  8 34 30 40 11 30 16 18 37 22 31 37 35  3  2 11 10 30 38 37  6
  4] 29
[30 37  8 34 30 40 11 30 16 18 37 22 31 37 35  3  2 11 10 30 38 37  6  4
 29] 37
[37  8 34 30 40 11 30 16 18 37 22 31 37 35  3  2 11 10 30 38 37  6  4 29
 37] 14
[ 8 34 30 40 11 30 16 18 37 22 31 37 35  3  2 11 10 30 38 37  6  4 29 37
 14] 29
[34 30 40 11 30 16 18 37 22 31 37 35  3  2 11 10 30 38 37  6  4 29 37 14
 29] 24
[30 40 11 30 16 18 37 22 31 37 35  3  2 11 10 30 38 37  6  4 29 37 14 29
 24] 24
[40 11 30 16 18 37 22 31 37 35  3  2 11 10 30 38 37  6  4 29 37 14 29 24
 24] 12
[11 30 16 18 37 22 31 37 35  3  2 11 10 30 38 37  6  4 29 37 14 29 24 24
 12] 3
[30 16 18 37 22 31 37 35  3  2 11 10 30 38 37  6  4 29 37 14 29 24 24 12
  3] 21
[16 18 37 22 31 37 35  3  2 11 10 30 38 37  6  4 29 37 14 29 24 24 12  3
 21] 37
[18 37 22 31 37 35  3  2 11 10 30 38 37  6  4 29 37 14 29 24 24 12  3 21
 37] 3
[37 22 31 37 35  3  2 11 10 30 38 37  6  4 29 37 14 29 24 24 12  3 21 37
  3] 22
[22 31 37 35  3  2 11 10 30 38 37  6  4 29 37 14 29 24 24 12  3 21 37  3
 22] 37
[31 37 35  3  2 11 10 30 38 37  6  4 29 37 14 29 24 24 12  3 21 37  3 22
 37] 35
[37 35  3  2 11 10 30 38 37  6  4 29 37 14 29 24 24 12  3 21 37  3 22 37
 35] 42
[35  3  2 11 10 30 38 37  6  4 29 37 14 29 24 24 12  3 21 37  3 22 37 35
 42] 19
[ 3  2 11 10 30 38 37  6  4 29 37 14 29 24 24 12  3 21 37  3 22 37 35 42
 19] 21
[ 2 11 10 30 38 37  6  4 29 37 14 29 24 24 12  3 21 37  3 22 37 35 42 19
 21] 14
[11 10 30 38 37  6  4 29 37 14 29 24 24 12  3 21 37  3 22 37 35 42 19 21
 14] 12
[10 30 38 37  6  4 29 37 14 29 24 24 12  3 21 37  3 22 37 35 42 19 21 14
 12] 3
[30 38 37  6  4 29 37 14 29 24 24 12  3 21 37  3 22 37 35 42 19 21 14 12
  3] 21
[38 37  6  4 29 37 14 29 24 24 12  3 21 37  3 22 37 35 42 19 21 14 12  3
 21] 42
[37  6  4 29 37 14 29 24 24 12  3 21 37  3 22 37 35 42 19 21 14 12  3 21
 42] 19
[ 6  4 29 37 14 29 24 24 12  3 21 37  3 22 37 35 42 19 21 14 12  3 21 42
 19] 22
[ 4 29 37 14 29 24 24 12  3 21 37  3 22 37 35 42 19 21 14 12  3 21 42 19
 22] 37
[29 37 14 29 24 24 12  3 21 37  3 22 37 35 42 19 21 14 12  3 21 42 19 22
 37] 12
[37 14 29 24 24 12  3 21 37  3 22 37 35 42 19 21 14 12  3 21 42 19 22 37
 12] 21
[14 29 24 24 12  3 21 37  3 22 37 35 42 19 21 14 12  3 21 42 19 22 37 12
 21] 32
[29 24 24 12  3 21 37  3 22 37 35 42 19 21 14 12  3 21 42 19 22 37 12 21
 32] 37
[24 24 12  3 21 37  3 22 37 35 42 19 21 14 12  3 21 42 19 22 37 12 21 32
 37] 12
[24 12  3 21 37  3 22 37 35 42 19 21 14 12  3 21 42 19 22 37 12 21 32 37
 12] 24
[12  3 21 37  3 22 37 35 42 19 21 14 12  3 21 42 19 22 37 12 21 32 37 12
 24] 3
[ 3 21 37  3 22 37 35 42 19 21 14 12  3 21 42 19 22 37 12 21 32 37 12 24
  3] 32
[21 37  3 22 37 35 42 19 21 14 12  3 21 42 19 22 37 12 21 32 37 12 24  3
 32] 17
[37  3 22 37 35 42 19 21 14 12  3 21 42 19 22 37 12 21 32 37 12 24  3 32
 17] 37
[ 3 22 37 35 42 19 21 14 12  3 21 42 19 22 37 12 21 32 37 12 24  3 32 17
 37] 36
[22 37 35 42 19 21 14 12  3 21 42 19 22 37 12 21 32 37 12 24  3 32 17 37
 36] 3
[37 35 42 19 21 14 12  3 21 42 19 22 37 12 21 32 37 12 24  3 32 17 37 36
  3] 14
[35 42 19 21 14 12  3 21 42 19 22 37 12 21 32 37 12 24  3 32 17 37 36  3
 14] 4
[42 19 21 14 12  3 21 42 19 22 37 12 21 32 37 12 24  3 32 17 37 36  3 14
  4] 37
[19 21 14 12  3 21 42 19 22 37 12 21 32 37 12 24  3 32 17 37 36  3 14  4
 37] 12
[21 14 12  3 21 42 19 22 37 12 21 32 37 12 24  3 32 17 37 36  3 14  4 37
 12] 37
[14 12  3 21 42 19 22 37 12 21 32 37 12 24  3 32 17 37 36  3 14  4 37 12
 37] 24
[12  3 21 42 19 22 37 12 21 32 37 12 24  3 32 17 37 36  3 14  4 37 12 37
 24] 3
[ 3 21 42 19 22 37 12 21 32 37 12 24  3 32 17 37 36  3 14  4 37 12 37 24
  3] 32
[21 42 19 22 37 12 21 32 37 12 24  3 32 17 37 36  3 14  4 37 12 37 24  3
 32] 33
[42 19 22 37 12 21 32 37 12 24  3 32 17 37 36  3 14  4 37 12 37 24  3 32
 33] 29
[19 22 37 12 21 32 37 12 24  3 32 17 37 36  3 14  4 37 12 37 24  3 32 33
 29] 37
[22 37 12 21 32 37 12 24  3 32 17 37 36  3 14  4 37 12 37 24  3 32 33 29
 37] 42
[37 12 21 32 37 12 24  3 32 17 37 36  3 14  4 37 12 37 24  3 32 33 29 37
 42] 7
[12 21 32 37 12 24  3 32 17 37 36  3 14  4 37 12 37 24  3 32 33 29 37 42
  7] 37
[21 32 37 12 24  3 32 17 37 36  3 14  4 37 12 37 24  3 32 33 29 37 42  7
 37] 35
[32 37 12 24  3 32 17 37 36  3 14  4 37 12 37 24  3 32 33 29 37 42  7 37
 35] 42
[37 12 24  3 32 17 37 36  3 14  4 37 12 37 24  3 32 33 29 37 42  7 37 35
 42] 19
[12 24  3 32 17 37 36  3 14  4 37 12 37 24  3 32 33 29 37 42  7 37 35 42
 19] 21
[24  3 32 17 37 36  3 14  4 37 12 37 24  3 32 33 29 37 42  7 37 35 42 19
 21] 14
[ 3 32 17 37 36  3 14  4 37 12 37 24  3 32 33 29 37 42  7 37 35 42 19 21
 14] 12
[32 17 37 36  3 14  4 37 12 37 24  3 32 33 29 37 42  7 37 35 42 19 21 14
 12] 3
[17 37 36  3 14  4 37 12 37 24  3 32 33 29 37 42  7 37 35 42 19 21 14 12
  3] 21
[37 36  3 14  4 37 12 37 24  3 32 33 29 37 42  7 37 35 42 19 21 14 12  3
 21] 22
[36  3 14  4 37 12 37 24  3 32 33 29 37 42  7 37 35 42 19 21 14 12  3 21
 22] 37
[ 3 14  4 37 12 37 24  3 32 33 29 37 42  7 37 35 42 19 21 14 12  3 21 22
 37] 24
[14  4 37 12 37 24  3 32 33 29 37 42  7 37 35 42 19 21 14 12  3 21 22 37
 24] 19
[ 4 37 12 37 24  3 32 33 29 37 42  7 37 35 42 19 21 14 12  3 21 22 37 24
 19] 21
[37 12 37 24  3 32 33 29 37 42  7 37 35 42 19 21 14 12  3 21 22 37 24 19
 21] 21
[12 37 24  3 32 33 29 37 42  7 37 35 42 19 21 14 12  3 21 22 37 24 19 21
 21] 3
[37 24  3 32 33 29 37 42  7 37 35 42 19 21 14 12  3 21 22 37 24 19 21 21
  3] 21
[24  3 32 33 29 37 42  7 37 35 42 19 21 14 12  3 21 22 37 24 19 21 21  3
 21] 33
[ 3 32 33 29 37 42  7 37 35 42 19 21 14 12  3 21 22 37 24 19 21 21  3 21
 33] 37
[32 33 29 37 42  7 37 35 42 19 21 14 12  3 21 22 37 24 19 21 21  3 21 33
 37] 14
[33 29 37 42  7 37 35 42 19 21 14 12  3 21 22 37 24 19 21 21  3 21 33 37
 14] 4
[29 37 42  7 37 35 42 19 21 14 12  3 21 22 37 24 19 21 21  3 21 33 37 14
  4] 29
[37 42  7 37 35 42 19 21 14 12  3 21 22 37 24 19 21 21  3 21 33 37 14  4
 29] 37
[42  7 37 35 42 19 21 14 12  3 21 22 37 24 19 21 21  3 21 33 37 14  4 29
 37] 15
[ 7 37 35 42 19 21 14 12  3 21 22 37 24 19 21 21  3 21 33 37 14  4 29 37
 15] 29
[37 35 42 19 21 14 12  3 21 22 37 24 19 21 21  3 21 33 37 14  4 29 37 15
 29] 21
[35 42 19 21 14 12  3 21 22 37 24 19 21 21  3 21 33 37 14  4 29 37 15 29
 21] 33
[42 19 21 14 12  3 21 22 37 24 19 21 21  3 21 33 37 14  4 29 37 15 29 21
 33] 14
[19 21 14 12  3 21 22 37 24 19 21 21  3 21 33 37 14  4 29 37 15 29 21 33
 14] 4
[21 14 12  3 21 22 37 24 19 21 21  3 21 33 37 14  4 29 37 15 29 21 33 14
  4] 37
[14 12  3 21 22 37 24 19 21 21  3 21 33 37 14  4 29 37 15 29 21 33 14  4
 37] 42
[12  3 21 22 37 24 19 21 21  3 21 33 37 14  4 29 37 15 29 21 33 14  4 37
 42] 7
[ 3 21 22 37 24 19 21 21  3 21 33 37 14  4 29 37 15 29 21 33 14  4 37 42
  7] 37
[21 22 37 24 19 21 21  3 21 33 37 14  4 29 37 15 29 21 33 14  4 37 42  7
 37] 14
[22 37 24 19 21 21  3 21 33 37 14  4 29 37 15 29 21 33 14  4 37 42  7 37
 14] 4
[37 24 19 21 21  3 21 33 37 14  4 29 37 15 29 21 33 14  4 37 42  7 37 14
  4] 29
[24 19 21 21  3 21 33 37 14  4 29 37 15 29 21 33 14  4 37 42  7 37 14  4
 29] 37
[19 21 21  3 21 33 37 14  4 29 37 15 29 21 33 14  4 37 42  7 37 14  4 29
 37] 3
[21 21  3 21 33 37 14  4 29 37 15 29 21 33 14  4 37 42  7 37 14  4 29 37
  3] 22
[21  3 21 33 37 14  4 29 37 15 29 21 33 14  4 37 42  7 37 14  4 29 37  3
 22] 15
[ 3 21 33 37 14  4 29 37 15 29 21 33 14  4 37 42  7 37 14  4 29 37  3 22
 15] 12
[21 33 37 14  4 29 37 15 29 21 33 14  4 37 42  7 37 14  4 29 37  3 22 15
 12] 21
[33 37 14  4 29 37 15 29 21 33 14  4 37 42  7 37 14  4 29 37  3 22 15 12
 21] 32
[37 14  4 29 37 15 29 21 33 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21
 32] 11
[14  4 29 37 15 29 21 33 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32
 11] 37
[ 4 29 37 15 29 21 33 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11
 37] 6
[29 37 15 29 21 33 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37
  6] 4
[37 15 29 21 33 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6
  4] 29
[15 29 21 33 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4
 29] 37
[29 21 33 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29
 37] 14
[21 33 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37
 14] 36
[33 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37 14
 36] 42
[14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37 14 36
 42] 37
[ 4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37 14 36 42
 37] 15
[37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37 14 36 42 37
 15] 12
[42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37 14 36 42 37 15
 12] 24
[ 7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37 14 36 42 37 15 12
 24] 33
[37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37 14 36 42 37 15 12 24
 33] 29
[14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37 14 36 42 37 15 12 24 33
 29] 22
[ 4 29 37  3 22 15 12 21 32 11 37  6  4 29 37 14 36 42 37 15 12 24 33 29
 22] 14
[29 37  3 22 15 12 21 32 11 37  6  4 29 37 14 36 42 37 15 12 24 33 29 22
 14] 37
[37  3 22 15 12 21 32 11 37  6  4 29 37 14 36 42 37 15 12 24 33 29 22 14
 37] 42
[ 3 22 15 12 21 32 11 37  6  4 29 37 14 36 42 37 15 12 24 33 29 22 14 37
 42] 7
[22 15 12 21 32 11 37  6  4 29 37 14 36 42 37 15 12 24 33 29 22 14 37 42
  7] 37
[15 12 21 32 11 37  6  4 29 37 14 36 42 37 15 12 24 33 29 22 14 37 42  7
 37] 14
[12 21 32 11 37  6  4 29 37 14 36 42 37 15 12 24 33 29 22 14 37 42  7 37
 14] 4
[21 32 11 37  6  4 29 37 14 36 42 37 15 12 24 33 29 22 14 37 42  7 37 14
  4] 29
[32 11 37  6  4 29 37 14 36 42 37 15 12 24 33 29 22 14 37 42  7 37 14  4
 29] 22
[11 37  6  4 29 37 14 36 42 37 15 12 24 33 29 22 14 37 42  7 37 14  4 29
 22] 29
[37  6  4 29 37 14 36 42 37 15 12 24 33 29 22 14 37 42  7 37 14  4 29 22
 29] 37
[ 6  4 29 37 14 36 42 37 15 12 24 33 29 22 14 37 42  7 37 14  4 29 22 29
 37] 35
[ 4 29 37 14 36 42 37 15 12 24 33 29 22 14 37 42  7 37 14  4 29 22 29 37
 35] 42
[29 37 14 36 42 37 15 12 24 33 29 22 14 37 42  7 37 14  4 29 22 29 37 35
 42] 19
[37 14 36 42 37 15 12 24 33 29 22 14 37 42  7 37 14  4 29 22 29 37 35 42
 19] 21
[14 36 42 37 15 12 24 33 29 22 14 37 42  7 37 14  4 29 22 29 37 35 42 19
 21] 14
[36 42 37 15 12 24 33 29 22 14 37 42  7 37 14  4 29 22 29 37 35 42 19 21
 14] 12
[42 37 15 12 24 33 29 22 14 37 42  7 37 14  4 29 22 29 37 35 42 19 21 14
 12] 3
[37 15 12 24 33 29 22 14 37 42  7 37 14  4 29 22 29 37 35 42 19 21 14 12
  3] 21
[15 12 24 33 29 22 14 37 42  7 37 14  4 29 22 29 37 35 42 19 21 14 12  3
 21] 22
[12 24 33 29 22 14 37 42  7 37 14  4 29 22 29 37 35 42 19 21 14 12  3 21
 22] 17
[24 33 29 22 14 37 42  7 37 14  4 29 22 29 37 35 42 19 21 14 12  3 21 22
 17] 37
[33 29 22 14 37 42  7 37 14  4 29 22 29 37 35 42 19 21 14 12  3 21 22 17
 37] 28
[29 22 14 37 42  7 37 14  4 29 22 29 37 35 42 19 21 14 12  3 21 22 17 37
 28] 29
[22 14 37 42  7 37 14  4 29 22 29 37 35 42 19 21 14 12  3 21 22 17 37 28
 29] 15
[14 37 42  7 37 14  4 29 22 29 37 35 42 19 21 14 12  3 21 22 17 37 28 29
 15] 3
[37 42  7 37 14  4 29 22 29 37 35 42 19 21 14 12  3 21 22 17 37 28 29 15
  3] 21
[42  7 37 14  4 29 22 29 37 35 42 19 21 14 12  3 21 22 17 37 28 29 15  3
 21] 29
[ 7 37 14  4 29 22 29 37 35 42 19 21 14 12  3 21 22 17 37 28 29 15  3 21
 29] 42
[37 14  4 29 22 29 37 35 42 19 21 14 12  3 21 22 17 37 28 29 15  3 21 29
 42] 21
[14  4 29 22 29 37 35 42 19 21 14 12  3 21 22 17 37 28 29 15  3 21 29 42
 21] 37
[ 4 29 22 29 37 35 42 19 21 14 12  3 21 22 17 37 28 29 15  3 21 29 42 21
 37] 8
[29 22 29 37 35 42 19 21 14 12  3 21 22 17 37 28 29 15  3 21 29 42 21 37
  8] 16
[22 29 37 35 42 19 21 14 12  3 21 22 17 37 28 29 15  3 21 29 42 21 37  8
 16] 17
[29 37 35 42 19 21 14 12  3 21 22 17 37 28 29 15  3 21 29 42 21 37  8 16
 17] 30
[37 35 42 19 21 14 12  3 21 22 17 37 28 29 15  3 21 29 42 21 37  8 16 17
 30] 26
[35 42 19 21 14 12  3 21 22 17 37 28 29 15  3 21 29 42 21 37  8 16 17 30
 26] 0
[42 19 21 14 12  3 21 22 17 37 28 29 15  3 21 29 42 21 37  8 16 17 30 26
  0] 37
[19 21 14 12  3 21 22 17 37 28 29 15  3 21 29 42 21 37  8 16 17 30 26  0
 37] 35
[21 14 12  3 21 22 17 37 28 29 15  3 21 29 42 21 37  8 16 17 30 26  0 37
 35] 37
[14 12  3 21 22 17 37 28 29 15  3 21 29 42 21 37  8 16 17 30 26  0 37 35
 37] 8
[12  3 21 22 17 37 28 29 15  3 21 29 42 21 37  8 16 17 30 26  0 37 35 37
  8] 39
[ 3 21 22 17 37 28 29 15  3 21 29 42 21 37  8 16 17 30 26  0 37 35 37  8
 39] 17
[21 22 17 37 28 29 15  3 21 29 42 21 37  8 16 17 30 26  0 37 35 37  8 39
 17] 30
[22 17 37 28 29 15  3 21 29 42 21 37  8 16 17 30 26  0 37 35 37  8 39 17
 30] 40
[17 37 28 29 15  3 21 29 42 21 37  8 16 17 30 26  0 37 35 37  8 39 17 30
 40] 40
[37 28 29 15  3 21 29 42 21 37  8 16 17 30 26  0 37 35 37  8 39 17 30 40
 40] 37
[28 29 15  3 21 29 42 21 37  8 16 17 30 26  0 37 35 37  8 39 17 30 40 40
 37] 7
[29 15  3 21 29 42 21 37  8 16 17 30 26  0 37 35 37  8 39 17 30 40 40 37
  7] 14
[15  3 21 29 42 21 37  8 16 17 30 26  0 37 35 37  8 39 17 30 40 40 37  7
 14] 2
[ 3 21 29 42 21 37  8 16 17 30 26  0 37 35 37  8 39 17 30 40 40 37  7 14
  2] 2
[21 29 42 21 37  8 16 17 30 26  0 37 35 37  8 39 17 30 40 40 37  7 14  2
  2] 37
[29 42 21 37  8 16 17 30 26  0 37 35 37  8 39 17 30 40 40 37  7 14  2  2
 37] 12
[42 21 37  8 16 17 30 26  0 37 35 37  8 39 17 30 40 40 37  7 14  2  2 37
 12] 21
[21 37  8 16 17 30 26  0 37 35 37  8 39 17 30 40 40 37  7 14  2  2 37 12
 21] 32
[37  8 16 17 30 26  0 37 35 37  8 39 17 30 40 40 37  7 14  2  2 37 12 21
 32] 37
[ 8 16 17 30 26  0 37 35 37  8 39 17 30 40 40 37  7 14  2  2 37 12 21 32
 37] 25
[16 17 30 26  0 37 35 37  8 39 17 30 40 40 37  7 14  2  2 37 12 21 32 37
 25] 5
[17 30 26  0 37 35 37  8 39 17 30 40 40 37  7 14  2  2 37 12 21 32 37 25
  5] 42
[30 26  0 37 35 37  8 39 17 30 40 40 37  7 14  2  2 37 12 21 32 37 25  5
 42] 22
[26  0 37 35 37  8 39 17 30 40 40 37  7 14  2  2 37 12 21 32 37 25  5 42
 22] 37
[ 0 37 35 37  8 39 17 30 40 40 37  7 14  2  2 37 12 21 32 37 25  5 42 22
 37] 8
[37 35 37  8 39 17 30 40 40 37  7 14  2  2 37 12 21 32 37 25  5 42 22 37
  8] 16
[35 37  8 39 17 30 40 40 37  7 14  2  2 37 12 21 32 37 25  5 42 22 37  8
 16] 17
[37  8 39 17 30 40 40 37  7 14  2  2 37 12 21 32 37 25  5 42 22 37  8 16
 17] 16
[ 8 39 17 30 40 40 37  7 14  2  2 37 12 21 32 37 25  5 42 22 37  8 16 17
 16] 27
[39 17 30 40 40 37  7 14  2  2 37 12 21 32 37 25  5 42 22 37  8 16 17 16
 27] 27
[17 30 40 40 37  7 14  2  2 37 12 21 32 37 25  5 42 22 37  8 16 17 16 27
 27] 37
[30 40 40 37  7 14  2  2 37 12 21 32 37 25  5 42 22 37  8 16 17 16 27 27
 37] 35
[40 40 37  7 14  2  2 37 12 21 32 37 25  5 42 22 37  8 16 17 16 27 27 37
 35] 37
[40 37  7 14  2  2 37 12 21 32 37 25  5 42 22 37  8 16 17 16 27 27 37 35
 37] 8
[37  7 14  2  2 37 12 21 32 37 25  5 42 22 37  8 16 17 16 27 27 37 35 37
  8] 34
[ 7 14  2  2 37 12 21 32 37 25  5 42 22 37  8 16 17 16 27 27 37 35 37  8
 34] 17
[14  2  2 37 12 21 32 37 25  5 42 22 37  8 16 17 16 27 27 37 35 37  8 34
 17] 27
[ 2  2 37 12 21 32 37 25  5 42 22 37  8 16 17 16 27 27 37 35 37  8 34 17
 27] 26
[ 2 37 12 21 32 37 25  5 42 22 37  8 16 17 16 27 27 37 35 37  8 34 17 27
 26] 27
[37 12 21 32 37 25  5 42 22 37  8 16 17 16 27 27 37 35 37  8 34 17 27 26
 27] 37
[12 21 32 37 25  5 42 22 37  8 16 17 16 27 27 37 35 37  8 34 17 27 26 27
 37] 7
[21 32 37 25  5 42 22 37  8 16 17 16 27 27 37 35 37  8 34 17 27 26 27 37
  7] 14
[32 37 25  5 42 22 37  8 16 17 16 27 27 37 35 37  8 34 17 27 26 27 37  7
 14] 2
[37 25  5 42 22 37  8 16 17 16 27 27 37 35 37  8 34 17 27 26 27 37  7 14
  2] 2
[25  5 42 22 37  8 16 17 16 27 27 37 35 37  8 34 17 27 26 27 37  7 14  2
  2] 17
[ 5 42 22 37  8 16 17 16 27 27 37 35 37  8 34 17 27 26 27 37  7 14  2  2
 17] 37
[42 22 37  8 16 17 16 27 27 37 35 37  8 34 17 27 26 27 37  7 14  2  2 17
 37] 12
[22 37  8 16 17 16 27 27 37 35 37  8 34 17 27 26 27 37  7 14  2  2 17 37
 12] 24
[37  8 16 17 16 27 27 37 35 37  8 34 17 27 26 27 37  7 14  2  2 17 37 12
 24] 29
[ 8 16 17 16 27 27 37 35 37  8 34 17 27 26 27 37  7 14  2  2 17 37 12 24
 29] 37
[16 17 16 27 27 37 35 37  8 34 17 27 26 27 37  7 14  2  2 17 37 12 24 29
 37] 22
[17 16 27 27 37 35 37  8 34 17 27 26 27 37  7 14  2  2 17 37 12 24 29 37
 22] 3
[16 27 27 37 35 37  8 34 17 27 26 27 37  7 14  2  2 17 37 12 24 29 37 22
  3] 14
[27 27 37 35 37  8 34 17 27 26 27 37  7 14  2  2 17 37 12 24 29 37 22  3
 14] 19
[27 37 35 37  8 34 17 27 26 27 37  7 14  2  2 17 37 12 24 29 37 22  3 14
 19] 12
[37 35 37  8 34 17 27 26 27 37  7 14  2  2 17 37 12 24 29 37 22  3 14 19
 12] 14
[35 37  8 34 17 27 26 27 37  7 14  2  2 17 37 12 24 29 37 22  3 14 19 12
 14] 29
[37  8 34 17 27 26 27 37  7 14  2  2 17 37 12 24 29 37 22  3 14 19 12 14
 29] 32
[ 8 34 17 27 26 27 37  7 14  2  2 17 37 12 24 29 37 22  3 14 19 12 14 29
 32] 37
[34 17 27 26 27 37  7 14  2  2 17 37 12 24 29 37 22  3 14 19 12 14 29 32
 37] 3
[17 27 26 27 37  7 14  2  2 17 37 12 24 29 37 22  3 14 19 12 14 29 32 37
  3] 21
[27 26 27 37  7 14  2  2 17 37 12 24 29 37 22  3 14 19 12 14 29 32 37  3
 21] 37
[26 27 37  7 14  2  2 17 37 12 24 29 37 22  3 14 19 12 14 29 32 37  3 21
 37] 14
[27 37  7 14  2  2 17 37 12 24 29 37 22  3 14 19 12 14 29 32 37  3 21 37
 14] 4
[37  7 14  2  2 17 37 12 24 29 37 22  3 14 19 12 14 29 32 37  3 21 37 14
  4] 29
[ 7 14  2  2 17 37 12 24 29 37 22  3 14 19 12 14 29 32 37  3 21 37 14  4
 29] 37
[14  2  2 17 37 12 24 29 37 22  3 14 19 12 14 29 32 37  3 21 37 14  4 29
 37] 21
[ 2  2 17 37 12 24 29 37 22  3 14 19 12 14 29 32 37  3 21 37 14  4 29 37
 21] 42
[ 2 17 37 12 24 29 37 22  3 14 19 12 14 29 32 37  3 21 37 14  4 29 37 21
 42] 24
[17 37 12 24 29 37 22  3 14 19 12 14 29 32 37  3 21 37 14  4 29 37 21 42
 24] 14
[37 12 24 29 37 22  3 14 19 12 14 29 32 37  3 21 37 14  4 29 37 21 42 24
 14] 4
[12 24 29 37 22  3 14 19 12 14 29 32 37  3 21 37 14  4 29 37 21 42 24 14
  4] 37
[24 29 37 22  3 14 19 12 14 29 32 37  3 21 37 14  4 29 37 21 42 24 14  4
 37] 42
[29 37 22  3 14 19 12 14 29 32 37  3 21 37 14  4 29 37 21 42 24 14  4 37
 42] 7
[37 22  3 14 19 12 14 29 32 37  3 21 37 14  4 29 37 21 42 24 14  4 37 42
  7] 37
[22  3 14 19 12 14 29 32 37  3 21 37 14  4 29 37 21 42 24 14  4 37 42  7
 37] 14
[ 3 14 19 12 14 29 32 37  3 21 37 14  4 29 37 21 42 24 14  4 37 42  7 37
 14] 4
[14 19 12 14 29 32 37  3 21 37 14  4 29 37 21 42 24 14  4 37 42  7 37 14
  4] 29
[19 12 14 29 32 37  3 21 37 14  4 29 37 21 42 24 14  4 37 42  7 37 14  4
 29] 37
[12 14 29 32 37  3 21 37 14  4 29 37 21 42 24 14  4 37 42  7 37 14  4 29
 37] 3
[14 29 32 37  3 21 37 14  4 29 37 21 42 24 14  4 37 42  7 37 14  4 29 37
  3] 22
[29 32 37  3 21 37 14  4 29 37 21 42 24 14  4 37 42  7 37 14  4 29 37  3
 22] 15
[32 37  3 21 37 14  4 29 37 21 42 24 14  4 37 42  7 37 14  4 29 37  3 22
 15] 12
[37  3 21 37 14  4 29 37 21 42 24 14  4 37 42  7 37 14  4 29 37  3 22 15
 12] 21
[ 3 21 37 14  4 29 37 21 42 24 14  4 37 42  7 37 14  4 29 37  3 22 15 12
 21] 32
[21 37 14  4 29 37 21 42 24 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21
 32] 11
[37 14  4 29 37 21 42 24 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32
 11] 37
[14  4 29 37 21 42 24 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11
 37] 6
[ 4 29 37 21 42 24 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37
  6] 4
[29 37 21 42 24 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6
  4] 29
[37 21 42 24 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4
 29] 37
[21 42 24 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29
 37] 1
[42 24 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37
  1] 29
[24 14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37  1
 29] 21
[14  4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37  1 29
 21] 14
[ 4 37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37  1 29 21
 14] 29
[37 42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37  1 29 21 14
 29] 24
[42  7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37  1 29 21 14 29
 24] 37
[ 7 37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37  1 29 21 14 29 24
 37] 42
[37 14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37  1 29 21 14 29 24 37
 42] 7
[14  4 29 37  3 22 15 12 21 32 11 37  6  4 29 37  1 29 21 14 29 24 37 42
  7] 37
[ 4 29 37  3 22 15 12 21 32 11 37  6  4 29 37  1 29 21 14 29 24 37 42  7
 37] 14
[29 37  3 22 15 12 21 32 11 37  6  4 29 37  1 29 21 14 29 24 37 42  7 37
 14] 4
[37  3 22 15 12 21 32 11 37  6  4 29 37  1 29 21 14 29 24 37 42  7 37 14
  4] 29
[ 3 22 15 12 21 32 11 37  6  4 29 37  1 29 21 14 29 24 37 42  7 37 14  4
 29] 37
[22 15 12 21 32 11 37  6  4 29 37  1 29 21 14 29 24 37 42  7 37 14  4 29
 37] 3
[15 12 21 32 11 37  6  4 29 37  1 29 21 14 29 24 37 42  7 37 14  4 29 37
  3] 22
[12 21 32 11 37  6  4 29 37  1 29 21 14 29 24 37 42  7 37 14  4 29 37  3
 22] 15
[21 32 11 37  6  4 29 37  1 29 21 14 29 24 37 42  7 37 14  4 29 37  3 22
 15] 12
[32 11 37  6  4 29 37  1 29 21 14 29 24 37 42  7 37 14  4 29 37  3 22 15
 12] 21
[11 37  6  4 29 37  1 29 21 14 29 24 37 42  7 37 14  4 29 37  3 22 15 12
 21] 32
[37  6  4 29 37  1 29 21 14 29 24 37 42  7 37 14  4 29 37  3 22 15 12 21
 32] 37
[ 6  4 29 37  1 29 21 14 29 24 37 42  7 37 14  4 29 37  3 22 15 12 21 32
 37] 3
[ 4 29 37  1 29 21 14 29 24 37 42  7 37 14  4 29 37  3 22 15 12 21 32 37
  3] 22
[29 37  1 29 21 14 29 24 37 42  7 37 14  4 29 37  3 22 15 12 21 32 37  3
 22] 37
[37  1 29 21 14 29 24 37 42  7 37 14  4 29 37  3 22 15 12 21 32 37  3 22
 37] 32
[ 1 29 21 14 29 24 37 42  7 37 14  4 29 37  3 22 15 12 21 32 37  3 22 37
 32] 3
[29 21 14 29 24 37 42  7 37 14  4 29 37  3 22 15 12 21 32 37  3 22 37 32
  3] 23
[21 14 29 24 37 42  7 37 14  4 29 37  3 22 15 12 21 32 37  3 22 37 32  3
 23] 3
[14 29 24 37 42  7 37 14  4 29 37  3 22 15 12 21 32 37  3 22 37 32  3 23
  3] 32
[29 24 37 42  7 37 14  4 29 37  3 22 15 12 21 32 37  3 22 37 32  3 23  3
 32] 29
[24 37 42  7 37 14  4 29 37  3 22 15 12 21 32 37  3 22 37 32  3 23  3 32
 29] 32
[37 42  7 37 14  4 29 37  3 22 15 12 21 32 37  3 22 37 32  3 23  3 32 29
 32] 37
[42  7 37 14  4 29 37  3 22 15 12 21 32 37  3 22 37 32  3 23  3 32 29 32
 37] 13
[ 7 37 14  4 29 37  3 22 15 12 21 32 37  3 22 37 32  3 23  3 32 29 32 37
 13] 29
[37 14  4 29 37  3 22 15 12 21 32 37  3 22 37 32  3 23  3 32 29 32 37 13
 29] 14
[14  4 29 37  3 22 15 12 21 32 37  3 22 37 32  3 23  3 32 29 32 37 13 29
 14] 36
[ 4 29 37  3 22 15 12 21 32 37  3 22 37 32  3 23  3 32 29 32 37 13 29 14
 36] 29
[29 37  3 22 15 12 21 32 37  3 22 37 32  3 23  3 32 29 32 37 13 29 14 36
 29] 29
[37  3 22 15 12 21 32 37  3 22 37 32  3 23  3 32 29 32 37 13 29 14 36 29
 29] 21
[ 3 22 15 12 21 32 37  3 22 37 32  3 23  3 32 29 32 37 13 29 14 36 29 29
 21] 37
[22 15 12 21 32 37  3 22 37 32  3 23  3 32 29 32 37 13 29 14 36 29 29 21
 37] 29
[15 12 21 32 37  3 22 37 32  3 23  3 32 29 32 37 13 29 14 36 29 29 21 37
 29] 12
[12 21 32 37  3 22 37 32  3 23  3 32 29 32 37 13 29 14 36 29 29 21 37 29
 12] 22
[21 32 37  3 22 37 32  3 23  3 32 29 32 37 13 29 14 36 29 29 21 37 29 12
 22] 14
[32 37  3 22 37 32  3 23  3 32 29 32 37 13 29 14 36 29 29 21 37 29 12 22
 14] 37
[37  3 22 37 32  3 23  3 32 29 32 37 13 29 14 36 29 29 21 37 29 12 22 14
 37] 12
[ 3 22 37 32  3 23  3 32 29 32 37 13 29 14 36 29 29 21 37 29 12 22 14 37
 12] 21
[22 37 32  3 23  3 32 29 32 37 13 29 14 36 29 29 21 37 29 12 22 14 37 12
 21] 32
[37 32  3 23  3 32 29 32 37 13 29 14 36 29 29 21 37 29 12 22 14 37 12 21
 32] 37
[32  3 23  3 32 29 32 37 13 29 14 36 29 29 21 37 29 12 22 14 37 12 21 32
 37] 36
[ 3 23  3 32 29 32 37 13 29 14 36 29 29 21 37 29 12 22 14 37 12 21 32 37
 36] 29
[23  3 32 29 32 37 13 29 14 36 29 29 21 37 29 12 22 14 37 12 21 32 37 36
 29] 22
[ 3 32 29 32 37 13 29 14 36 29 29 21 37 29 12 22 14 37 12 21 32 37 36 29
 22] 14
[32 29 32 37 13 29 14 36 29 29 21 37 29 12 22 14 37 12 21 32 37 36 29 22
 14] 37
[29 32 37 13 29 14 36 29 29 21 37 29 12 22 14 37 12 21 32 37 36 29 22 14
 37] 13
[32 37 13 29 14 36 29 29 21 37 29 12 22 14 37 12 21 32 37 36 29 22 14 37
 13] 41
[37 13 29 14 36 29 29 21 37 29 12 22 14 37 12 21 32 37 36 29 22 14 37 13
 41] 37
[13 29 14 36 29 29 21 37 29 12 22 14 37 12 21 32 37 36 29 22 14 37 13 41
 37] 12
[29 14 36 29 29 21 37 29 12 22 14 37 12 21 32 37 36 29 22 14 37 13 41 37
 12] 37
[14 36 29 29 21 37 29 12 22 14 37 12 21 32 37 36 29 22 14 37 13 41 37 12
 37] 24
[36 29 29 21 37 29 12 22 14 37 12 21 32 37 36 29 22 14 37 13 41 37 12 37
 24] 12
[29 29 21 37 29 12 22 14 37 12 21 32 37 36 29 22 14 37 13 41 37 12 37 24
 12] 21
[29 21 37 29 12 22 14 37 12 21 32 37 36 29 22 14 37 13 41 37 12 37 24 12
 21] 33
[21 37 29 12 22 14 37 12 21 32 37 36 29 22 14 37 13 41 37 12 37 24 12 21
 33] 29
[37 29 12 22 14 37 12 21 32 37 36 29 22 14 37 13 41 37 12 37 24 12 21 33
 29] 37
[29 12 22 14 37 12 21 32 37 36 29 22 14 37 13 41 37 12 37 24 12 21 33 29
 37] 42
[12 22 14 37 12 21 32 37 36 29 22 14 37 13 41 37 12 37 24 12 21 33 29 37
 42] 7
[22 14 37 12 21 32 37 36 29 22 14 37 13 41 37 12 37 24 12 21 33 29 37 42
  7] 37
[14 37 12 21 32 37 36 29 22 14 37 13 41 37 12 37 24 12 21 33 29 37 42  7
 37] 22
[37 12 21 32 37 36 29 22 14 37 13 41 37 12 37 24 12 21 33 29 37 42  7 37
 22] 35
[12 21 32 37 36 29 22 14 37 13 41 37 12 37 24 12 21 33 29 37 42  7 37 22
 35] 12
[21 32 37 36 29 22 14 37 13 41 37 12 37 24 12 21 33 29 37 42  7 37 22 35
 12] 15
[32 37 36 29 22 14 37 13 41 37 12 37 24 12 21 33 29 37 42  7 37 22 35 12
 15] 15
[37 36 29 22 14 37 13 41 37 12 37 24 12 21 33 29 37 42  7 37 22 35 12 15
 15] 29
[36 29 22 14 37 13 41 37 12 37 24 12 21 33 29 37 42  7 37 22 35 12 15 15
 29] 24
[29 22 14 37 13 41 37 12 37 24 12 21 33 29 37 42  7 37 22 35 12 15 15 29
 24] 37
[22 14 37 13 41 37 12 37 24 12 21 33 29 37 42  7 37 22 35 12 15 15 29 24
 37] 5
[14 37 13 41 37 12 37 24 12 21 33 29 37 42  7 37 22 35 12 15 15 29 24 37
  5] 29
[37 13 41 37 12 37 24 12 21 33 29 37 42  7 37 22 35 12 15 15 29 24 37  5
 29] 12
[13 41 37 12 37 24 12 21 33 29 37 42  7 37 22 35 12 15 15 29 24 37  5 29
 12] 20
[41 37 12 37 24 12 21 33 29 37 42  7 37 22 35 12 15 15 29 24 37  5 29 12
 20] 22
[37 12 37 24 12 21 33 29 37 42  7 37 22 35 12 15 15 29 24 37  5 29 12 20
 22] 17
[12 37 24 12 21 33 29 37 42  7 37 22 35 12 15 15 29 24 37  5 29 12 20 22
 17] 37
[37 24 12 21 33 29 37 42  7 37 22 35 12 15 15 29 24 37  5 29 12 20 22 17
 37] 20
[24 12 21 33 29 37 42  7 37 22 35 12 15 15 29 24 37  5 29 12 20 22 17 37
 20] 21
[12 21 33 29 37 42  7 37 22 35 12 15 15 29 24 37  5 29 12 20 22 17 37 20
 21] 42
[21 33 29 37 42  7 37 22 35 12 15 15 29 24 37  5 29 12 20 22 17 37 20 21
 42] 36
[33 29 37 42  7 37 22 35 12 15 15 29 24 37  5 29 12 20 22 17 37 20 21 42
 36] 21
[29 37 42  7 37 22 35 12 15 15 29 24 37  5 29 12 20 22 17 37 20 21 42 36
 21] 37
[37 42  7 37 22 35 12 15 15 29 24 37  5 29 12 20 22 17 37 20 21 42 36 21
 37] 12
[42  7 37 22 35 12 15 15 29 24 37  5 29 12 20 22 17 37 20 21 42 36 21 37
 12] 22
[ 7 37 22 35 12 15 15 29 24 37  5 29 12 20 22 17 37 20 21 42 36 21 37 12
 22] 37
[37 22 35 12 15 15 29 24 37  5 29 12 20 22 17 37 20 21 42 36 21 37 12 22
 37] 28
[22 35 12 15 15 29 24 37  5 29 12 20 22 17 37 20 21 42 36 21 37 12 22 37
 28] 24
[35 12 15 15 29 24 37  5 29 12 20 22 17 37 20 21 42 36 21 37 12 22 37 28
 24] 42
[12 15 15 29 24 37  5 29 12 20 22 17 37 20 21 42 36 21 37 12 22 37 28 24
 42] 23
[15 15 29 24 37  5 29 12 20 22 17 37 20 21 42 36 21 37 12 22 37 28 24 42
 23] 12
[15 29 24 37  5 29 12 20 22 17 37 20 21 42 36 21 37 12 22 37 28 24 42 23
 12] 14
[29 24 37  5 29 12 20 22 17 37 20 21 42 36 21 37 12 22 37 28 24 42 23 12
 14] 12
[24 37  5 29 12 20 22 17 37 20 21 42 36 21 37 12 22 37 28 24 42 23 12 14
 12] 22
[37  5 29 12 20 22 17 37 20 21 42 36 21 37 12 22 37 28 24 42 23 12 14 12
 22] 11
(483, 25)
(483,)
483
25
43
(483, 43)
tf.keras.backend.clear_session

# define model
model = Sequential()
# conv1d layer with input dim (seq_length, vocab_size), ReLU activation, 64 7x7 filters
model.add(Conv1D(filters=64, kernel_size=7, activation='relu', input_shape=(seq_length, vocab_size)))  
# maxpool layer, with pool size=2
model.add(MaxPooling1D(pool_size=2))
# flatten the data before passing it to a fully connected / dense layer
model.add(Flatten())
# a dense layer with output size=43 for the 43 unique classes and a softmax activation to give the 43 class probabilities
model.add(Dense(43, activation='softmax'))
# compile the model with adam optimizer and cross entropy loss. Print accuracy metrics while training the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

model.summary()
Model: "sequential_1"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 conv1d_1 (Conv1D)           (None, 19, 64)            19328     
                                                                 
 max_pooling1d_1 (MaxPooling  (None, 9, 64)            0         
 1D)                                                             
                                                                 
 flatten_1 (Flatten)         (None, 576)               0         
                                                                 
 dense_1 (Dense)             (None, 43)                24811     
                                                                 
=================================================================
Total params: 44,139
Trainable params: 44,139
Non-trainable params: 0
_________________________________________________________________
X_input = X_onehot
y_target = y_onehot

# function to test the model and predict characters after each epoch
class PredictionCallback(tf.keras.callbacks.Callback):    
  def on_epoch_end(self, epoch, logs={}):
    txt = ''
   
    x = X_input[0:1,:,:]                          # set the first input as the first 25 characters
    for i in range(seq_length):                   # convert the one_hot encoded x inputs to tokens and then to characters, add them to string 'txt'
      txt = ''.join([txt,ix_to_char[np.argmax(x[0,i,:])]])

    n = 0                                         # data pointer
    while(n < num_samples):                       # run the prediction loop until the end of total number of inputs to the CNN
      n = n + 1            
      y_pred = self.model.predict(x, verbose=0)   # predict the class probabilities for the next character from a sequence of 25 encoded characters
      ix = np.argmax(y_pred)                      # find the index of the value with the largest probability
      txt = ''.join([txt,ix_to_char[ix]])         # convert the prediction into character and add it to the list of previous predictions 

      # at test-time, feed back the predicted character to model for next character prediction
      ypred_onehot = np.zeros((1,vocab_size))     # one-hot encode the predicted probabilities
      ypred_onehot[:,ix] = 1

      x = x.reshape(seq_length,vocab_size)        # reshape x into [seq_length, vocab_size] before stacking y_pred
      x = np.vstack([x[1:,:],ypred_onehot])       # remove the first character from x and stack y_pred for the next iteration
      x = x.astype(int)                           # numpy vstack returns a float array, convert it into an integer array
      x = x.reshape(1,seq_length,vocab_size)      # reshape the input x into [1, seq_length, vocab_size]

    print('----\n %s \n----' % (txt, ))           # print the entire string of our model predictions
# train the model for 100 epochs on X_input
# call the PredictionCallback() function to predict all characters and print them after each epoch
# print the loss and accuracies after each epoch

#hist = model.fit(X_input, y_target, epochs=100, verbose=2, callbacks=[PredictionCallback()])
Epoch 1/100
2023-03-18 11:26:23.001180: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at xla_ops.cc:446 : INTERNAL: libdevice not found at ./libdevice.10.bc
2023-03-18 11:26:23.001245: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at xla_ops.cc:446 : INTERNAL: libdevice not found at ./libdevice.10.bc
2023-03-18 11:26:23.001354: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at xla_ops.cc:446 : INTERNAL: libdevice not found at ./libdevice.10.bc
2023-03-18 11:26:23.001550: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at xla_ops.cc:446 : INTERNAL: libdevice not found at ./libdevice.10.bc
---------------------------------------------------------------------------
InternalError                             Traceback (most recent call last)
Cell In[7], line 5
      1 get_ipython().system('export XLA_FLAGS=--xla_gpu_cuda_data_dir=/usr/lib/cuda')
      2 # train the model for 100 epochs on X_input
      3 # call the PredictionCallback() function to predict all characters and print them after each epoch
      4 # print the loss and accuracies after each epoch
----> 5 hist = model.fit(X_input, y_target, epochs=100, verbose=2, callbacks=[PredictionCallback()])

File /workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
     67     filtered_tb = _process_traceback_frames(e.__traceback__)
     68     # To get the full stack trace, call:
     69     # `tf.debugging.disable_traceback_filtering()`
---> 70     raise e.with_traceback(filtered_tb) from None
     71 finally:
     72     del filtered_tb

File /workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/tensorflow/python/eager/execute.py:52, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     50 try:
     51   ctx.ensure_initialized()
---> 52   tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
     53                                       inputs, attrs, num_outputs)
     54 except core._NotOkStatusException as e:
     55   if name is not None:

InternalError: Graph execution error:

Detected at node 'StatefulPartitionedCall_2' defined at (most recent call last):
    File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
      exec(code, run_globals)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/ipykernel_launcher.py", line 17, in <module>
      app.launch_new_instance()
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/traitlets/config/application.py", line 1043, in launch_instance
      app.start()
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/ipykernel/kernelapp.py", line 725, in start
      self.io_loop.start()
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/tornado/platform/asyncio.py", line 215, in start
      self.asyncio_loop.run_forever()
    File "/usr/local/lib/python3.10/asyncio/base_events.py", line 603, in run_forever
      self._run_once()
    File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1909, in _run_once
      handle._run()
    File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
      self._context.run(self._callback, *self._args)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 513, in dispatch_queue
      await self.process_one()
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 502, in process_one
      await dispatch(*args)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 409, in dispatch_shell
      await result
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 729, in execute_request
      reply_content = await reply_content
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/ipykernel/ipkernel.py", line 422, in do_execute
      res = shell.run_cell(
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/ipykernel/zmqshell.py", line 540, in run_cell
      return super().run_cell(*args, **kwargs)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2961, in run_cell
      result = self._run_cell(
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3016, in _run_cell
      result = runner(coro)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/IPython/core/async_helpers.py", line 129, in _pseudo_sync_runner
      coro.send(None)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3221, in run_cell_async
      has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3400, in run_ast_nodes
      if await self.run_code(code, result, async_=asy):
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3460, in run_code
      exec(code_obj, self.user_global_ns, self.user_ns)
    File "/tmp/ipykernel_1055/4258978627.py", line 34, in <module>
      hist = model.fit(X_input, y_target, epochs=100, verbose=2, callbacks=[PredictionCallback()])
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler
      return fn(*args, **kwargs)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/engine/training.py", line 1650, in fit
      tmp_logs = self.train_function(iterator)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/engine/training.py", line 1249, in train_function
      return step_function(self, iterator)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/engine/training.py", line 1233, in step_function
      outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/engine/training.py", line 1222, in run_step
      outputs = model.train_step(data)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/engine/training.py", line 1027, in train_step
      self.optimizer.minimize(loss, self.trainable_variables, tape=tape)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 527, in minimize
      self.apply_gradients(grads_and_vars)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 1140, in apply_gradients
      return super().apply_gradients(grads_and_vars, name=name)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 634, in apply_gradients
      iteration = self._internal_apply_gradients(grads_and_vars)
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 1166, in _internal_apply_gradients
      return tf.__internal__.distribute.interim.maybe_merge_call(
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 1216, in _distributed_apply_gradients_fn
      distribution.extended.update(
    File "/workspaces/artificial_intelligence/.venv/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py", line 1211, in apply_grad_to_update_var
      return self._update_step_xla(grad, var, id(self._var_key(var)))
Node: 'StatefulPartitionedCall_2'
libdevice not found at ./libdevice.10.bc
     [[{{node StatefulPartitionedCall_2}}]] [Op:__inference_train_function_1645]
Back to top