Thank you for your interest in contributing to ROUGE-Torch! We welcome contributions of all kinds, from bug reports and feature requests to code improvements and documentation updates.
- 🐛 Bug Reports: Report issues you encounter
- 💡 Feature Requests: Suggest new features or improvements
- 📝 Documentation: Improve docs, examples, or tutorials
- 🔧 Code: Fix bugs, implement features, or optimize performance
- 🧪 Tests: Add or improve test coverage
- 📊 Benchmarks: Performance improvements or comparisons
-
Fork and Clone
git clone https://github.com/your-username/rouge-torch.git cd rouge-torch -
Create Development Environment
# Using conda (recommended) conda create -n rouge-torch python=3.8 conda activate rouge-torch # Or using venv python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies
# Install package in development mode with all dependencies pip install -e ".[dev,test]" # Or install basic dependencies pip install torch>=1.9.0 pytest>=6.0 black isort flake8 mypy
-
Verify Installation
python -c "import rouge_torch; print('Installation successful!')" python -m pytest test_rouge_torch.py -v
-
Create a Branch
git checkout -b feature/your-feature-name # or git checkout -b bugfix/issue-description -
Make Changes
- Write your code following our style guidelines (see below)
- Add tests for new functionality
- Update documentation as needed
-
Run Tests and Checks
# Run all tests python -m pytest test_rouge_torch.py -v # Run specific test python -m pytest test_rouge_torch.py::TestROUGEScoreTorch::test_overfit_convergence -v # Check code formatting black --check rouge_torch/ test_rouge_torch.py example.py isort --check-only rouge_torch/ test_rouge_torch.py example.py # Check code style flake8 rouge_torch/ test_rouge_torch.py example.py # Type checking mypy rouge_torch/
-
Format Code (if needed)
black rouge_torch/ test_rouge_torch.py example.py isort rouge_torch/ test_rouge_torch.py example.py
-
Commit and Push
git add . git commit -m "Add: brief description of changes" git push origin feature/your-feature-name
-
Create Pull Request
- Go to GitHub and create a pull request
- Fill out the PR template with details about your changes
- Link any related issues
- Readability: Code should be self-documenting and easy to understand
- Performance: Maintain the vectorized, GPU-optimized approach
- Compatibility: Ensure compatibility with PyTorch 1.9+ and Python 3.8+
- Testing: All new features must include comprehensive tests
We follow PEP 8 with some modifications:
# Good: Clear, documented function
def compute_rouge_loss(
self,
candidate_logits: torch.Tensor,
reference_logits: List[torch.Tensor],
rouge_types: List[str] = ["rouge_1", "rouge_l"],
weights: Optional[Dict[str, float]] = None,
reduction: str = "mean",
) -> torch.Tensor:
"""
Compute ROUGE-based loss for training.
Args:
candidate_logits: Model output logits (batch_size, seq_len, vocab_size)
reference_logits: List of reference tensors
rouge_types: ROUGE metrics to combine
weights: Optional weights for different ROUGE types
reduction: 'mean', 'sum', or 'none'
Returns:
Loss tensor with proper bounds [0, N] where N = len(rouge_types)
"""- Line Length: 88 characters (Black default)
- Imports: Use isort for consistent import ordering
- Type Hints: Required for all public functions and methods
- Docstrings: Use Google-style docstrings
- Device Agnostic: Always respect the device parameter
- Vectorized Operations: Avoid Python loops in favor of tensor operations
- Memory Efficient: Consider memory usage for large batches/sequences
- Gradient-Safe: Ensure operations work correctly with autograd
- Unit Tests: Test individual functions and methods
- Integration Tests: Test end-to-end workflows
- Performance Tests: Validate speed and memory usage
- Validation Tests: The overfit test that validates loss convergence
def test_your_feature(self):
"""Test description explaining what this validates."""
# Setup
device = self.device
rouge_scorer = self.rouge
# Test data
candidate_logits = torch.randn(2, 10, self.vocab_size, device=device)
ref_logits = [torch.randn(2, 10, self.vocab_size, device=device)]
# Execute
result = rouge_scorer.your_method(candidate_logits, ref_logits)
# Validate
self.assertEqual(result.shape, (2,))
self.assertTrue(torch.all(result >= 0))
self.assertTrue(torch.all(result <= 1))- Loss Bounds: Verify loss ∈ [0, N] for N ROUGE types
- Perfect Match: loss = 0 when F1 = 1
- No Match: loss = N when F1 = 0
- Gradient Flow: Ensure backpropagation works correctly
- Batch Consistency: Same results for batched vs individual processing
Add: new feature descriptionFix: bug descriptionUpdate: improvement descriptionDocs: documentation changesTest: test improvements
## Description
Brief description of changes made.
## Type of Change
- [ ] Bug fix (non-breaking change fixing an issue)
- [ ] New feature (non-breaking change adding functionality)
- [ ] Breaking change (fix or feature causing existing functionality to change)
- [ ] Documentation update
## Testing
- [ ] All existing tests pass
- [ ] New tests added for new functionality
- [ ] Manual testing performed
## Performance Impact
- [ ] No performance impact
- [ ] Performance improved
- [ ] Performance regression (justify why)
## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] Tests added/updatedWhen reporting bugs, please include:
-
Environment Information
import torch import rouge_torch print(f"Python: {__import__('sys').version}") print(f"PyTorch: {torch.__version__}") print(f"ROUGE-Torch: {rouge_torch.__version__}") print(f"CUDA Available: {torch.cuda.is_available()}")
-
Minimal Reproduction Example
# Minimal code that reproduces the issue import torch from rouge_torch import ROUGEScoreTorch # Your reproduction code here
-
Expected vs Actual Behavior
-
Error Messages (full traceback)
-
Additional Context
For feature requests, please provide:
- Problem Statement: What problem does this solve?
- Proposed Solution: How should it work?
- Alternative Solutions: Other approaches considered
- Use Cases: Real-world scenarios where this would be useful
- Performance Considerations: Impact on speed/memory
- Correctness: Does the code work as intended?
- Performance: Maintains vectorized, GPU-optimized approach
- Testing: Adequate test coverage for new functionality
- Documentation: Clear docstrings and comments
- Style: Follows project conventions
- Backward Compatibility: Doesn't break existing APIs
- Initial review within 3-5 days
- Follow-up reviews within 1-2 days
- Merge after approval and passing CI
Contributors will be:
- Listed in CHANGELOG.md for their contributions
- Acknowledged in release notes
- Added to a CONTRIBUTORS.md file (coming soon)
- README.md - Package overview and usage
- example.py - Comprehensive usage example
- test_rouge_torch.py - Test suite including validation
- Questions: Open a GitHub Discussion
- Bugs: Create a GitHub Issue
- Chat: Join our Discord Server (coming soon)
By contributing to ROUGE-Torch, you agree that your contributions will be licensed under the same MIT License that covers the project.
Thank you for contributing to ROUGE-Torch! Your help makes this project better for everyone. 🎉