<jupyter_start><jupyter_text><jupyter_code>note_seq = ['g8', 'e8', 'e4', 'f8', 'd8', 'd4', 'c8', 'd8', 'e8', 'f8', 'g8', 'g8', 'g4',
       'g8', 'e8', 'e8', 'e8', 'f8', 'd8', 'd4', 'c8', 'e8', 'g8', 'g8', 'e8', 'e8', 'e4',
       'd8', 'd8', 'd8', 'd8', 'd8', 'e8', 'f4', 'e8', 'e8', 'e8', 'e8', 'e8', 'f8', 'g4',
       'g8', 'e8', 'e4', 'f8', 'd8', 'd4', 'c8', 'e8', 'g8', 'g8', 'e8', 'e8', 'e4']
note_seq[0:4], note_seq[1:5], note_seq[2:6]
code2idx = {'c4':0, 'd4':1, 'e4':2, 'f4':3, 'g4':4, 'a4':5, 'b4':6,
            'c8':7, 'd8':8, 'e8':9, 'f8':10, 'g8':11, 'a8':12, 'b8':13}<jupyter_output><empty_output><jupyter_text>[4,8,12,...]<jupyter_code>len(note_seq), range(len(note_seq)-4)
code2idx['g8']
dataset = list()
for i in range(len(note_seq)-4):
  subset = note_seq[i:i+4]
  items = list()
  # print(subset)
  for item in subset:
    # code2idx[item]
    # print(code2idx[item])
    items.append(code2idx[item])
  # print(items)
  dataset.append(items)

print(dataset)
import numpy as np
datasets = np.array(dataset)
x_train = datasets[:,0:3]
x_train.shape
y_train = datasets[:,3]
y_train.shape
len(code2idx)
x_train = x_train/13 # len(code2index) 정규화
x_train[3]<jupyter_output><empty_output><jupyter_text>make model<jupyter_code>import tensorflow as tf
x_train.shape  # input의 사이즈를 알기위해 (=3 -> column의 값), tensorflow type(tensor) (50,3,1)
x_train[2] # -> metrix 모양
X_train = np.reshape(x_train, (50,3,1))  # tensor 모양 (갯수,행,열)
X_train.shape, X_train[2]
np.unique(y_train)
model = tf.keras.models.Sequential()

tf.keras.Input(shape=(3,1))
model.add(tf.keras.layers.Dense(13,activation='softmax'))  # output layer
# (batch_size , timesteps, input_dim) -> (rows, cols:행의 갯수, 1) -> tensorflow 의 모양
model.add(tf.keras.layers.LSTM(128))  # hidden layer
model.add(tf.keras.layers.Dense(13,activation='softmax'))  # output layer

model.compile(optimizer='adam',loss='sparse_categorical_crossentropy', metrics=['accuracy'])  # gadget
hist = model.fit(X_train, y_train, epochs=2, batch_size=5)
model.evaluate(X_train, y_train)
model.predict(X_train[4:5])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.23309352517985613, 'fraction_numerical': 0.06618705035971223, 'mean_word_length': 5.750809061488673, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '438430', 'license': 'Apache-2.0', 'n_tokens_mistral': 1018, 'n_tokens_neox': 1015, 'n_words': 173, 'path': 'Notescale_LSTM.ipynb', 'repo_name': 'SolbiChoi/test_deeplearning', 'size': '2085'}