Repository navigation
fix(classifier): fail at start with a clear error when the model is missing - #307
Merged
Merged
Conversation
…issing A checkout without the model file logged "Unable to load file" and crashed with an AttributeError about a missing clf attribute. The loader now raises a FileNotFoundError that names the path and the notebook that builds the model. - classifier.py resolves the model next to the module, so the service starts from any working directory. - A missing model stops the process before Flask starts. - Startup with the model in place behaves as before, and nothing else broke.
Dependency ReviewThe following issues were found:
OpenSSF ScorecardScorecard details
Scanned Files
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
) The score in every classification response was the string "1". It came from comparing the article text with the predicted label, which never match. The handler now takes the class probabilities from the soft-voting ensemble and returns the highest one with its category. - classifier-ml.py picks the category from the model's classes at the highest probability, which agrees with predict. - Responses carry the score as a number between 0 and 1. - Classification returns the same categories as before, and nothing else broke.
* fix(api): report the predicted category's probability as the score The score in every classification response was the string "1". It came from comparing the article text with the predicted label, which never match. The handler now takes the class probabilities from the soft-voting ensemble and returns the highest one with its category. - classifier-ml.py picks the category from the model's classes at the highest probability, which agrees with predict. - Responses carry the score as a number between 0 and 1. - Classification returns the same categories as before, and nothing else broke. * fix(api): retrain the served model from the train endpoint The train endpoint never trained anything. Its payload indexing raised a KeyError that went back to the caller with a 200, and the fit would have run on a fresh classifier that served nothing. The endpoint now fits a copy of the served pipeline on 80% of the posted documents, scores it on the rest and swaps it in once the fit succeeds. - classifier.py clones the pipeline, so predictions never see a half-fitted model. - A lock turns a second request during a fit into a 409, since each fit holds another copy of the model in memory. - Malformed or undersized payloads get a 400 with the reason. - Training on 500 articles swaps the new model in while predictions keep serving, and nothing else broke.
* fix(api): report the predicted category's probability as the score The score in every classification response was the string "1". It came from comparing the article text with the predicted label, which never match. The handler now takes the class probabilities from the soft-voting ensemble and returns the highest one with its category. - classifier-ml.py picks the category from the model's classes at the highest probability, which agrees with predict. - Responses carry the score as a number between 0 and 1. - Classification returns the same categories as before, and nothing else broke. * fix(api): retrain the served model from the train endpoint The train endpoint never trained anything. Its payload indexing raised a KeyError that went back to the caller with a 200, and the fit would have run on a fresh classifier that served nothing. The endpoint now fits a copy of the served pipeline on 80% of the posted documents, scores it on the rest and swaps it in once the fit succeeds. - classifier.py clones the pipeline, so predictions never see a half-fitted model. - A lock turns a second request during a fit into a 409, since each fit holds another copy of the model in memory. - Malformed or undersized payloads get a 400 with the reason. - Training on 500 articles swaps the new model in while predictions keep serving, and nothing else broke. * fix(api): listen on port 7070 by default The service fell back to port 8080 when PORT was unset, while the image, the manifests and the probes all use 7070. A checkout started without PORT came up on the wrong port. The default now matches the rest of the project. - classifier-ml.py defaults PORT to 7070. - The comment above the setting goes, since it only restated the default. - With PORT unset the server listens on 7070, and nothing else broke. * fix(deployment): apply the image tag override in the default kustomization (#308) The images override in the default kustomization was three list items where kustomize expects one, so it matched no image and dropped the tag. Changing newTag had no effect, and the tag pinned in the base Deployment always won. The override is now a single entry. - deployment/kustomization.yml joins name, newName and newTag into one item. - Rendered output stays the same at the current tag, and a different newTag now reaches the Deployment. * docs(site): publish the documentation on Read the Docs (#310) * fix(deployment): apply the image tag override in the default kustomization The images override in the default kustomization was three list items where kustomize expects one, so it matched no image and dropped the tag. Changing newTag had no effect, and the tag pinned in the base Deployment always won. The override is now a single entry. - deployment/kustomization.yml joins name, newName and newTag into one item. - Rendered output stays the same at the current tag, and a different newTag now reaches the Deployment. * docs: add pages on training, running and deploying the classifier The project's documentation was a handful of usage commands. Eight pages now cover how the model is trained, how to run and call the service, how to deploy and operate it, and what CI builds. - docs/README.md serves as the home page on GitHub and on the site. - Architecture opens with a diagram of the path from dataset to cluster. - Image tags, resource limits and other values that drift stay in the files that set them, and the pages link there. - Every link and anchor resolves, and nothing broke. * docs(site): publish the documentation on Read the Docs The documentation pages are now a Material-themed site that Read the Docs builds with MkDocs. Read the Docs installs the tooling from a docs dependency group in the uv lock file, which keeps it out of the image and lets Dependabot update it with everything else. - .readthedocs.yaml syncs the docs group with uv on Python 3.14. - pyproject.toml pins MkDocs, Material, pymdown-extensions and Pygments by major version. - mkdocs.yml runs in strict mode, so a broken link fails the build. - README.md links to the published site and carries its badge. - The site builds without warnings, and the image still installs only the runtime dependencies.
|
Application ml-classifier-eca654a-307-pr-reviews has been created. |
5 similar comments
|
Application ml-classifier-eca654a-307-pr-reviews has been created. |
|
Application ml-classifier-eca654a-307-pr-reviews has been created. |
|
Application ml-classifier-eca654a-307-pr-reviews has been created. |
|
Application ml-classifier-eca654a-307-pr-reviews has been created. |
|
Application ml-classifier-eca654a-307-pr-reviews has been created. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
A missing model now stops the service at start with
FileNotFoundError: /app/data/voting_classifier.pickle.xz is missing, build it with classifier-ml.ipynb. The path resolves next toclassifier.py, so the service starts from any working directory.Related Issues
Fixes #301.
Testing
data/emptied - exits with theFileNotFoundErrorabove/tmp- loads thePipeline