Skip to content

fixes EmbeddingScorer._prepare() passes arg of wrong type #133

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions delphi/scorers/embedding/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,39 @@ async def __call__( # type: ignore
random.shuffle(samples)
results = self._query(
record.explanation,
samples, # type: ignore
samples,
)

return ScorerResult(record=record, score=results)

def call_sync(self, record: LatentRecord) -> list[EmbeddingOutput]:
return asyncio.run(self.__call__(record)) # type: ignore

def _prepare(self, record: LatentRecord) -> list[list[Sample]]:
def _prepare(self, record: LatentRecord) -> list[Sample]:
"""
Prepare and shuffle a list of samples for classification.
"""
samples = []

defaults = {
"tokenizer": self.tokenizer,
}
samples = examples_to_samples(
record.extra_examples, # type: ignore
distance=-1,
**defaults, # type: ignore
)
if record.extra_examples is not None:
samples.extend(
examples_to_samples(
record.extra_examples,
tokenizer=self.tokenizer,
distance=-1,
)
)

for i, examples in enumerate(record.test):
for i, example in enumerate(record.test):
samples.extend(
examples_to_samples(
examples, # type: ignore
[example],
tokenizer=self.tokenizer,
distance=i + 1,
**defaults, # type: ignore
)
)

return samples # type: ignore
return samples

def _query(self, explanation: str, samples: list[Sample]) -> list[EmbeddingOutput]:
explanation_string = (
Expand Down Expand Up @@ -110,15 +111,15 @@ def _query(self, explanation: str, samples: list[Sample]) -> list[EmbeddingOutpu

def examples_to_samples(
examples: list[Example],
tokenizer: PreTrainedTokenizer,
tokenizer: PreTrainedTokenizer | None,
**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)
text = "".join(str(token) for token in example.tokens)
activations = example.activations.tolist()
samples.append(
Sample(
Expand Down