Skip to content

Conversation

jjmachan
Copy link
Member

@jjmachan jjmachan commented Aug 2, 2023

todo

  • greenlight this with shahul about the UI

Added a context manager to group together runs in order to make it easier to visualise what is happening inside ragas.

future steps

  • connect the output values along with the context too

Comment on lines +96 to +142
with trace_as_chain_group(
callback_group_name, callback_manager=callbacks
) as batch_group:
for q, a in zip(question, answer):
human_prompt = LONG_FORM_ANSWER_PROMPT.format(question=q, answer=a)
prompts.append(ChatPromptTemplate.from_messages([human_prompt]))

result = generate(prompts, self.llm, callbacks=batch_group)
list_statements: list[list[str]] = []
for output in result.generations:
# use only the first generation for each prompt
statements = output[0].text.split("\n")
list_statements.append(statements)

prompts = []
for context, statements in zip(contexts, list_statements):
statements_str: str = "\n".join(
[f"{i+1}.{st}" for i, st in enumerate(statements)]
)
score = score / len(list_statements[i])
else:
score = max(0, output.count("verdict: no")) / len(list_statements[i])

scores.append(1 - score)

return ds.add_column(f"{self.name}", scores) # type: ignore
contexts_str: str = "\n".join(context)
human_prompt = NLI_STATEMENTS_MESSAGE.format(
context=contexts_str, statements=statements_str
)
prompts.append(ChatPromptTemplate.from_messages([human_prompt]))

result = generate(prompts, self.llm, callbacks=batch_group)
outputs = result.generations

scores = []
final_answer = "Final verdict for each statement in order:"
final_answer = final_answer.lower()
for i, output in enumerate(outputs):
output = output[0].text.lower().strip()
if output.find(final_answer) != -1:
output = output[output.find(final_answer) + len(final_answer) :]
score = sum(
0 if "yes" in answer else 1
for answer in output.strip().split(".")
if answer != ""
)
score = score / len(list_statements[i])
else:
score = max(0, output.count("verdict: no")) / len(list_statements[i])

scores.append(1 - score)

return scores
Copy link
Member Author

Choose a reason for hiding this comment

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

can you make sure this part is consistent with your change also. There was a merge conflict I fixed here

@shahules786 shahules786 merged commit 40ad4f7 into explodinggradients:main Aug 2, 2023
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.

2 participants