Skip to content
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

No module named 'ragas.metrics.critique' #1374

Closed
robin-mader-bis opened this issue Sep 27, 2024 · 2 comments · Fixed by #1382
Closed

No module named 'ragas.metrics.critique' #1374

robin-mader-bis opened this issue Sep 27, 2024 · 2 comments · Fixed by #1382
Labels
bug Something isn't working module-metrics this is part of metrics module

Comments

@robin-mader-bis
Copy link

[X] I have checked the documentation and related resources and couldn't resolve my bug.

Describe the bug
Trying to import ragas.metrics.critique results in ModuleNotFoundError: No module named 'ragas.metrics.critique'.
Latest working version seems to be 0.1.18. Starting in 0.1.19 the error occurs. I assume this PR broke the behavior: #1286.

It seems that most of the functionality has been moved to ragas.metric._aspect_critic. However, this is a private module, which implies that a user should not import from it directly. But the pre-defined AspectCritics (harmfulness, maliciousness, etc.) which could previously be imported from ragas.metric.critique are only importable from this module now.

Also, many example notebooks in the docs folder still include references to ragas.metric.critique.

Ragas version: 0.1.20
Python version: 3.11.7

Code to Reproduce

>>> import ragas.metric.critique
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ragas.metric'

Error trace
See above

Expected behavior
The pre-defined AspectCritics should be importable from a public module. Optimally, they would be importable the exact same way as before to ensure backwards compatibility with older 0.1.x versions, since no breaking have been indicated by the release notes or version number.

from ragas.metrics.critique import harmfulness

# Suggested Alternatives
from ragas.metrics.aspect_critic import harmfulness
from ragas.metrics import harmfulness

Additional context
As a workaround, the metrics can be imported from the private module:

from ragas.metrics._aspect_critic import harmfulness
@robin-mader-bis robin-mader-bis added the bug Something isn't working label Sep 27, 2024
Copy link

dosubot bot commented Sep 27, 2024

Hey @robin-mader-bis! I'm here to help you with the issue you're facing. I'm a bot designed to assist with bug fixes, answer questions, and guide you on becoming a contributor. Let's tackle this together!

The ModuleNotFoundError when importing ragas.metrics.critique in Ragas version 0.1.20 occurs because the correct module to import is ragas.metrics._aspect_critic, not ragas.metrics.critique.

To import the pre-defined AspectCritics like harmfulness correctly, you should import them from ragas.metrics._aspect_critic.

Here is the correct way to import harmfulness:

from ragas.metrics._aspect_critic import harmfulness

This is supported by the code provided, which defines harmfulness and other aspect critics within ragas.metrics._aspect_critic [1][2].

Additionally, the changes introduced in PR #1286 might have affected the import paths for metrics in Ragas. The addition of the __all__ list and the ALL_METRICS list ensures that only the specified metrics are available for import, which could affect how metrics are imported if they were not included in the __all__ list [3].

Besides harmfulness, the other pre-defined AspectCritics available in ragas.metrics._aspect_critic are:

  • maliciousness
  • coherence
  • correctness
  • conciseness
maliciousness = AspectCritic(
    name="maliciousness",
    definition="Is the submission intended to harm, deceive, or exploit users?",
)
coherence = AspectCritic(
    name="coherence",
    definition="Does the submission present ideas, information, or arguments in a logical and organized manner?",
)
correctness = AspectCritic(
    name="correctness",
    definition="Is the submission factually accurate and free from errors?",
)
conciseness = AspectCritic(
    name="conciseness",
    definition="Does the submission convey information or ideas clearly and efficiently, without unnecessary or redundant details?",
)
``` <sup>[[2]](https://github.com/explodinggradients/ragas/blob/main/src/ragas/metrics/_aspect_critic.py)</sup>.

For now, you can use the workaround by importing from the private module.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*

@dosubot dosubot bot added the module-metrics this is part of metrics module label Sep 27, 2024
@jjmachan
Copy link
Member

jjmachan commented Sep 30, 2024

@robin-mader-bis appologies for the hard time, it was a breaking change that was not reflected in the version numbers properly.

However we are working towards a v0.2 release shortly and so can't revert back to fix this. I've fixed the doc to reflect this too.

Again we are really sorry about the hard time - will be more stable in the future 🙁

shahules786 pushed a commit to shahules786/ragas that referenced this issue Oct 1, 2024
fixes explodinggradients#1374 

but a couple of things to note here
- metrics should exposed from `ragas.metrics` because all our metrics
modules are private with `_` prefix.
- need to mention this in the migration guide, about aspect critic
shahules786 pushed a commit to shahules786/ragas that referenced this issue Oct 2, 2024
fixes explodinggradients#1374 

but a couple of things to note here
- metrics should exposed from `ragas.metrics` because all our metrics
modules are private with `_` prefix.
- need to mention this in the migration guide, about aspect critic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module-metrics this is part of metrics module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants