(self, path, category="Uncategorized", use_classifier: bool = False)
| 21 | |
| 22 | class Categorizer: |
| 23 | def __init__(self, path, category="Uncategorized", use_classifier: bool = False): |
| 24 | self.cache = get_commit_data_cache() |
| 25 | self.commits = CommitList.from_existing(path) |
| 26 | if use_classifier: |
| 27 | print("Using a classifier to aid with categorization.") |
| 28 | device = "cuda" if torch.cuda.is_available() else "cpu" |
| 29 | classifier_config = CategoryConfig(common.categories) |
| 30 | author_map = get_author_map( |
| 31 | Path("results/classifier"), regen_data=False, assert_stored=True |
| 32 | ) |
| 33 | file_map = get_file_map( |
| 34 | Path("results/classifier"), regen_data=False, assert_stored=True |
| 35 | ) |
| 36 | self.classifier = CommitClassifier( |
| 37 | XLMR_BASE, author_map, file_map, classifier_config |
| 38 | ).to(device) |
| 39 | self.classifier.load_state_dict( |
| 40 | torch.load(Path("results/classifier/commit_classifier.pt")) |
| 41 | ) |
| 42 | self.classifier.eval() |
| 43 | else: |
| 44 | self.classifier = None |
| 45 | # Special categories: 'Uncategorized' |
| 46 | # All other categories must be real |
| 47 | self.category = category |
| 48 | |
| 49 | def categorize(self): |
| 50 | commits = self.commits.filter(category=self.category) |
nothing calls this directly
no test coverage detected