<jupyter_start><jupyter_text>Import configuration for this experiment<jupyter_code># available configurations: long_train_conf, short_conf, test_conf
from config import long_train_conf as conf

# Load weights if want to use previously calculated weights 
# and your model didn't changed (except weights)
LOAD_WEIGHTS_FROM_CHECKPOINT = True
LOAD_METHOD = load_from_file

# drive is None when loading data from filesystem
drive = None<jupyter_output><empty_output><jupyter_text>Configuration for google colab (skip if not running in Colab)<jupyter_code># Install the PyDrive wrapper & import libraries.
# This only needs to be done once per notebook.
!pip install -U -q PyDrive

from colab_tools import g_authenticate, check_gpu, load_from_gdrive

LOAD_METHOD = load_from_gdrive
drive = g_authenticate()

# check if GPU is available:
check_gpu<jupyter_output><empty_output><jupyter_text>Loading input sequences, output sequences<jupyter_code>x, y = load_train_data(file_source_lang='vocab_en',
                       file_target_lang='vocab_fr',
                       load_method=load_from_file,
                       drive
                       )<jupyter_output>- Loading training data<jupyter_text>Splitting text to sentences, reversing order in input sequences<jupyter_code>x, y = split_text_to_array_of_sentences(x, y,
                                        conf['MAX_LEN'],
                                        conf['NUM_SENT']
                                        )<jupyter_output><empty_output><jupyter_text>Create word-to-index and index-to-word mappings, map the data<jupyter_code># process data in source language
x_sent_array, x_vocab_len, x_word_to_idx, x_idx_to_word = preprocess_data(
    x, conf['VOCAB_SIZE']
)

# process data in target language
y_sent_array, y_vocab_len, y_word_to_idx, y_idx_to_word = preprocess_data(
    y, conf['VOCAB_SIZE']
)<jupyter_output>- creating vocabulary
- creating mappings
- converting words to indices
- creating vocabulary
- creating mappings
- converting words to indices<jupyter_text>Find the length of the longest sequence, pad with zeros<jupyter_code># find the length of the longest sequence in source and target sentences
x_max_len = max([len(sentence) for sentence in x_sent_array])
y_max_len = max([len(sentence) for sentence in y_sent_array])

# Padding zeros to make all sequences have a same length as the longest one
print('Zero padding...')
X = pad_sequences(x_sent_array, maxlen=x_max_len, dtype='int32')
y = pad_sequences(y_sent_array, maxlen=y_max_len, dtype='int32')<jupyter_output>Zero padding...<jupyter_text>Create network model<jupyter_code># Creating the network model
model = create_model(x_vocab_len, x_max_len,
                     y_vocab_len, y_max_len,
                     conf['HIDDEN_DIM'], conf['LAYER_NUM'])
plot_model(model, to_file='model.png')

# Finding trained weights of previous epoch if any
saved_weights = find_checkpoint_file('.')

# if you don't want to use previously calculate weights set `saved_weights` to [] as below.

saved_weights = []

train(X, y, y_word_to_idx, y_max_len, saved_weights, model, conf)<jupyter_output>[INFO] Training model: epoch 1th 0/137860 samples
Epoch 1/1
 - 5s - loss: 5.5111 - acc: 0.3607
[INFO] Training model: epoch 1th 1000/137860 samples
Epoch 1/1
 - 2s - loss: 5.4291 - acc: 0.4030
[INFO] Training model: epoch 1th 2000/137860 samples
Epoch 1/1
 - 2s - loss: 5.2074 - acc: 0.4116
[INFO] Training model: epoch 1th 3000/137860 samples
Epoch 1/1
{'fraction_non_alphanumeric': 0.08129847744900891, 'fraction_numerical': 0.02470554438379776, 'mean_word_length': 4.061046511627907, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '651954', 'license': 'MIT', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1101, 'n_words': 321, 'path': 'machine_translation.ipynb', 'repo_name': 'izikeros/sequence_to_sequence_translation', 'size': '3481'}