-
Notifications
You must be signed in to change notification settings - Fork 12
Refine evaluator instructions #454
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,46 +1,38 @@ | ||||||||||||||
| from typing import cast | ||||||||||||||
|
|
||||||||||||||
| from draive.evaluation import EvaluationScore, EvaluationScoreValue, evaluator | ||||||||||||||
| from draive.evaluation import EvaluationScore, evaluator | ||||||||||||||
| from draive.evaluators.utils import FORMAT_INSTRUCTION, extract_evaluation_result | ||||||||||||||
| from draive.multimodal import Multimodal, MultimodalContent | ||||||||||||||
| from draive.stages import Stage | ||||||||||||||
|
|
||||||||||||||
| __all__ = ("coherence_evaluator",) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| INSTRUCTION: str = """\ | ||||||||||||||
| INSTRUCTION: str = f"""\ | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Mark INSTRUCTION as Final The Apply this diff: +from typing import Final
+
from draive.evaluation import EvaluationScore, evaluator-INSTRUCTION: str = f"""\
+INSTRUCTION: Final[str] = f"""\📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| You are evaluating the provided content according to the defined criteria. | ||||||||||||||
|
|
||||||||||||||
| <INSTRUCTION> | ||||||||||||||
| Compare the REFERENCE and the EVALUATED content by carefully examining them, then rate\ | ||||||||||||||
| the EVALUATED content using solely a coherence metric according to the EVALUATION_CRITERIA. | ||||||||||||||
| Compare the REFERENCE and the EVALUATED content by carefully examining them, then rate the EVALUATED content using solely a coherence metric according to the EVALUATION_CRITERIA. | ||||||||||||||
| Think step by step and provide explanation of the score before the final score. | ||||||||||||||
| Use the explained RATING scale and the requested FORMAT to provide the result. | ||||||||||||||
| </INSTRUCTION> | ||||||||||||||
|
|
||||||||||||||
| <EVALUATION_CRITERIA> | ||||||||||||||
| Evaluated metric is coherence - a collective quality of the content. | ||||||||||||||
| We align this dimension with the DUC (Document Understanding Conference) quality question of\ | ||||||||||||||
| structure and coherence, whereby the content should be well-structured and well-organized. | ||||||||||||||
| EVALUATED content should not just be a heap of related information, but should build from part | ||||||||||||||
| to part into a coherent body of information about the topic. | ||||||||||||||
| We align this dimension with the DUC (Document Understanding Conference) quality question of structure and coherence, whereby the content should be well-structured and well-organized. | ||||||||||||||
| EVALUATED content should not just be a heap of related information, but should build from part to part into a coherent body of information about the topic. | ||||||||||||||
| </EVALUATION_CRITERIA> | ||||||||||||||
| {guidelines} | ||||||||||||||
| {{guidelines}} | ||||||||||||||
| <RATING> | ||||||||||||||
| Assign a coherence score using exact name of one of the following values: | ||||||||||||||
| - "poor" is very low coherence, the content is chaotic, lacking logical connections between parts. | ||||||||||||||
| - "fair" is low coherence, some connections are visible, but the overall structure is weak. | ||||||||||||||
| - "good" is moderate coherence, the content has a noticeable structure, but with some shortcomings. | ||||||||||||||
| - "excellent" is high coherence, the content is well-organized with minor imperfections. | ||||||||||||||
| - "perfect" is very high coherence, the content is exemplarily structured, with smooth transitions\ | ||||||||||||||
| between ideas. | ||||||||||||||
| - "perfect" is very high coherence, the content is exemplarily structured, with smooth transitions between ideas. | ||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| Use the "none" value for content that cannot be rated at all. | ||||||||||||||
| </RATING> | ||||||||||||||
|
|
||||||||||||||
| <FORMAT> | ||||||||||||||
| The final result containing only the rating value, HAVE to be put inside a `RESULT`\ | ||||||||||||||
| xml tag within the result i.e. `<RESULT>good</RESULT>`. | ||||||||||||||
| </FORMAT> | ||||||||||||||
| """ | ||||||||||||||
| {FORMAT_INSTRUCTION} | ||||||||||||||
| """ # noqa: E501 | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| @evaluator(name="coherence") | ||||||||||||||
|
|
@@ -63,26 +55,17 @@ async def coherence_evaluator( | |||||||||||||
| meta={"comment": "Reference was empty!"}, | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| completion: MultimodalContent = await Stage.completion( | ||||||||||||||
| MultimodalContent.of( | ||||||||||||||
| "<REFERENCE>", | ||||||||||||||
| reference, | ||||||||||||||
| "</REFERENCE>\n<EVALUATED>", | ||||||||||||||
| evaluated, | ||||||||||||||
| "</EVALUATED>", | ||||||||||||||
| ), | ||||||||||||||
| instructions=INSTRUCTION.format( | ||||||||||||||
| guidelines=f"\n<GUIDELINES>\n{guidelines}\n</GUIDELINES>\n" | ||||||||||||||
| if guidelines is not None | ||||||||||||||
| else "" | ||||||||||||||
| ), | ||||||||||||||
| ).execute() | ||||||||||||||
|
|
||||||||||||||
| if result := completion.tag("RESULT"): | ||||||||||||||
| return EvaluationScore.of( | ||||||||||||||
| cast(EvaluationScoreValue, result.content.to_str().strip().lower()), | ||||||||||||||
| meta={"comment": completion.to_str()}, | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| else: | ||||||||||||||
| raise ValueError(f"Invalid evaluator result:\n{completion}") | ||||||||||||||
| return extract_evaluation_result( | ||||||||||||||
| await Stage.completion( | ||||||||||||||
| MultimodalContent.of( | ||||||||||||||
| "<REFERENCE>", | ||||||||||||||
| reference, | ||||||||||||||
| "</REFERENCE>\n<EVALUATED>", | ||||||||||||||
| evaluated, | ||||||||||||||
| "</EVALUATED>", | ||||||||||||||
| ), | ||||||||||||||
| instructions=INSTRUCTION.format( | ||||||||||||||
| guidelines=f"\n<GUIDELINES>\n{guidelines}\n</GUIDELINES>\n" if guidelines else "", | ||||||||||||||
| ), | ||||||||||||||
| ).execute() | ||||||||||||||
| ) | ||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.