Python program for detecting unintentional bilingual and translation instances in NLP datasets.
Python
0
20 commits
updated Feb 7, 2025
This repository contains code developed as part of a research internship at the Machine Learning Professorship at the Technical University of Munich (TUM). The project implements Google's "Searching for Needles in a Haystack: On the Role of Incidental Bilingualism in PaLM's Translation Capability" (Briakou et al. 2023) using open source tools and GPT-2 as the language model of study.
The codebase is mainly aimed at reproduction of research results detailed in internship_report.pdf, but the main script can be used by anyone looking to detect bilingual and translation instances in their NLP datasets.
Some differences with respect to the original paper:
More details about how the ablated GPT-2 models were trained are available at HuggingFace, in their respective card.
Required libraries:
unzip
g++
python3
Required Python packages:
python-daemon
numpy
fasttext-langdetect
iso-639
levenshtein
<WORKING_DIR>, then you'd want to do:cd <WORKING_DIR>
git clone https://github.com/lkevers/ldig-python3.git
git clone https://github.com/lkevers/dicServer.git
git clone https://github.com/lkevers/coswid.git
cd <WORKING_DIR>/coswid/data_lgID_learn
unzip filter2.zip
cat filter2/LEARN_data_filter2_* >>filter2/LEARN_data_filter2_ALL.txt
mkdir ../models/filter2
cd ../../ldig-python3/maxsubst
g++ -o maxsubst maxsubst.cpp -Icybozulib/include
chmod +x maxsubst
cd ../
python3 ldig.py -m ../coswid/models/filter2 -x maxsubst/maxsubst --init ../coswid/data_lgID_learn/filter2/LEARN_data_filter2_ALL.txt
python3 ldig.py -m ../coswid/models/filter2 --learn ../coswid/data_lgID_learn/filter2/LEARN_data_filter2_ALL.txt -e 0.5
python3 ldig.py -m ../coswid/models/filter2 --shrink
Modify the script <WORKING_DIR>/coswid/src/coswid.py as instructed in the CoSwID repository's README.
Run the dicServer with:
cd <WORKING_DIR>/dicServer
python3 dicServer.py .
cd <WORKING_DIR>/coswid/src
python3 coswid.py -m FILTER2 -t "Voici un texte à analyser in order to predict the languages" -c 2 -f 0 -g 0.1 -v dico
The results will be written to the default.out file.
Once the coswid.py script is working properly, you can move on to the next step.
Install the Python packages:
pip install -r requirements.txt
To detect bilingual and translation instances in your dataset:
python main.py --repo_id REPO_ID --filename FILENAME [options]
Required arguments:
--repo_id # HuggingFace dataset repository ID
--filename # File to process within the repository
Optional arguments:
--max_tokens # Maximum tokens per instance (default: 1024)
--num_workers # Number of parallel workers (default: 1)
--N # Minimum consecutive tokens threshold (default: 10)
--coswid_model # CoSwID model name (default: FILTER2)
--coswid_path # Path to coswid.py (default: ./coswid/src/coswid.py)
--cache_dir # Cache directory for downloaded files
This will identify monolingual, bilingual and translation instances in your dataset using CoSwID for language detection and LABSE for translation detection. The script outputs results in HuggingFace dataset format containing instance labels and language information, ready for downstream tasks or analysis.
The source code in this repository falls under the MIT License. For CoSwID's license, please refer to its repository.
Python program for detecting unintentional bilingual and translation instances in NLP datasets.
Python
0
20 commits
updated Feb 7, 2025
This repository contains code developed as part of a research internship at the Machine Learning Professorship at the Technical University of Munich (TUM). The project implements Google's "Searching for Needles in a Haystack: On the Role of Incidental Bilingualism in PaLM's Translation Capability" (Briakou et al. 2023) using open source tools and GPT-2 as the language model of study.
The codebase is mainly aimed at reproduction of research results detailed in internship_report.pdf, but the main script can be used by anyone looking to detect bilingual and translation instances in their NLP datasets.
Some differences with respect to the original paper:
More details about how the ablated GPT-2 models were trained are available at HuggingFace, in their respective card.
Required libraries:
unzip
g++
python3
Required Python packages:
python-daemon
numpy
fasttext-langdetect
iso-639
levenshtein
<WORKING_DIR>, then you'd want to do:cd <WORKING_DIR>
git clone https://github.com/lkevers/ldig-python3.git
git clone https://github.com/lkevers/dicServer.git
git clone https://github.com/lkevers/coswid.git
cd <WORKING_DIR>/coswid/data_lgID_learn
unzip filter2.zip
cat filter2/LEARN_data_filter2_* >>filter2/LEARN_data_filter2_ALL.txt
mkdir ../models/filter2
cd ../../ldig-python3/maxsubst
g++ -o maxsubst maxsubst.cpp -Icybozulib/include
chmod +x maxsubst
cd ../
python3 ldig.py -m ../coswid/models/filter2 -x maxsubst/maxsubst --init ../coswid/data_lgID_learn/filter2/LEARN_data_filter2_ALL.txt
python3 ldig.py -m ../coswid/models/filter2 --learn ../coswid/data_lgID_learn/filter2/LEARN_data_filter2_ALL.txt -e 0.5
python3 ldig.py -m ../coswid/models/filter2 --shrink
Modify the script <WORKING_DIR>/coswid/src/coswid.py as instructed in the CoSwID repository's README.
Run the dicServer with:
cd <WORKING_DIR>/dicServer
python3 dicServer.py .
cd <WORKING_DIR>/coswid/src
python3 coswid.py -m FILTER2 -t "Voici un texte à analyser in order to predict the languages" -c 2 -f 0 -g 0.1 -v dico
The results will be written to the default.out file.
Once the coswid.py script is working properly, you can move on to the next step.
Install the Python packages:
pip install -r requirements.txt
To detect bilingual and translation instances in your dataset:
python main.py --repo_id REPO_ID --filename FILENAME [options]
Required arguments:
--repo_id # HuggingFace dataset repository ID
--filename # File to process within the repository
Optional arguments:
--max_tokens # Maximum tokens per instance (default: 1024)
--num_workers # Number of parallel workers (default: 1)
--N # Minimum consecutive tokens threshold (default: 10)
--coswid_model # CoSwID model name (default: FILTER2)
--coswid_path # Path to coswid.py (default: ./coswid/src/coswid.py)
--cache_dir # Cache directory for downloaded files
This will identify monolingual, bilingual and translation instances in your dataset using CoSwID for language detection and LABSE for translation detection. The script outputs results in HuggingFace dataset format containing instance labels and language information, ready for downstream tasks or analysis.
The source code in this repository falls under the MIT License. For CoSwID's license, please refer to its repository.