This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#train.py | |
from model import Transformer | |
from configs import ModelConfigs | |
configs = ModelConfigs() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#configs.py | |
import os | |
from datetime import datetime | |
from mltu.configs import BaseModelConfigs | |
class ModelConfigs(BaseModelConfigs): | |
def __init__(self): | |
super().__init__() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#model.py | |
import tensorflow as tf | |
from mltu.tensorflow.transformer.layers import Encoder, Decoder | |
def Transformer( | |
input_vocab_size: int, | |
target_vocab_size: int, | |
encoder_input_size: int = None, | |
decoder_input_size: int = None, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tensorflow as tf | |
try: [tf.config.experimental.set_memory_growth(gpu, True) for gpu in tf.config.experimental.list_physical_devices("GPU")] | |
except: pass | |
from keras.callbacks import EarlyStopping, ModelCheckpoint, ReduceLROnPlateau, TensorBoard | |
from mltu.tensorflow.callbacks import Model2onnx, WarmupCosineDecay | |
from mltu.tensorflow.dataProvider import DataProvider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
from tqdm import tqdm | |
from bs4 import BeautifulSoup | |
# URL to the directory containing the files to be downloaded | |
language = "en-es" | |
url = f"https://data.statmt.org/opus-100-corpus/v1.0/supervised/{language}/" | |
save_directory = f"./Datasets/{language}" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
['fueron los asbestos aquí. ¡eso es lo que ocurrió!', 'me voy de aquí.', 'una vez, juro que cagué una barra de tiza.', 'y prefiero mudarme, ¿entiendes?'] | |
["<start>it was the asbestos in here, that's what did it!", "<start>i'm out of here.", '<start>one time, i swear i pooped out a stick of chalk.', '<start>and i will move, do you understand me?'] | |
["it was the asbestos in here, that's what did it!<eos>", "i'm out of here.<eos>", 'one time, i swear i pooped out a stick of chalk.<eos>', 'and i will move, do you understand me?<eos>'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[33, 51, 48, 55, 55, 58, 3, 66, 58, 61, 55, 47, 15, 3, 51, 58, 66, 3, 44, 61, 48, 3, 68, 58, 64, 36, 32] | |
['<start>hello world, how are you?<eos>'] | |
['hello world, how are you?'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fitting tokenizer: 100%|██████████| 995249/995249 [00:10<00:00, 95719.57it/s] | |
Fitting tokenizer: 100%|██████████| 995249/995249 [00:07<00:00, 134446.71it/s] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
995249 | |
1990 | |
('Fueron los asbestos aquí. ¡Eso es lo que ocurrió!', 'Me voy de aquí.', 'Una vez, juro que cagué una barra de tiza.') | |
("It was the asbestos in here, that's what did it!", "I'm out of here.", 'One time, I swear I pooped out a stick of chalk.') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for data_batch in train_dataProvider: | |
(encoder_inputs, decoder_inputs), decoder_outputs = data_batch | |
encoder_inputs_str = tokenizer.detokenize(encoder_inputs) | |
decoder_inputs_str = detokenizer.detokenize(decoder_inputs, remove_start_end=False) | |
decoder_outputs_str = detokenizer.detokenize(decoder_outputs, remove_start_end=False) | |
print(encoder_inputs_str) | |
print(decoder_inputs_str) | |
print(decoder_outputs_str) | |