{"id":17950893,"url":"https://github.com/jonathanpeppers/inclusive-code-reviews-ml","last_synced_at":"2025-03-25T00:31:23.392Z","repository":{"id":48383129,"uuid":"496842359","full_name":"jonathanpeppers/inclusive-code-reviews-ml","owner":"jonathanpeppers","description":"Machine learning for code reviews!","archived":false,"fork":false,"pushed_at":"2024-08-19T20:05:59.000Z","size":18575,"stargazers_count":14,"open_issues_count":15,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-29T10:17:35.710Z","etag":null,"topics":["hacktoberfest","machine-learning","ml-dotnet","onnx","onnx-runtime"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonathanpeppers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-27T02:56:13.000Z","updated_at":"2024-08-30T14:39:23.000Z","dependencies_parsed_at":"2023-11-07T01:11:38.674Z","dependency_job_id":"c3529d1f-e0c4-4a2d-983e-514c86bb15bd","html_url":"https://github.com/jonathanpeppers/inclusive-code-reviews-ml","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanpeppers%2Finclusive-code-reviews-ml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanpeppers%2Finclusive-code-reviews-ml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanpeppers%2Finclusive-code-reviews-ml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanpeppers%2Finclusive-code-reviews-ml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonathanpeppers","download_url":"https://codeload.github.com/jonathanpeppers/inclusive-code-reviews-ml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245377919,"owners_count":20605374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","machine-learning","ml-dotnet","onnx","onnx-runtime"],"created_at":"2024-10-29T09:40:59.785Z","updated_at":"2025-03-25T00:31:22.529Z","avatar_url":"https://github.com/jonathanpeppers.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Inclusive Code Reviews: Machine Learning\n\nMachine learning for code reviews! This is an MIT-licensed companion\nto our [Inclusive Code Comments browser extension][browser].\n\nThe goal of this project is to produce a machine learning model for\nclassifying sentences for code reviews.\n\nSome examples:\n\n* \"Looks good to me. Ship it!\" -\u003e OK!\n* \"There are test failures\" -\u003e OK!\n* \"You are a failure\" -\u003e BAD!\n* \"This code stinks\" -\u003e BAD!\n\nWe have the model in two formats, that is free to use in other\nprojects:\n\n* `MLModel.zip` - model in ML.NET format\n* `model.onnx` - model in ONNX format\n\nYou can find these in the `models.zip` artifact on the GitHub status\nof a commit or pull request.\n\nYou can create them locally via:\n\n```bash\ndotnet run --project ml.net/InclusiveCodeReviews.Convert/InclusiveCodeReviews.Convert.csproj\n...\n=============== Saving the model  ===============\nThe model is saved to inclusive-code-reviews-ml/bin/MLModel.zip\nThe model is saved to inclusive-code-reviews-ml/bin/model.onnx\n```\n\nSee the `InclusiveCodeReviews.ConsoleApp` for a C# example, general\nusage:\n\n```csharp\nvar results = ConsumeModel.Predict(new ModelInput\n{\n    Text = \"Your text here.\"\n});\nvar result = result.Prediction;\nvar score = result.Score[result.Prediction == \"1\" ? 1 : 0];\n```\n\nSee `onnxjs\\tests\\onnx.ts` for a TypeScript/JavaScript example,\ngeneral usage:\n\n```typescript\nconst session = await ort.InferenceSession.create('./model.onnx');\nconst results = await session.run({\n    text: new ort.Tensor([\"Your text here.\"], [1,1]),\n    isnegative: new ort.Tensor([''], [1,1]),\n    importance: new ort.Tensor('float32', [''], [1,1]),\n});\nconst result = results['PredictedLabel.output'].data[0];\nconst score = results['Score.output'].data[Number(result)];\n```\n\n## Repo layout / structure\n\nFolder structure of this repo:\n\n* `comments`: several `.csv` files of code review comments\n* `Maui`: desktop app for classifying data, see [MLTrainer app](#mltrainer-app)\n* `ml.net`: contains C# projects related to ML.NET usage, creating `.zip` or `.onnx` files\n* `onnxjs`: JS test project for the `.onnx` model\n\n[browser]: https://github.com/jonathanpeppers/inclusive-code-comments\n\n## MLTrainer app\n\nIf you're here to update [`comments/classified.csv`](comments/classified.csv),\nwe have a CI archive of the app, so you don't have to build it from\nsource.\n\nFind a commit on GitHub, and click a status for either Windows or Mac:\n\n![GitHub Status](docs/MLTrainer-GH-Status.png)\n\nClick on `Summary`:\n\n![GitHub Summary](docs/MLTrainer-Summary.png)\n\nScroll to the bottom, and pick either a Windows or Mac build:\n\n![GitHub Artifacts](docs/MLTrainer-Artifacts.png)\n\nThe Windows build contains an `MLTrainer.exe` inside, you can unzip\nthis somewhere and run it.\n\nThe Mac build contains an `MLTrainer-1.0.pkg` inside. You can simply\ninstall it and run `/Applications/MLTrainer.app` afterward.\n\nNote that you may need to bypass various signing prompts, as this app\nis not digitally signed. Mac you will need to go to `System\nPreferences \u003e Security \u0026 Privacy` to run an unsigned `.pkg` installer.\n\n## Notes about Inputs\n\nThe model is meant to be passed individual sentences. If you need to\nclassify paragraphs of text, it is recommended to split the text into\nsentences and match each against the model.\n\nThe model is trained with all GitHub handles removed and replaced with\n`@github`, you should apply this same replacement with your own input\ntext using the regex:\n\n```TypeScript\nconst regex:RegExp = /\\B@([a-z0-9](?:-(?=[a-z0-9])|[a-z0-9]){0,38}(?\u003c=[a-z0-9]))/gi;\nconst replaced = text.replace(regex, '@github');\n```\n\nAdditionally, inline code blocks such as:\n\n```markdown\nThis is a sentence with a `CodeBlock();`. Nice?\n```\n\nAre replaced via `#code`:\n\n```TypeScript\nconst regex:RegExp = /`+[^`]+`+/gi;\nconst replaced = text.replace(regex, '#code');\n```\n\nURLs are replaced with `#url`:\n\n```TypeScript\nconst regex:RegExp = /\\b(https?|ftp|file):\\/\\/[\\-A-Za-z0-9+\u0026@#\\/%?=~_|!:,.;]*[\\-A-Za-z0-9+\u0026@#\\/%=~_|]/gi;\nconst replaced = text.replace(regex, '#url');\n```\n\nTrailing punctuation should be replaced such as:\n\n```TypeScript\nconst regex:RegExp = /(\\.|!|\\?|;|:)+$/g;\nconst replaced = text.replace(regex, '');\n```\n\nLeading/trailing blank space should also be replaced:\n\n```TypeScript\nconst final = text.trim();\n```\n\n## `mlnet` .NET Global Tool\n\nInstall with:\n\n```dotnetcli\ndotnet tool install --global mlnet\n```\n\nAnd you can train, such as:\n\n```dotnetcli\nmlnet classification --dataset comments/classified.csv --label-col 1 --has-header true --train-time 10\n```\n\nThis outputs a folder named `SampleClassification` in the current\ndirectory. It's not exactly the same output the ML.NET Model Builder\noutputs, but this should also work on a Mac.\n\nSee the [ML.NET docs][mlnet] for more info.\n\n[mlnet]: https://docs.microsoft.com/dotnet/machine-learning/automate-training-with-cli\n\n## Generate Projects in `ml.net` folder\n\nRun `train.ps1`.\n\nNote there are additional manual edits we would lose if running this\nagain. You might discard some of the changes, or compare the diff.\n\n## Updating the Model\n\nOpen `ml.net\\InclusiveCodeReviews.sln` in VS, and run `InclusiveCodeReviews.Convert` project.\n\nThis will update `InclusiveCodeReviews.Model\\MLModel.zip` and `onnxjs\\model.onnx` in-place.\n\nTo test `model.onnx`, run `npm test` in the `onnxjs` directory.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanpeppers%2Finclusive-code-reviews-ml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonathanpeppers%2Finclusive-code-reviews-ml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanpeppers%2Finclusive-code-reviews-ml/lists"}