Skip to content

Support zero-shot CoT for filter#197

Merged
sidjha1 merged 1 commit into
mainfrom
sid/cot-fix
Aug 8, 2025
Merged

Support zero-shot CoT for filter#197
sidjha1 merged 1 commit into
mainfrom
sid/cot-fix

Conversation

@sidjha1
Copy link
Copy Markdown
Collaborator

@sidjha1 sidjha1 commented Aug 8, 2025

Addresses #194. I think the CoT code has become very convoluted and there is probably a simpler way to achieve the desired functionality.

import lotus
from lotus.models import LM
from lotus.types import ReasoningStrategy
import pandas as pd

lm = LM(model="gpt-4.1")
lotus.settings.configure(lm=lm)

data = {
    "Text": [
        "I had two apples, then I gave away one",
        "My friend gave me an apple",
        "I gave away both of my apples",
        "I gave away my apple, then a friend gave me his apple, then I threw my apple away",
    ]
}
df = pd.DataFrame(data)
user_instruction = "{Text} I have at least one apple"
filtered_df = df.sem_filter(
    user_instruction, strategy=ReasoningStrategy.ZS_COT, return_all=True, return_explanations=True
) 

print(filtered_df)
Filtering: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ 4/4 LM calls [00:03<00:00,  1.17it/s]
                                                Text  filter_label                                 explanation_filter
0             I had two apples, then I gave away one          True  The text states, "I had two apples, then I gav...
1                         My friend gave me an apple          True  The text states, "My friend gave me an apple."...
2                      I gave away both of my apples         False  The text states, "I gave away both of my apple...
3  I gave away my apple, then a friend gave me hi...         False  Let's break down the sequence of events:\n1. "...

return cot_postprocessor


def map_postprocess_cot(llm_answers: list[str]) -> SemanticMapPostprocessOutput:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Never used

@sidjha1 sidjha1 requested review from ankitasun and liana313 August 8, 2025 01:14
@liana313
Copy link
Copy Markdown
Collaborator

liana313 commented Aug 8, 2025

LGTM!

Addresses #194. I think the CoT code has become very convoluted and there is probably a simpler way to achieve the desired functionality.

And I agree, opening #198 to address this. PR #140 is also related.

@liana313 liana313 closed this Aug 8, 2025
@liana313 liana313 reopened this Aug 8, 2025
@sidjha1 sidjha1 merged commit b4c2e6b into main Aug 8, 2025
14 checks passed
@sidjha1 sidjha1 deleted the sid/cot-fix branch August 8, 2025 01:55
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