The viewer is disabled because this dataset repo requires arbitrary Python code execution. Please consider removing the loading script and relying on automated data support (you can use convert_to_parquet from the datasets library). If this is not possible, please open a discussion for direct help.

Portuguese Varieties Identification

This repository contains the code for the paper "Enhancing Portuguese Varieties Identification with Domain-Agnostic Ensemble Approaches," submitted to EACL 2024. In this README, you can find more information about the corpus created to support the training of a model to identify the Portuguese variety of a given text.

The corpus is composed of four million documents across six textual domains (law, literature, news, politics, social media, web). In terms of models, we covered three types of techniques: a) a baseline model using N-Grams and Naive Bayes; b) a model using a pre-trained language model (BERT); c) Anomaly-based language identification using autoencoders. To mitigate the variability introduced by the different domains, we used an ensemble approach to combine the predictions of domain-specialized models trained in isolation.

The work developed in this repository is part of the initiative anonymized for EACL

Quickstart

# In /benchmarks folder

1. Install the requirements
  pip install -r requirements.txt
  
2. Run the benchmarking script
  ./run.sh

Corpus

The developed corpus is a composition of pre-existing datasets initially created for other NLP tasks that provide permissive licenses. The first release of the corpus is available on Huggingface.

Data Sources

The corpus consists of the following datasets:

Domain Variety Dataset Original Task # Docs License Silver Labeled
Literature PT-PT Arquivo Pessoa - ~4k CC βœ”
Gutenberg Project - 6 CC βœ”
LT-Corpus - 56 ELRA END USER ✘
PT-BR Brazilian Literature Author Identification 81 CC ✘
LT-Corpus - 8 ELRA END USER ✘
Politics PT-PT Koehn (2005) Europarl Machine Translation ~10k CC ✘
PT-BR Brazilian Senate Speeches - ~5k CC βœ”
Journalistic PT-PT CETEM Público - 1M CC ✘
PT-BR CETEM Folha - 272k CC ✘
Social Media PT-PT Ramalho (2021) Fake News Detection 2M MIT βœ”
PT-BR Vargas (2022) Hate Speech Detection 5k CC-BY-NC-4.0 ✘
Cunha (2021) Fake News Detection 2k GPL-3.0 license βœ”
Web BOTH Ortiz-Suarez (2020) - 10k CC βœ”

Table 1: Data Sources

Note: The dataset "Brazilian Senate Speeches" was created by the authors of this paper, using web crawling of the Brazilian Senate website and is available in the Huggingface repository.

Annotation Schema & Data Preprocessing Pipeline

We leveraged our knowledge of the Portuguese language to identify data sources that guaranteed mono-variety documents. However, this first release lacks any kind of supervision, so we cannot guarantee that all documents are mono-variety. In the future, we plan to release a second version of the corpus with a more robust annotation schema, combining automatic and manual annotation.

To improve the quality of the corpus, we applied a preprocessing pipeline to all documents. The pipeline consists of the following steps:

  1. Remove all NaN values.
  2. Remove all empty documents.
  3. Remove all duplicated documents.
  4. Apply the clean_text library to remove non-relevant information for language identification from the documents.
  5. Remove all documents with a length significantly more than two standard deviations from the mean length of the documents in the corpus.

The pipeline is illustrated in Figure 1.

Image Description

Figure 1: Data Pre-Processing Pipeline

Class Distribution

The class distribution of the corpus is presented in Table 2. The corpus is highly imbalanced, with the majority of the documents being from the journalistic domain. In the future, we plan to release a second version of the corpus with a more balanced distribution across the six domains. Depending on the imbalance of the textual domain, we used different strategies to perform train-validation-test splits. For the heavily imbalanced domains, we ensured a minimum of 100 documents for validation and 400 for testing. In the other domains, we applied a stratified split.

Domain # PT-PT # PT-BR Stratified
Politics 6500 4894 βœ“
Web 7960 21592 βœ“
Literature 18282 2772 βœ“
Law 392839 5766 βœ•
Journalistic 1494494 354180 βœ“
Social Media 2013951 6222 βœ•

Table 2: Class Balance across the six textual domains in both varieties of Portuguese.

Future Releases & How to Contribute

We plan to release a second version of this corpus considering more textual domains and extending the scope to other Portuguese varieties. If you want to contribute to this corpus, please contact us.

Models

We explored three Machine Learning based techniques founded on the corpus compiled to present a reliable language identification model capable of operating in a real-world scenario, independent of the textual domain. The three techniques are:

  • A baseline model using N-Grams and Naive Bayes;
  • A model using a pre-trained language model (BERT);
  • Anomaly-based language identification using autoencoders.

To mitigate the impact of the variability introduced by the different domains, we used an ensemble approach to combine the predictions of domain-specialized models trained in isolation.

Baseline Model

The baseline model is a Naive Bayes classifier trained on the TF-IDF representation of the documents. The model is trained using the scikit-learn library. After performing a grid search to find the best hyperparameters, we obtained the following results:

Tokenizer # Features max_df Lowercase Stop_words Token_pattern Ngram_range Analyzer Algorithm
NLTK Portuguese 40000 1.0 False NLTK Stopwords None (1, 2) word
NLTK Portuguese 30000 1.0 False NLTK Stopwords None (1, 5) char_wb

Table 3: Hyperparameters of the baseline model.

The F1-scores obtained by this technique are presented in Figure 2. The architecture strugles to generalize outside the domains used for training, compromising the performance of the model in a real-world scenario.

Image Description

Figure 2: F1-Scores N-Grams based Model

Autoencoder Model

The autoencoder model proposes a anomaly-detection approach to language identification. The model is composed of encoder-decoder feed-foward layers trained using BERTimbau embeddings as input. The results obtained by this technique are presented in Figure 3. This model presents intermidiate results between the baseline model and the BERT model.

Image Description

Figure 3: F1-Scores Autoencoder based Model

BERT Model

The BERT model is a fine-tuned version of BERTimbau on the corpus compiled. The model is trained using the Huggingface library. The results obtained by this technique are presented in Figure 4. This model is capable of generalizing to unseen domains, making it a good candidate for a real-world scenario.

Image Description

Figure 4: F1-Scores BERT based Model

Downloads last month
38