<jupyter_start><jupyter_text>%config IPCompleter.greedy=True<jupyter_code># Imports

import os
import warnings
import numpy as np

import tensorflow as tf

from tensorflow.keras import layers, models, optimizers
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import SimpleRNN, Dense, Bidirectional

from data_repository import DataRepository
from sklearn.model_selection import KFold, StratifiedKFold

# Ignore future warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
# Root CSV files directory
dirname = "./data/absolute/2D/"  

repo = DataRepository(dirname, verbose=False)

#load all
x, y = repo.getDataAndLabels()
physical_devices = tf.config.list_physical_devices('GPU') 
print("Num GPUs:", len(physical_devices)) 

from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession

config = ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.3
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)
with open('tokens_json.txt', 'r') as outfile:
    json_ex = outfile.read()
    

tokenizer = tf.keras.preprocessing.text.tokenizer_from_json(json_ex)
print(tokenizer.word_index)
token_labels = {y:x for x,y in tokenizer.word_index.items()}

y_integer = np.argmax(y, axis=1)
y_name= ([token_labels[p] for p in y_integer])

y_name
skfold = StratifiedKFold(n_splits=5, shuffle=True, random_state=7)
cvscores = []
for train, test in skfold.split(x, y_name):
    print("size_x_train: ", len(x[train]))
    print("size_y_train: ", len(y[train]))
    print("size_x_test: ", len(x[test]))
    print("size_y_test: ", len(y[test]))
    model = Sequential()
    model.add(layers.LSTM(128, return_sequences=True, input_shape=(x.shape[1], x.shape[2])))
    model.add(layers.LSTM(64, return_sequences=True)) 
    model.add(layers.LSTM(96))  
    model.add(layers.Dense(12, activation='softmax'))
    model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['accuracy',tf.keras.metrics.Precision(),tf.keras.metrics.Recall()])
    model.summary()

    history=model.fit(x[train],y[train],epochs=170,validation_data=(x[test],y[test]),verbose=2)
    scores = model.evaluate(x[test], y[test], verbose=0)
    print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
    cvscores.append(scores[1] * 100)
    print("Scores: ", scores)
    print("%.2f%% (+/- %.2f%%)" % (np.mean(cvscores), np.std(cvscores)))<jupyter_output>size_x_train:  743
size_y_train:  743
size_x_test:  186
size_y_test:  186
Model: "sequential_4"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
lstm_12 (LSTM)               (None, 100, 128)          110080    
_________________________________________________________________
lstm_13 (LSTM)               (None, 100, 64)           49408     
_________________________________________________________________
lstm_14 (LSTM)               (None, 96)                61824     
_________________________________________________________________
dense_4 (Dense)              (None, 12)                1164      
=================================================================
Total params: 222,476
Trainable params: 222,476
Non-trainable params: 0
_________________________________________________________________
Epoch 1/170
24/24 - 1s - loss: 2.3553 - [...]
{'fraction_non_alphanumeric': 0.15495808037004916, 'fraction_numerical': 0.03411390575310783, 'mean_word_length': 4.975820379965458, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '368043', 'license': 'Apache-2.0', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1048, 'n_words': 207, 'path': 'lab/Crossval.ipynb', 'repo_name': 'Tachionstrahl/SignLanguageRecognition', 'size': '3459'}