GPU-accelerated active learning pipelines for Arabic text classification using SBERT embeddings and multiple sampling strategies.
This project implements two active learning approaches for binary Arabic text classification (security vs non-security):
- Uncertainty Sampling Pipeline: Uses SBERT embeddings with a single classifier
- Committee-Based Sampling Pipeline: Uses SBERT embeddings with multiple classifiers
- π GPU-accelerated processing with CUDA support
- π€ SBERT embeddings for Arabic text using multilingual models
- π Multiple sampling strategies: uncertainty, margin, entropy, vote entropy, disagreement
- π§ Committee learning with multiple classifiers (LogisticRegression, SVM, LightGBM, RandomForest)
- π Modular design with clean separation of concerns
- π Jupyter notebook demo with detailed explanations
ActiveLearning-Abdu/
βββ pipelines/
β βββ __init__.py
β βββ uncertainty_sampling.py # Uncertainty sampling implementation
β βββ committee_sampling.py # Committee-based sampling implementation
βββ utils/
β βββ __init__.py
β βββ data_loader.py # CSV data loading utilities
β βββ embeddings.py # SBERT embedding generation
βββ notebooks/
β βββ active_learning_demo.ipynb # Interactive Jupyter demo
βββ data/ # Data directory (created automatically)
βββ main.py # Main execution script
βββ requirements.txt # Python dependencies
- Python 3.11
- CUDA 12.6+ (for GPU acceleration)
- Conda environment recommended
# Create conda environment
conda create -n al_env python=3.11
conda activate al_env
# Install PyTorch with CUDA
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
# Install core dependencies
pip install scikit-learn pandas numpy scipy jupyter
# Install SBERT (may require compatible huggingface-hub version)
pip install sentence-transformers>=2.7.0 huggingface-hub>=0.19.0
# Install LightGBM
pip install lightgbmIf you encounter dependency issues, run the simplified demo first:
python simple_demo.pyThis uses TF-IDF instead of SBERT and demonstrates both active learning approaches without external model dependencies.
For cloud machines (Google Colab, AWS, Azure, etc.):
# Clone the repository
git clone <your-repo-url>
cd ActiveLearning-Abdu
# Install dependencies in cloud environment
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt
# Test GPU availability
python test_dependencies.py
# Run the demo
python main.py # Full SBERT version
# OR
python simple_demo.py # Compatible versionGoogle Colab Setup:
!git clone <your-repo-url>
%cd ActiveLearning-Abdu
!pip install -r requirements.txt
!python main.pyFor GPU acceleration with LightGBM:
pip uninstall lightgbm
pip install lightgbm --config-settings=cmake.define.USE_CUDA=ONpython main.pyThis will:
- Create sample Arabic data automatically
- Run both pipelines with demonstration data
- Show results and selected samples
jupyter notebook notebooks/active_learning_demo.ipynbThe notebook provides:
- Step-by-step pipeline execution
- Detailed explanations and visualizations
- Interactive exploration of results
from utils.data_loader import DataLoader
from utils.embeddings import SBERTEmbedder
from pipelines.uncertainty_sampling import UncertaintySamplingPipeline
# Load your CSV data (must have 'text' and 'label' columns)
data_loader = DataLoader("path/to/your/arabic_data.csv")
embedder = SBERTEmbedder()
# Get initial split
labeled_texts, labeled_labels, unlabeled_texts, unlabeled_labels = data_loader.get_initial_split(
initial_labeled_size=100
)
# Initialize pipeline
pipeline = UncertaintySamplingPipeline(embedder, classifier_type='logistic')
pipeline.initialize_pools(labeled_texts, labeled_labels, unlabeled_texts)
# Run active learning iteration
results = pipeline.run_active_learning_iteration(n_samples=20, strategy='least_confident')Your CSV file should contain:
text: Arabic text contentlabel: Binary labels (0 for non-security, 1 for security)
Example:
text,label
"Ψ£Ω
Ψ§Ω Ψ§ΩΩ
ΨΉΩΩΩ
Ψ§Ψͺ ΩΨ§ΩΨΩ
Ψ§ΩΨ© Ψ§ΩΨ±ΩΩ
ΩΨ©",1
"Ψ§ΩΨ·ΩΨ³ Ψ§ΩΩΩΩ
Ω
Ψ΄Ω
Ψ³ ΩΨ¬Ω
ΩΩ",0- Embeddings: SBERT (paraphrase-multilingual-MiniLM-L12-v2)
- Classifiers: LogisticRegression, SVM
- Strategies:
least_confident: 1 - max(P(y|x))margin: difference between top 2 predictionsentropy: prediction entropy
- Embeddings: SBERT (paraphrase-multilingual-MiniLM-L12-v2)
- Committee: LogisticRegression, SVM, LightGBM, RandomForest
- Strategies:
vote_entropy: entropy of averaged predictionsdisagreement: proportion of disagreeing classifiers
pipeline = UncertaintySamplingPipeline(
embedder=embedder,
classifier_type='logistic', # 'logistic' or 'svm'
random_state=42
)pipeline = CommitteeSamplingPipeline(
embedder=embedder,
use_gpu_lightgbm=True, # Enable GPU LightGBM
random_state=42
)The project supports GPU acceleration for:
- β SBERT embeddings: Automatic GPU utilization
- β LightGBM: GPU training when available
- β PyTorch: CUDA operations
Check GPU status:
import torch
print(f"GPU available: {torch.cuda.is_available()}")
print(f"Device: {torch.cuda.get_device_name() if torch.cuda.is_available() else 'CPU'}")- Batch Processing: Adjust
batch_sizein embedding generation - Initial Pool Size: Start with 50-200 labeled samples
- Iteration Size: Select 10-50 samples per iteration
- GPU Memory: Monitor memory usage for large datasets
-
CUDA Out of Memory:
- Reduce batch size in embedding generation
- Use CPU fallback:
device='cpu'
-
LightGBM GPU Issues:
- Set
use_gpu_lightgbm=False - Install CPU version:
pip install lightgbm
- Set
-
Arabic Text Encoding:
- Ensure CSV is saved with UTF-8 encoding
- Use
encoding='utf-8'when reading files
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is available for educational and research purposes.