Skip to content

hallucination classifier and helper fixes#211

Open
Darkxzie wants to merge 8 commits into
deepforestsci:mainfrom
Darkxzie:autosolve-changes-main
Open

hallucination classifier and helper fixes#211
Darkxzie wants to merge 8 commits into
deepforestsci:mainfrom
Darkxzie:autosolve-changes-main

Conversation

@Darkxzie
Copy link
Copy Markdown
Contributor

Description

  • merged the classifier dataset prediction path into predict_probability(dataset, threshold=None) so it now returns (labels, probabilities)
  • added optional threshold override support for single-reaction prediction paths
  • normalized ML hallucination helper output so single-string pathways are returned as one-element lists
    Fix #(issue)

Type of change

Please check the option that is related to your PR.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • In this case, we recommend to discuss your modification on GitHub issues before creating the PR
  • Documentations (modification for documents)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

) -> dict[str, Any]:
"""Thin wrapper around :func:`predict_single_reaction`."""
return predict_single_reaction(self, product_smiles, reactants_smiles)
return predict_single_reaction(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to remove this function in its entirety

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to add this cuz hallucination_helpers.py calls a predict_single and i have a few doubts on how to change the logic in that file so had to add this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved.

@Darkxzie Darkxzie changed the title Autosolve changes main hallucination classifier and helper fixes Apr 27, 2026
Copy link
Copy Markdown
Collaborator

@riya-singh28 riya-singh28 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Darkxzie I have left a few comments after my first review.

>>> checker = build_ml_checker(clf) # doctest: +SKIP
>>> status, kept = checker("CCO", [["CC", "O"]]) # doctest: +SKIP
"""
def _checker(product: str, pathways: list) -> tuple[int, list]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is to change this to a simple MLChecker class for now. It resolves issues with the nested functions and provides a clean pathway for future sub-classes, in case multiple types of MLClassifiers are added.

Class MLChecker:
    
    Init(clf):
        store classifier
        load is_valid_smiles utility

    Call(product, pathways):
        .
        .
        If valid_pathways not empty:
            return (200, valid_pathways)
        Else:
            return (400, [])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

f"hallucination_mode='ml' requires a HallucinationClassifier "
f"or path to saved model — got {type(classifier)}"
)
return build_ml_checker(clf)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this according to the suggested new class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

>>> checker = resolve_hallucination("heuristic", None) # doctest: +SKIP
>>> callable(checker) # doctest: +SKIP
True
>>> checker = resolve_hallucination("ml", "model_out/") # doctest: +SKIP
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix doctest, remove skip, add import statements

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Copy Markdown
Collaborator

@riya-singh28 riya-singh28 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have requested a few changes.

) -> dict[str, Any]:
"""Thin wrapper around :func:`predict_single_reaction`."""
return predict_single_reaction(self, product_smiles, reactants_smiles)
return predict_single_reaction(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve this.

assert np.all((probabilities >= 0.0) & (probabilities <= 1.0))


def test_predict_probability_override_uses_explicit_threshold():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstrings for all the unit tests

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Darkxzie Please add a test file for hallucination_helpers.py and include tests for the resolve hallucination function with model types = heuristic, ml, and none, among other required tests.

@riya-singh28
Copy link
Copy Markdown
Collaborator

@Darkxzie Can you also check why these tests are failing? I have not seen it failing for other PRs yet.

FAILED test_adv_prompt.py::test_claude_adv_success - assert 400 == 200
FAILED test_llm.py::test_call_llm_success - assert 400 == 200

@Darkxzie Darkxzie deployed to testing May 22, 2026 17:54 — with GitHub Actions Active
@Darkxzie
Copy link
Copy Markdown
Contributor Author

@Darkxzie Can you also check why these tests are failing? I have not seen it failing for other PRs yet.

FAILED test_adv_prompt.py::test_claude_adv_success - assert 400 == 200
FAILED test_llm.py::test_call_llm_success - assert 400 == 200

@Darkxzie Can you also check why these tests are failing? I have not seen it failing for other PRs yet.

FAILED test_adv_prompt.py::test_claude_adv_success - assert 400 == 200
FAILED test_llm.py::test_call_llm_success - assert 400 == 200

Hey riya, I checked the failing run. This pr is from a fork branch, so github actions is running without the anthropic api key which is why both test_claud_adv_success and test_call_llm_success are failing. I did this because i currently do not have permission to create branches in this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants