-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[docs] Add Google-style docstrings for dspy/evaluate/metrics.py #8954
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
dspy/evaluate/metrics.py
Outdated
|
|
||
| def EM(prediction, answers_list): # noqa: N802 | ||
| assert isinstance(answers_list, list) | ||
| """Return True if any reference exactly matches the prediction (after normalization). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening line should describe what this API is, instead of the API's behavior.
dspy/evaluate/metrics.py
Outdated
| otherwise False. | ||
| Example: | ||
| >>> EM("The Eiffel Tower", ["Eiffel Tower", "Louvre"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't render on mkdocs, let's use the block style, e.g.,:
my_code
dspy/evaluate/metrics.py
Outdated
| >>> EM("paris", ["Paris"]) | ||
| True | ||
| """ | ||
| assert isinstance(answers_list, list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's don't mix fix with docstring changes. Actually this assert statement won't provide more information to users
dspy/evaluate/metrics.py
Outdated
| >>> round(F1("Eiffel Tower is in Paris", ["Paris"]), 2) | ||
| 0.33 | ||
| """ | ||
| assert isinstance(answers_list, list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
dspy/evaluate/metrics.py
Outdated
| float: The highest HotpotQA-style F1 score in [0.0, 1.0]. | ||
| Example: | ||
| >>> HotPotF1("yes", ["no"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use block code
dspy/evaluate/metrics.py
Outdated
|
|
||
| def remove_articles(text): | ||
| return re.sub(r"\b(a|an|the)\b", " ", text) | ||
| return re.sub(r"\\b(a|an|the)\\b", " ", text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to change this?
dspy/evaluate/metrics.py
Outdated
| def answer_exact_match(example, pred, trace=None, frac=1.0): | ||
| """Example/Prediction evaluator for answer strings with EM/F1 thresholding. | ||
| If ``example.answer`` is a string, compare ``pred.answer`` against it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: single backtick around variables: example.answer
dspy/evaluate/metrics.py
Outdated
|
|
||
|
|
||
| def answer_exact_match(example, pred, trace=None, frac=1.0): | ||
| """Example/Prediction evaluator for answer strings with EM/F1 thresholding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too detailed for the open sentence
…k examples); revert non-doc changes
|
All feedback addressed (concise openings + mkdocs block examples) |
This PR adds Google-style docstrings to public metrics in
dspy/evaluate/metrics.py.resolve #8953
cc @chenmoneygithub