-
Notifications
You must be signed in to change notification settings - Fork 329
Add a component_specific model to identify 'general' bugs that should be moved into more specific components #5892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+175
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
| # You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
|
||
| import logging | ||
| from datetime import datetime, timezone | ||
|
|
||
| import dateutil.parser | ||
| import xgboost | ||
| from dateutil.relativedelta import relativedelta | ||
| from sklearn.compose import ColumnTransformer | ||
| from sklearn.feature_extraction import DictVectorizer | ||
| from sklearn.pipeline import Pipeline | ||
|
|
||
| from bugbug import bug_features, bugzilla, feature_cleanup, utils | ||
| from bugbug.model import BugModel | ||
|
|
||
| logging.basicConfig(level=logging.INFO) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ComponentSpecificModel(BugModel): | ||
| def __init__(self, lemmatization=False, product="Firefox", component="General"): | ||
| BugModel.__init__(self, lemmatization) | ||
|
|
||
| self.product = product | ||
| self.component = component | ||
|
|
||
| feature_extractors = [ | ||
| bug_features.HasSTR(), | ||
| bug_features.Severity(), | ||
| bug_features.Keywords(), | ||
| bug_features.HasCrashSignature(), | ||
| bug_features.HasURL(), | ||
| bug_features.HasW3CURL(), | ||
| bug_features.HasGithubURL(), | ||
| bug_features.Whiteboard(), | ||
| bug_features.Patches(), | ||
| bug_features.Landings(), | ||
| ] | ||
|
|
||
| cleanup_functions = [ | ||
| feature_cleanup.fileref(), | ||
| feature_cleanup.url(), | ||
| feature_cleanup.synonyms(), | ||
| ] | ||
|
|
||
| self.extraction_pipeline = Pipeline( | ||
| [ | ||
| ( | ||
| "bug_extractor", | ||
| bug_features.BugExtractor( | ||
| feature_extractors, cleanup_functions, rollback=True | ||
| ), | ||
| ), | ||
| ] | ||
| ) | ||
|
|
||
| self.clf = Pipeline( | ||
| [ | ||
| ( | ||
| "union", | ||
| ColumnTransformer( | ||
| [ | ||
| ("data", DictVectorizer(), "data"), | ||
| ("title", self.text_vectorizer(min_df=0.0001), "title"), | ||
| ( | ||
| "comments", | ||
| self.text_vectorizer(min_df=0.0001), | ||
| "comments", | ||
| ), | ||
| ] | ||
| ), | ||
| ), | ||
| ( | ||
| "estimator", | ||
| xgboost.XGBClassifier(n_jobs=utils.get_physical_cpu_count()), | ||
| ), | ||
| ] | ||
| ) | ||
|
|
||
| def get_labels(self): | ||
| classes = {} | ||
|
|
||
| for bug_data in bugzilla.get_bugs(): | ||
| if dateutil.parser.parse(bug_data["creation_time"]) < datetime.now( | ||
| timezone.utc | ||
| ) - relativedelta(years=3): | ||
| continue | ||
|
|
||
| # Only bugs that were moved out of General and into a specific component | ||
| # Or the opposite | ||
marco-c marked this conversation as resolved.
Show resolved
Hide resolved
marco-c marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| for history in bug_data["history"]: | ||
| to_product_firefox = False | ||
| to_component_general = False | ||
|
|
||
| from_product_firefox = False | ||
| from_component_general = False | ||
|
|
||
| for change in history["changes"]: | ||
| if change["field_name"] == "product": | ||
| if change["added"] == self.product: | ||
| to_product_firefox = True | ||
| elif change["removed"] == self.product: | ||
| from_product_firefox = True | ||
|
|
||
| if change["field_name"] == "component": | ||
| if change["added"] == self.component: | ||
| to_component_general = True | ||
| elif change["removed"] == self.component: | ||
| from_component_general = True | ||
|
|
||
| if from_product_firefox and from_component_general: | ||
| classes[bug_data["id"]] = 1 | ||
| elif to_product_firefox and to_component_general: | ||
| classes[bug_data["id"]] = 0 | ||
|
|
||
| logger.info( | ||
| "%d bugs were moved out of %s::%s", | ||
| sum(label == 1 for label in classes.values()), | ||
| self.product, | ||
| self.component, | ||
| ) | ||
| logger.info( | ||
| "%d bugs were moved in %s::%s", | ||
| sum(label == 0 for label in classes.values()), | ||
| self.product, | ||
| self.component, | ||
| ) | ||
|
|
||
| return classes, [0, 1] | ||
|
|
||
| def get_feature_names(self): | ||
| return self.clf.named_steps["union"].get_feature_names_out() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.