This project provides a Python-based tool for normalizing Arabic text. It offers two normalization models: a standard model for rule-based normalization and an LLM-based model for more advanced, context-aware normalization using Google's Gemini API.
- Dual Normalization Models: Choose between a standard, rule-based normalizer and a powerful LLM-based normalizer.
- Customizable Configuration: Easily configure normalization rules through a JSON file.
- Secure API Key Handling: Uses a
.envfile to securely manage your Gemini API key. - Batch Processing: Process text files in batches with progress tracking.
- Easy to Use: Comes with a simple command-line interface and a
run.batscript for easy execution.
-
Clone the repository:
git clone <repository-url> cd normalizer
-
Create a Python virtual environment:
python -m venv venv
-
Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
-
Install the required dependencies:
pip install -r requirements.txt
-
Create a
.envfile:- Create a file named
.envin the root directory of the project. - Add your Gemini API key to the
.envfile as follows:GEMINI_API_KEY="your_api_key_here"
- Create a file named
-
Customize the normalization rules (optional):
- The
config.jsonfile contains the rules for the standard normalizer. You can modify this file to add, remove, or change the normalization rules.
- The
This project can be run from the command line using the main.py script or the run.bat script on Windows.
The run.bat script provides a convenient way to run the normalizer. It activates the virtual environment and provides examples of how to run the main.py script.
- Open the
run.batfile in a text editor. - Uncomment one of the example commands and replace the placeholder file paths with your actual input and output file paths.
- Save the
run.batfile and run it from the command line.
You can also run the main.py script directly from the command line.
python main.py --input_file <input_path> --output_file <output_path> --model <model_type> --config <config_path>Arguments:
--input_file: The path to the input text file.--output_file: The path to save the normalized text.--model: The normalization model to use. Can bestandardorllm.--config: The path to the JSON config file for the normalizer (default isconfig.json).
Examples:
-
Standard Normalization:
python main.py --input_file "data/sample_input.txt" --output_file "data/sample_output_standard.txt" --model "standard"
-
LLM-based Normalization:
python main.py --input_file "data/sample_input.txt" --output_file "data/sample_output_llm.txt" --model "llm"
The standard normalizer is a rule-based normalizer that applies a set of predefined rules to the text. These rules are defined in the config.json file and are executed by the arabic_normalizer.py script. This model is fast and efficient for common normalization tasks.
The llm normalizer uses a Large Language Model (LLM) from Google's Gemini API to perform more advanced, context-aware normalization. This model is more powerful than the standard normalizer and can handle more complex normalization tasks, but it requires an API key and an internet connection.
Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request.