É necessário um conjunto de dados de treinamento que contenha pares de frases em inglês e suas traduções correspondentes em português. Quanto maior e mais diversificado for o conjunto de dados, melhor será o desempenho do seu modelo.
Para isso, estaremos utilizando o modelo VanessaSchenkel/translation-en-pt. Acesso em: (https://huggingface.co/datasets/VanessaSchenkel/translation-en-pt) que possui 260482 frases em inglês com suas respectivas traduções para o português.
Todo o processo será realizado em um notebook dentro do kaggle por conta de sua praticidade e a possibilidade de estarmos utilizando sua GPU
Link do Código: (Ainda não finalizado)
from datasets import load_dataset
remote_dataset = load_dataset("VanessaSchenkel/translation-en-pt", field="data")
remote_dataset
Carregando o dataset "VanessaSchenkel/translation-en-pt" dentro do notebook kaggle e fazendo a chamada da variável "remote_dataset" temos a seguinte saída:
remote_dataset["train"]["translation"]
Entrando no conjunto de dados e chamando a coluna "translation" podemos verificar os pares de frases EN-PT:
remote_dataset["train"]['translation'][0]['english']
remote_dataset["train"]['translation'][0]['portuguese']
Podemos entrar em cada índice e pegar as frases separadamente. Estaremos utilizando esse recurso para fazer o pré-processamento dos dados.
Limpeza e preparação os dados para o treinamento. Etapa em que faremos o tokenizer dos nossos dados textuais.
phrase_list_bit = [remote_dataset["train"]["translation"][c] for c in range(1, 10)]
phrase_list_bit
O código acima pega apenas 10 pares de frases do conjunto de dados para diminuir o tempo de pré-processamento.
!pip install nltk -q
Para fazer a tokenização das frases, estaremos utilizando a biblioteca NLTK.
import nltk
from nltk.tokenize import word_tokenize
O "word_tokenize" é um tokenizador simples que cria tokens das palavras e pontuações das frases.
list_tokens = []
for pair in phrase_list_bit:
tokens_english = word_tokenize(pair["english"])
tokens_portuguese = word_tokenize(pair["portuguese"])
list_tokens.append(tokens_english)
list_tokens.append(tokens_portuguese)
Aplicação do "word_tokenize" nas frases da lista "phrase_list_bit".
for token in list_tokens:
print(token)
A training dataset containing pairs of English sentences and their corresponding Portuguese translations is required. The larger and more diverse the dataset, the better your model will perform.
For this, we will be using the model VanessaSchenkel/translation-en-pt. Access at: (https://huggingface.co/datasets/VanessaSchenkel/translation-en-pt) which has 260482 sentences in English with their respective translations into Portuguese.
The entire process will be carried out on a notebook inside kaggle due to its practicality and the possibility of using its GPU
Code Link: (Not finalized yet)
from datasets import load_dataset
remote_dataset = load_dataset("VanessaSchenkel/translation-en-pt", field="data")
remote_dataset
Loading the "VanessaSchenkel/translation-en-pt" dataset into the kaggle notebook and calling the "remote_dataset" variable, we get the following output:
remote_dataset["train"]["translation"]
Entering the dataset and calling the "translation" column we can verify the EN-PT sentence pairs:
remote_dataset["train"]['translation'][0]['english']
remote_dataset["train"]['translation'][0]['english']
We can go into each index and get the phrases separately. We will be using this feature to pre-process the data.
Cleaning and preparing data for training. Step in which we will tokenize our textual data.
phrase_list_bit = [remote_dataset["train"]["translation"][c] for c in range(1, 10)]
phrase_list_bit
The code above grabs only 10 sentence pairs from the dataset to decrease preprocessing time.
!pip install nltk -q
To tokenize the sentences, we will be using the NLTK library.
import nltk
from nltk.tokenize import word_tokenize
"word_tokenize" is a simple tokenizer that tokenizes words and sentence punctuations.
list_tokens = []
for pair in phrase_list_bit:
tokens_english = word_tokenize(pair["english"])
tokens_portuguese = word_tokenize(pair["portuguese"])
list_tokens.append(tokens_english)
list_tokens.append(tokens_portuguese)
Application of "word_tokenize" in the phrases of the "phrase_list_bit" list.
for token in list_tokens:
print(token)