Chiquitin
upload tokenizer script and configs
41fb647
# - x - x - x - x - x - x - x - x - x - x - x - x - x - x - #
# #
# This file was created by: Alberto Palomo Alonso #
# Universidad de Alcalá - Escuela Politécnica Superior #
# #
# - x - x - x - x - x - x - x - x - x - x - x - x - x - x - #
# Import statements:
from src import SegmentationTokenizer, SentenceSegmenter, SegmentationDataset
from bin.config import TokenizerConfig
# - x - x - x - x - x - x - x - x - x - x - x - x - x - x - #
# MAIN FUNC #
# - x - x - x - x - x - x - x - x - x - x - x - x - x - x - #
def main():
# Get configs:
wikipedia_dataset_path: str = input('Enter path to wikipedia dataset: ')
config = TokenizerConfig()
# Build tokenizer:
tokenizer = SegmentationTokenizer(
vocab_size=config.vocab_size,
min_frequency=config.min_frequency,
max_length=config.max_length
)
# Build segmenter:
segmenter = SentenceSegmenter(max_sentences=config.max_sentences)
# Build dataset:
dataset = SegmentationDataset(
wikipedia_dataset_path,
tokenizer=tokenizer,
segmenter=segmenter,
percentage=config.dataset_portion
)
# Train tokenizer:
tokenizer.train_from_iterator(
tokenizer.build_iterator(dataset.huggingface_dataset, batch_size=config.train_batch_size)
)
tokenizer.save('tokenizer_32768.json')
print('Tokenizer saved to tokenizer_32768.json')
# - x - x - x - x - x - x - x - x - x - x - x - x - x - x - #
# MAIN #
# - x - x - x - x - x - x - x - x - x - x - x - x - x - x - #
if __name__ == '__main__':
main()
# - x - x - x - x - x - x - x - x - x - x - x - x - x - x - #
# END OF FILE #
# - x - x - x - x - x - x - x - x - x - x - x - x - x - x - #