Contributing to TorchLingo¶
Thank you for your interest in contributing to TorchLingo! This guide will help you get started.
Ways to Contribute¶
- ๐ Report bugs via GitHub issues
- ๐ก Suggest features via GitHub discussions
- ๐ Improve documentation โ typos, clarifications, examples
- ๐งช Add tests โ increase coverage
- ๐ Submit code โ bug fixes, new features
Development Setup¶
1. Fork and Clone¶
2. Create a Virtual Environment¶
3. Install in Development Mode¶
4. Run Tests¶
Code Style¶
We use Ruff for linting and formatting:
# Check style
ruff check src/
# Auto-fix issues
ruff check --fix src/
# Format code
ruff format src/
Style Guidelines¶
- Line length: 88 characters max
- Docstrings: Google style
- Type hints: Required for public APIs
- Imports: Sorted with isort
# Good example
def encode(self, sentence: str, add_special_tokens: bool = True) -> List[int]:
"""Encode a sentence to vocabulary indices.
Args:
sentence: Raw text to encode.
add_special_tokens: Whether to add SOS/EOS tokens.
Returns:
List of integer indices.
Raises:
ValueError: If sentence is empty.
"""
...
Running Tests¶
# All tests
python -m unittest discover tests -v
# Specific file
python -m unittest tests.test_vocab -v
# Specific test case or method
python -m unittest tests.test_vocab.TestSimpleVocab.test_build_vocab -v
Writing Tests¶
Tests live in tests/ and use unittest:
# tests/test_vocab.py
import unittest
from torchlingo.data_processing import SimpleVocab
class TestSimpleVocab(unittest.TestCase):
def test_build_vocab(self):
vocab = SimpleVocab()
vocab.build_vocab(["hello world", "hello friend"])
self.assertIn("hello", vocab.token2idx)
self.assertGreaterEqual(len(vocab), 4) # At least special tokens
def test_encode_decode(self):
vocab = SimpleVocab()
vocab.build_vocab(["hello world"])
indices = vocab.encode("hello world", add_special_tokens=True)
text = vocab.decode(indices, skip_special_tokens=True)
self.assertEqual(text, "hello world")
if __name__ == "__main__":
unittest.main()
Documentation¶
Building Docs Locally¶
Visit http://localhost:8000 to preview.
Documentation Guidelines¶
- Use clear, simple language โ imagine explaining to a beginner
- Include code examples for every concept
- Add type hints to all public functions
- Use admonitions for tips, warnings, notes
!!! tip "Helpful Tip"
Use this format for tips.
!!! warning "Watch Out"
Use this for common mistakes.
Submitting Changes¶
1. Create a Branch¶
2. Make Your Changes¶
- Keep commits focused and atomic
- Write clear commit messages
- Add tests for new functionality
- Update documentation if needed
3. Push and Create PR¶
Then create a Pull Request on GitHub.
PR Guidelines¶
- Title: Clear, descriptive (e.g., "Add beam search decoding")
- Description: Explain what and why
- Tests: Include tests for new code
- Docs: Update docs if behavior changes
Issue Guidelines¶
Bug Reports¶
Include:
- TorchLingo version
- Python version
- Minimal code to reproduce
- Expected vs actual behavior
- Full error traceback
Feature Requests¶
Include:
- What problem does this solve?
- Proposed solution
- Alternatives considered
Project Structure¶
torchlingo/
โโโ src/torchlingo/ # Main package
โ โโโ config.py # Configuration
โ โโโ data_processing/ # Datasets, vocab, batching
โ โโโ models/ # Neural network architectures
โ โโโ preprocessing/ # Data loading, tokenization
โโโ tests/ # Test suite
โโโ docs/ # Documentation (MkDocs)
โโโ assignments/ # Course assignments
Questions?¶
- Open a GitHub Discussion for questions
- Check existing issues before creating new ones
- Join our community (if applicable)
Thank you for helping make TorchLingo better! ๐