Skip to content

Commit

Permalink
add token mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
menamerai committed Feb 2, 2024
1 parent cb3976e commit 8339961
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Empty file removed scripts/.gitkeep
Empty file.
14 changes: 14 additions & 0 deletions scripts/map_tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from datasets import DatasetDict, IterableDataset, IterableDatasetDict
from datasets.arrow_dataset import Dataset


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

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

return mapping

0 comments on commit 8339961

Please sign in to comment.