Skip to content

EmbeddingScorer._prepare() passes arg of wrong type to examples_to_samples() #132

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

Open
anthonyduong9 opened this issue Jun 4, 2025 · 1 comment · May be fixed by #133
Open

EmbeddingScorer._prepare() passes arg of wrong type to examples_to_samples() #132

anthonyduong9 opened this issue Jun 4, 2025 · 1 comment · May be fixed by #133

Comments

@anthonyduong9
Copy link
Contributor

In

for i, examples in enumerate(record.test):
samples.extend(
examples_to_samples(
examples, # type: ignore
distance=i + 1,
**defaults, # type: ignore
)
)
, when record.test is list[ActivatingExample] (the type expected by annotations), examples is of type ActivatingExample, so when
def examples_to_samples(
examples: list[Example],
tokenizer: PreTrainedTokenizer,
**sample_kwargs,
) -> list[Sample]:
samples = []
for example in examples:
if tokenizer is not None:
text = "".join(tokenizer.batch_decode(example.tokens))
else:
text = "".join(example.tokens)
activations = example.activations.tolist()
samples.append(
Sample(
text=text,
activations=activations,
data=EmbeddingOutput(text=text, **sample_kwargs),
)
)
return samples
runs, it tries to iterate over an ActivatingExample, leading to a TypeError.

@anthonyduong9
Copy link
Contributor Author

I just realized that in

for i, examples in enumerate(record.test):
examples = assert_type(list, examples)
samples.extend(
examples_to_samples(
examples,
distance=i + 1,
**defaults,
)
)
, record.test is expected to be list[list[ActivatingExample]] rather than list[ActivatingExample]. But I think this might be incorrect, as this is due to #99, which fixed type errors, and in the rest of the codebase, record.test is expected to be list[ActivatingExample] (again, expected by type annotations).

If we want both places to expect record.test to be list[ActivatingExample], I can make the changes in my PR and mark it as ready for review.

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 a pull request may close this issue.

1 participant