We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Support multiclass classifiers in bug_classifier script
The bug_classifier script at scripts/bug_classifier.py currently assumes the model is a binary model. We need to make it work for multiclass models too (e.g. defectenhancementtask).

In particular, https://github.com/mozilla/bugbug/blob/65bf1b4604ca55a67490d27adc99c6441bad38c8/scripts/bug_classifier.py#L75-L78 needs to be changed.

To test your changes, simply run `python3 -m scripts.bug_classifier defectenhancementtask`

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scripts/bug_classifier.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 import argparse
4 import os
5 from logging import INFO, basicConfig, getLogger
6 
7 import numpy as np
8 import requests
9 
10 from bugbug import bugzilla
11 from bugbug.models import get_model_class
12 from bugbug.utils import download_check_etag, zstd_decompress
13 
14 MODELS_WITH_TYPE = ("component",)
15 
16 basicConfig(level=INFO)
17 logger = getLogger(__name__)
18 
19 
20 def classify_bugs(model_name, classifier, bug_id):
21     if classifier != "default":
22         assert (
23             model_name in MODELS_WITH_TYPE
24         ), f"{classifier} is not a valid classifier type for {model_name}"
25 
26         model_file_name = f"{model_name}{classifier}model"
27         model_name = f"{model_name}_{classifier}"
28     else:
29         model_file_name = f"{model_name}model"
30 
31     if not os.path.exists(model_file_name):
32         logger.info(f"{model_file_name} does not exist. Downloading the model....")
33         try:
34             download_check_etag(
35                 f"https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug.train_{model_name}.latest/artifacts/public/{model_file_name}.zst",
36                 f"{model_file_name}.zst",
37             )
38         except requests.HTTPError:
39             logger.error(
40                 f"A pre-trained model is not available, you will need to train it yourself using the trainer script"
41             )
42             raise SystemExit(1)
43 
44         zstd_decompress(model_file_name)
45         assert os.path.exists(model_file_name), "Decompressed file doesn't exist"
46 
47     model_class = get_model_class(model_name)
48     model = model_class.load(model_file_name)
49 
50     if bug_id:
51         bugs = bugzilla.get(bug_id).values()
52         assert bugs, f"A bug with a bug id of {bug_id} was not found"
53     else:
54         bugs = bugzilla.get_bugs()
55 
56     for bug in bugs:
57         print(
58             f'https://bugzilla.mozilla.org/show_bug.cgi?id={bug["id"]} - {bug["summary"]} '
59         )
60 
61         if model.calculate_importance:
62             probas, importance = model.classify(
63                 bug, probabilities=True, importances=True
64             )
65 
66             model.print_feature_importances(
67                 importance["importances"], class_probabilities=probas
68             )
69         else:
70             probas = model.classify(bug, probabilities=True, importances=False)
71 
72         if np.argmax(probas) == 1:
73             print(f"Positive! {probas}")
74         else:
75             print(f"Negative! {probas}")
76         input()
77 
78 
79 def main():
80     description = "Perform evaluation on bugs using the specified model"
81     parser = argparse.ArgumentParser(description=description)
82 
83     parser.add_argument("model", help="Which model to use for evaluation")
84     parser.add_argument(
85         "--classifier",
86         help="Type of the classifier. Only used for component classification.",
87         choices=["default", "nn"],
88         default="default",
89     )
90     parser.add_argument("--bug-id", help="Classify the given bug id")
91 
92     args = parser.parse_args()
93 
94     classify_bugs(args.model, args.classifier, args.bug_id)
95 
96 
97 if __name__ == "__main__":
98     main()
99
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scripts/bug_classifier.py b/scripts/bug_classifier.py
--- a/scripts/bug_classifier.py
+++ b/scripts/bug_classifier.py
@@ -69,10 +69,13 @@
         else:
             probas = model.classify(bug, probabilities=True, importances=False)
 
-        if np.argmax(probas) == 1:
-            print(f"Positive! {probas}")
+        probability = probas[0]
+        pred_index = np.argmax(probability)
+        if len(probability) > 2:
+            pred_class = model.le.inverse_transform([pred_index])[0]
         else:
-            print(f"Negative! {probas}")
+            pred_class = "Positive" if pred_index == 1 else "Negative"
+        print(f"{pred_class} {probability}")
         input()

{"golden_diff": "diff --git a/scripts/bug_classifier.py b/scripts/bug_classifier.py\n--- a/scripts/bug_classifier.py\n+++ b/scripts/bug_classifier.py\n@@ -69,10 +69,13 @@\n         else:\n             probas = model.classify(bug, probabilities=True, importances=False)\n \n-        if np.argmax(probas) == 1:\n-            print(f\"Positive! {probas}\")\n+        probability = probas[0]\n+        pred_index = np.argmax(probability)\n+        if len(probability) > 2:\n+            pred_class = model.le.inverse_transform([pred_index])[0]\n         else:\n-            print(f\"Negative! {probas}\")\n+            pred_class = \"Positive\" if pred_index == 1 else \"Negative\"\n+        print(f\"{pred_class} {probability}\")\n         input()\n", "issue": "Support multiclass classifiers in bug_classifier script\nThe bug_classifier script at scripts/bug_classifier.py currently assumes the model is a binary model. We need to make it work for multiclass models too (e.g. defectenhancementtask).\r\n\r\nIn particular, https://github.com/mozilla/bugbug/blob/65bf1b4604ca55a67490d27adc99c6441bad38c8/scripts/bug_classifier.py#L75-L78 needs to be changed.\r\n\r\nTo test your changes, simply run `python3 -m scripts.bug_classifier defectenhancementtask`\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport argparse\nimport os\nfrom logging import INFO, basicConfig, getLogger\n\nimport numpy as np\nimport requests\n\nfrom bugbug import bugzilla\nfrom bugbug.models import get_model_class\nfrom bugbug.utils import download_check_etag, zstd_decompress\n\nMODELS_WITH_TYPE = (\"component\",)\n\nbasicConfig(level=INFO)\nlogger = getLogger(__name__)\n\n\ndef classify_bugs(model_name, classifier, bug_id):\n    if classifier != \"default\":\n        assert (\n            model_name in MODELS_WITH_TYPE\n        ), f\"{classifier} is not a valid classifier type for {model_name}\"\n\n        model_file_name = f\"{model_name}{classifier}model\"\n        model_name = f\"{model_name}_{classifier}\"\n    else:\n        model_file_name = f\"{model_name}model\"\n\n    if not os.path.exists(model_file_name):\n        logger.info(f\"{model_file_name} does not exist. Downloading the model....\")\n        try:\n            download_check_etag(\n                f\"https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug.train_{model_name}.latest/artifacts/public/{model_file_name}.zst\",\n                f\"{model_file_name}.zst\",\n            )\n        except requests.HTTPError:\n            logger.error(\n                f\"A pre-trained model is not available, you will need to train it yourself using the trainer script\"\n            )\n            raise SystemExit(1)\n\n        zstd_decompress(model_file_name)\n        assert os.path.exists(model_file_name), \"Decompressed file doesn't exist\"\n\n    model_class = get_model_class(model_name)\n    model = model_class.load(model_file_name)\n\n    if bug_id:\n        bugs = bugzilla.get(bug_id).values()\n        assert bugs, f\"A bug with a bug id of {bug_id} was not found\"\n    else:\n        bugs = bugzilla.get_bugs()\n\n    for bug in bugs:\n        print(\n            f'https://bugzilla.mozilla.org/show_bug.cgi?id={bug[\"id\"]} - {bug[\"summary\"]} '\n        )\n\n        if model.calculate_importance:\n            probas, importance = model.classify(\n                bug, probabilities=True, importances=True\n            )\n\n            model.print_feature_importances(\n                importance[\"importances\"], class_probabilities=probas\n            )\n        else:\n            probas = model.classify(bug, probabilities=True, importances=False)\n\n        if np.argmax(probas) == 1:\n            print(f\"Positive! {probas}\")\n        else:\n            print(f\"Negative! {probas}\")\n        input()\n\n\ndef main():\n    description = \"Perform evaluation on bugs using the specified model\"\n    parser = argparse.ArgumentParser(description=description)\n\n    parser.add_argument(\"model\", help=\"Which model to use for evaluation\")\n    parser.add_argument(\n        \"--classifier\",\n        help=\"Type of the classifier. Only used for component classification.\",\n        choices=[\"default\", \"nn\"],\n        default=\"default\",\n    )\n    parser.add_argument(\"--bug-id\", help=\"Classify the given bug id\")\n\n    args = parser.parse_args()\n\n    classify_bugs(args.model, args.classifier, args.bug_id)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "scripts/bug_classifier.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport argparse\nimport os\nfrom logging import INFO, basicConfig, getLogger\n\nimport numpy as np\nimport requests\n\nfrom bugbug import bugzilla\nfrom bugbug.models import get_model_class\nfrom bugbug.utils import download_check_etag, zstd_decompress\n\nMODELS_WITH_TYPE = (\"component\",)\n\nbasicConfig(level=INFO)\nlogger = getLogger(__name__)\n\n\ndef classify_bugs(model_name, classifier, bug_id):\n    if classifier != \"default\":\n        assert (\n            model_name in MODELS_WITH_TYPE\n        ), f\"{classifier} is not a valid classifier type for {model_name}\"\n\n        model_file_name = f\"{model_name}{classifier}model\"\n        model_name = f\"{model_name}_{classifier}\"\n    else:\n        model_file_name = f\"{model_name}model\"\n\n    if not os.path.exists(model_file_name):\n        logger.info(f\"{model_file_name} does not exist. Downloading the model....\")\n        try:\n            download_check_etag(\n                f\"https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug.train_{model_name}.latest/artifacts/public/{model_file_name}.zst\",\n                f\"{model_file_name}.zst\",\n            )\n        except requests.HTTPError:\n            logger.error(\n                f\"A pre-trained model is not available, you will need to train it yourself using the trainer script\"\n            )\n            raise SystemExit(1)\n\n        zstd_decompress(model_file_name)\n        assert os.path.exists(model_file_name), \"Decompressed file doesn't exist\"\n\n    model_class = get_model_class(model_name)\n    model = model_class.load(model_file_name)\n\n    if bug_id:\n        bugs = bugzilla.get(bug_id).values()\n        assert bugs, f\"A bug with a bug id of {bug_id} was not found\"\n    else:\n        bugs = bugzilla.get_bugs()\n\n    for bug in bugs:\n        print(\n            f'https://bugzilla.mozilla.org/show_bug.cgi?id={bug[\"id\"]} - {bug[\"summary\"]} '\n        )\n\n        if model.calculate_importance:\n            probas, importance = model.classify(\n                bug, probabilities=True, importances=True\n            )\n\n            model.print_feature_importances(\n                importance[\"importances\"], class_probabilities=probas\n            )\n        else:\n            probas = model.classify(bug, probabilities=True, importances=False)\n\n        probability = probas[0]\n        pred_index = np.argmax(probability)\n        if len(probability) > 2:\n            pred_class = model.le.inverse_transform([pred_index])[0]\n        else:\n            pred_class = \"Positive\" if pred_index == 1 else \"Negative\"\n        print(f\"{pred_class} {probability}\")\n        input()\n\n\ndef main():\n    description = \"Perform evaluation on bugs using the specified model\"\n    parser = argparse.ArgumentParser(description=description)\n\n    parser.add_argument(\"model\", help=\"Which model to use for evaluation\")\n    parser.add_argument(\n        \"--classifier\",\n        help=\"Type of the classifier. Only used for component classification.\",\n        choices=[\"default\", \"nn\"],\n        default=\"default\",\n    )\n    parser.add_argument(\"--bug-id\", help=\"Classify the given bug id\")\n\n    args = parser.parse_args()\n\n    classify_bugs(args.model, args.classifier, args.bug_id)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "scripts/bug_classifier.py"}]}