Skip to content

Commit 1734900

Browse files
authored
fix: remove answer_relevance* intrinsics; fix other intrinsics issues (#690)
* fix: add support back for older models and requirement_check adapter * fix: fix model used in test_rag for intrinsics * fix: remove answer_relevance_classifier and answer_relevance_rewriter
1 parent a86fe40 commit 1734900

21 files changed

Lines changed: 4 additions & 10694 deletions

docs/examples/intrinsics/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ Core example showing how to directly use intrinsics with adapters.
1313
- Working with Granite Common adapters (aLoRA-based)
1414
- Understanding adapter output formats
1515

16-
### answer_relevance.py
17-
Evaluates whether an answer is relevant to a question.
18-
1916
### answerability.py
2017
Checks if a question can be answered given the context.
2118

@@ -71,7 +68,6 @@ out, new_ctx = mfuncs.act(
7168
## Available Intrinsics
7269

7370
- **requirement_check**: Validate requirements (used by ALoraRequirement)
74-
- **answer_relevance**: Check answer-question relevance
7571
- **answerability**: Determine if question is answerable
7672
- **citations**: Extract and validate citations
7773
- **context_relevance**: Assess context-query relevance

docs/examples/intrinsics/answer_relevance.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

mellea/backends/adapters/catalog.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,13 @@ class IntriniscsCatalogEntry(pydantic.BaseModel):
6565
# Core Intrinsics
6666
############################################
6767
IntriniscsCatalogEntry(name="requirement-check", repo_id=_CORE_R1_REPO),
68+
IntriniscsCatalogEntry(
69+
name="requirement_check", repo_id=_CORE_REPO
70+
), # Necessary to support granite 3.2 and 3.3.
6871
IntriniscsCatalogEntry(name="uncertainty", repo_id=_CORE_R1_REPO),
6972
############################################
7073
# RAG Intrinsics
7174
############################################
72-
IntriniscsCatalogEntry(
73-
name="answer_relevance_classifier",
74-
repo_id=_RAG_REPO,
75-
adapter_types=(AdapterType.LORA,),
76-
),
77-
IntriniscsCatalogEntry(name="answer_relevance_rewriter", repo_id=_RAG_REPO),
7875
IntriniscsCatalogEntry(name="answerability", repo_id=_RAG_REPO),
7976
IntriniscsCatalogEntry(name="citations", repo_id=_RAG_REPO),
8077
IntriniscsCatalogEntry(name="context_relevance", repo_id=_RAG_REPO),

mellea/stdlib/components/intrinsic/rag.py

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,6 @@
88
from ..chat import Message
99
from ._util import call_intrinsic
1010

11-
_ANSWER_RELEVANCE_CORRECTION_METHODS = {
12-
"Excessive unnecessary information": "removing the excessive information from the "
13-
"draft response",
14-
"Unduly restrictive": "providing answer without the unwarranted restriction, or "
15-
"indicating that the desired answer is not available",
16-
"Too vague or generic": "providing more crisp and to-the-point answer, or "
17-
"indicating that the desired answer is not available",
18-
"Contextual misalignment": "providing a response that answers the last user "
19-
"inquiry, taking into account the context of the conversation",
20-
"Misinterpreted inquiry": "providing answer only to the correct interpretation of "
21-
"the inquiry, or attempting clarification if the inquiry is ambiguous or otherwise "
22-
"confusing, or indicating that the desired answer is not available",
23-
"No attempt": "providing a relevant response if an inquiry should be answered, or "
24-
"providing a short response if the last user utterance contains no inquiry",
25-
}
26-
"""Prompting strings for the answer relevance rewriter. This model is a (a)LoRA adapter,
27-
so it's important to stick to in-domain prompts."""
28-
2911

3012
def check_answerability(
3113
question: str,
@@ -207,62 +189,3 @@ def flag_hallucinated_content(
207189
backend,
208190
)
209191
return result_json
210-
211-
212-
def rewrite_answer_for_relevance(
213-
response: str,
214-
documents: collections.abc.Iterable[Document],
215-
context: ChatContext,
216-
backend: AdapterMixin,
217-
/,
218-
rewrite_threshold: float = 0.5,
219-
) -> str:
220-
"""Rewrite an assistant answer to improve relevance to the user's question.
221-
222-
Args:
223-
response: The assistant's response to the user's question in the last turn
224-
of ``context``.
225-
documents: Document snippets that were used to generate ``response``.
226-
context: A chat log that ends with a user asking a question.
227-
backend: Backend instance that supports the adapters that implement this
228-
intrinsic.
229-
rewrite_threshold: Number between 0.0 and 1.0 that determines how eagerly
230-
to skip rewriting the assistant's answer for relevance. 0.0 means never
231-
rewrite and 1.0 means always rewrite.
232-
233-
Returns:
234-
Either the original response, or a rewritten version of the original response.
235-
"""
236-
# First run the classifier to determine the likelihood of a relevant answer
237-
# Output will have three fields:
238-
# * answer_relevance_analysis
239-
# * answer_relevance_category
240-
# * answer_relevance_likelihood
241-
result_json = call_intrinsic(
242-
"answer_relevance_classifier",
243-
context.add(Message("assistant", response, documents=list(documents))),
244-
backend,
245-
)
246-
if result_json["answer_relevance_likelihood"] >= rewrite_threshold:
247-
return response
248-
249-
# If we get here, the classifier indicated a likely irrelevant response. Trigger
250-
# rewrite.
251-
# Rewrite needs a prompt string that is an expanded version of the classifier's
252-
# short output.
253-
correction_method = _ANSWER_RELEVANCE_CORRECTION_METHODS[
254-
result_json["answer_relevance_category"]
255-
]
256-
257-
result_json = call_intrinsic(
258-
"answer_relevance_rewriter",
259-
context.add(Message("assistant", response, documents=list(documents))),
260-
backend,
261-
kwargs={
262-
"answer_relevance_category": result_json["answer_relevance_category"],
263-
"answer_relevance_analysis": result_json["answer_relevance_analysis"],
264-
"correction_method": correction_method,
265-
},
266-
)
267-
# Unpack boxed string
268-
return result_json["answer_relevance_rewrite"]

test/formatters/granite/test_intrinsics_formatters.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -193,32 +193,6 @@ def _maybe_download_yaml(self):
193193
task="context_relevance",
194194
is_alora=True,
195195
),
196-
YamlJsonCombo(
197-
short_name="answer_relevance_classifier",
198-
inputs_file=_INPUT_JSON_DIR / "answer_relevance_classifier.json",
199-
task="answer_relevance_classifier",
200-
),
201-
# aLoRA adapter for this intrinsic not currently available
202-
# YamlJsonCombo(
203-
# short_name="answer_relevance_classifier_alora",
204-
# inputs_file=_INPUT_JSON_DIR / "answer_relevance_classifier.json",
205-
# task="answer_relevance_classifier",
206-
# is_alora=True,
207-
# ),
208-
YamlJsonCombo(
209-
short_name="answer_relevance_rewriter",
210-
inputs_file=_INPUT_JSON_DIR / "answer_relevance_rewriter.json",
211-
arguments_file=_INPUT_ARGS_DIR / "answer_relevance_rewriter.json",
212-
task="answer_relevance_rewriter",
213-
),
214-
# aLoRA adapter for this intrinsic not currently available
215-
# YamlJsonCombo(
216-
# short_name="answer_relevance_rewriter_alora",
217-
# inputs_file=_INPUT_JSON_DIR / "answer_relevance_rewriter.json",
218-
# arguments_file=_INPUT_ARGS_DIR / "answer_relevance_rewriter.json",
219-
# task="answer_relevance_rewriter",
220-
# is_alora=True,
221-
# ),
222196
YamlJsonCombo(
223197
short_name="citations",
224198
inputs_file=_INPUT_JSON_DIR / "citations.json",

test/formatters/granite/testdata/input_args/answer_relevance_rewriter.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/formatters/granite/testdata/input_json/answer_relevance_classifier.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/formatters/granite/testdata/input_json/answer_relevance_rewriter.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/formatters/granite/testdata/test_canned_input/answer_relevance_classifier.json

Lines changed: 0 additions & 67 deletions
This file was deleted.

test/formatters/granite/testdata/test_canned_input/answer_relevance_rewriter.json

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)