Skip to content

Aplicação de um modelo PLN (Processamento de Linguagem Natural) para a tradução de textos do inglês para o português. | Application of a NLP (Natural Language Processing) model for the translation of texts from English to Portuguese.

License

Notifications You must be signed in to change notification settings

HedvaldoCosta/TranslatorEN-PT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Coleta de dados

É 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:

image

remote_dataset["train"]["translation"]

Entrando no conjunto de dados e chamando a coluna "translation" podemos verificar os pares de frases EN-PT:

image

remote_dataset["train"]['translation'][0]['english']

image

remote_dataset["train"]['translation'][0]['portuguese']

image

Podemos entrar em cada índice e pegar as frases separadamente. Estaremos utilizando esse recurso para fazer o pré-processamento dos dados.

Pré-processamento de 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

image

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)

image

Data collect

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:

image

remote_dataset["train"]["translation"]

Entering the dataset and calling the "translation" column we can verify the EN-PT sentence pairs:

image

remote_dataset["train"]['translation'][0]['english']

image

remote_dataset["train"]['translation'][0]['english']

image

We can go into each index and get the phrases separately. We will be using this feature to pre-process the data.

Data pre-processing

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

image

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)

image

About

Aplicação de um modelo PLN (Processamento de Linguagem Natural) para a tradução de textos do inglês para o português. | Application of a NLP (Natural Language Processing) model for the translation of texts from English to Portuguese.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published