Download test_setup.py from Deepu1965/code2-repo: direct link, hf CLI and curl.
- Browser
- Download file 5.92 kB
-
https://huggingface.co/Deepu1965/code2-repo/resolve/main/test_setup.py
- Command line
-
hf download hf://Deepu1965/code2-repo/test_setup.py
-
curl -L -o test_setup.py https://huggingface.co/Deepu1965/code2-repo/resolve/main/test_setup.py
5.92 kB
| #!/usr/bin/env python3 | |
| """ | |
| Quick Test Script - Verify Installation and Setup | |
| Tests basic functionality without full training | |
| """ | |
| import sys | |
| import os | |
| def test_imports(): | |
| """Test if all required packages can be imported""" | |
| print("๐ Testing imports...") | |
| errors = [] | |
| # Core dependencies | |
| packages = [ | |
| ('torch', 'PyTorch'), | |
| ('transformers', 'Transformers'), | |
| ('sklearn', 'scikit-learn'), | |
| ('pandas', 'Pandas'), | |
| ('numpy', 'NumPy') | |
| ] | |
| for package, name in packages: | |
| try: | |
| __import__(package) | |
| print(f" โ {name}") | |
| except ImportError: | |
| print(f" โ {name} - NOT INSTALLED") | |
| errors.append(name) | |
| # Optional dependencies | |
| optional_packages = [ | |
| ('matplotlib', 'Matplotlib'), | |
| ('seaborn', 'Seaborn') | |
| ] | |
| print("\n๐ Optional packages:") | |
| for package, name in optional_packages: | |
| try: | |
| __import__(package) | |
| print(f" โ {name}") | |
| except ImportError: | |
| print(f" โ ๏ธ {name} - Not installed (visualizations will be skipped)") | |
| return len(errors) == 0, errors | |
| def test_module_imports(): | |
| """Test if project modules can be imported""" | |
| print("\n๐ Testing project modules...") | |
| modules = [ | |
| 'config', | |
| 'data_loader', | |
| 'risk_discovery', | |
| 'model', | |
| 'trainer', | |
| 'evaluator', | |
| 'utils' | |
| ] | |
| errors = [] | |
| for module in modules: | |
| try: | |
| __import__(module) | |
| print(f" โ {module}.py") | |
| except Exception as e: | |
| print(f" โ {module}.py - {str(e)[:50]}") | |
| errors.append(module) | |
| return len(errors) == 0, errors | |
| def test_configuration(): | |
| """Test configuration loading""" | |
| print("\n๐ Testing configuration...") | |
| try: | |
| from config import LegalBertConfig | |
| config = LegalBertConfig() | |
| print(f" โ Configuration loaded") | |
| print(f" - BERT Model: {config.bert_model_name}") | |
| print(f" - Batch Size: {config.batch_size}") | |
| print(f" - Epochs: {config.num_epochs}") | |
| print(f" - Device: {config.device}") | |
| print(f" - Data Path: {config.data_path}") | |
| # Check if data path exists | |
| if os.path.exists(config.data_path): | |
| print(f" โ CUAD dataset found at {config.data_path}") | |
| else: | |
| print(f" โ ๏ธ CUAD dataset NOT found at {config.data_path}") | |
| print(f" Please download and place it at this location") | |
| return True, None | |
| except Exception as e: | |
| print(f" โ Configuration failed: {e}") | |
| return False, str(e) | |
| def test_model_initialization(): | |
| """Test model can be initialized""" | |
| print("\n๐ Testing model initialization...") | |
| try: | |
| from config import LegalBertConfig | |
| from model import FullyLearningBasedLegalBERT, HierarchicalLegalBERT, LegalBertTokenizer | |
| config = LegalBertConfig() | |
| # Test tokenizer | |
| tokenizer = LegalBertTokenizer(config.bert_model_name) | |
| test_text = "This agreement shall be governed by the laws of Delaware." | |
| encoded = tokenizer.tokenize_clauses([test_text], max_length=128) | |
| print(f" โ Tokenizer works") | |
| print(f" Input shape: {encoded['input_ids'].shape}") | |
| # Test model (without downloading weights for quick test) | |
| print(f" โน๏ธ Model initialization skipped (use train.py to fully initialize)") | |
| return True, None | |
| except Exception as e: | |
| print(f" โ Model initialization failed: {e}") | |
| return False, str(e) | |
| def test_data_loader(): | |
| """Test data loader (if data exists)""" | |
| print("\n๐ Testing data loader...") | |
| try: | |
| from config import LegalBertConfig | |
| from data_loader import CUADDataLoader | |
| config = LegalBertConfig() | |
| if not os.path.exists(config.data_path): | |
| print(f" โ ๏ธ Data file not found, skipping data loader test") | |
| return True, None | |
| loader = CUADDataLoader(config.data_path) | |
| print(f" โ Data loader initialized") | |
| # Try to load a small sample | |
| print(f" โน๏ธ Full data loading skipped (use train.py for full load)") | |
| return True, None | |
| except Exception as e: | |
| print(f" โ Data loader failed: {e}") | |
| return False, str(e) | |
| def main(): | |
| """Run all tests""" | |
| print("=" * 80) | |
| print("๐งช LEGAL-BERT PROJECT - QUICK TEST") | |
| print("=" * 80) | |
| all_passed = True | |
| # Test imports | |
| passed, errors = test_imports() | |
| if not passed: | |
| print(f"\nโ Missing required packages: {', '.join(errors)}") | |
| print(f" Install with: pip install -r requirements.txt") | |
| all_passed = False | |
| # Test modules | |
| passed, errors = test_module_imports() | |
| if not passed: | |
| print(f"\nโ Module import errors: {', '.join(errors)}") | |
| all_passed = False | |
| # Test configuration | |
| passed, error = test_configuration() | |
| if not passed: | |
| all_passed = False | |
| # Test model initialization | |
| passed, error = test_model_initialization() | |
| if not passed: | |
| all_passed = False | |
| # Test data loader | |
| passed, error = test_data_loader() | |
| if not passed: | |
| all_passed = False | |
| # Summary | |
| print("\n" + "=" * 80) | |
| if all_passed: | |
| print("โ ALL TESTS PASSED!") | |
| print("=" * 80) | |
| print("\n๐ Ready to train! Run: python train.py") | |
| else: | |
| print("โ SOME TESTS FAILED") | |
| print("=" * 80) | |
| print("\nโ ๏ธ Please fix the issues above before training") | |
| return 0 if all_passed else 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |