Skip to content

Commit

Permalink
added type casting for token_map
Browse files Browse the repository at this point in the history
  • Loading branch information
menamerai committed Feb 9, 2024
1 parent 8339961 commit f0efad3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions scripts/map_tokens.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from datasets import DatasetDict, IterableDataset, IterableDatasetDict
from datasets.arrow_dataset import Dataset
from typing import cast

from datasets import Dataset


def token_map(
tokenized_dataset: DatasetDict | Dataset | IterableDatasetDict | IterableDataset,
tokenized_dataset: Dataset,
) -> dict[int, list[tuple[int, int]]]:
mapping = {}

tokenized_dataset = cast(Dataset, tokenized_dataset)
for prompt_idx, prompt in enumerate(tokenized_dataset):
prompt = cast(dict, prompt)
for token_idx, token in enumerate(prompt["tokens"]):
mapping.setdefault(token, []).append((prompt_idx, token_idx))

Expand Down

0 comments on commit f0efad3

Please sign in to comment.