Datasets:
Download padding.py from samricotta/fin-extract-bench: direct link, hf CLI and curl.
- Browser
- Download file 3.41 kB
-
https://huggingface.co/datasets/samricotta/fin-extract-bench/resolve/main/padding.py
- Command line
-
hf download hf://datasets/samricotta/fin-extract-bench/padding.py
-
curl -L -o padding.py https://huggingface.co/datasets/samricotta/fin-extract-bench/resolve/main/padding.py
3.41 kB
| """Neutral filler text for the context depth axis. | |
| Deterministic for a given seed. Nothing here mentions invoices, payments, | |
| customers or instructions, so the only thing it adds is distance. | |
| Token counts are estimated at 4 characters per token; the runner records | |
| the real prompt_tokens from the API response. | |
| """ | |
| import random | |
| CHARS_PER_TOKEN = 4 | |
| _SUBJECTS = [ | |
| "The Leeds depot", "The night shift", "The facilities team", "The new forklift", | |
| "The timber rack", "The yard gate", "The staff canteen", "The training room", | |
| "The delivery schedule", "The weekly safety walk", "The recycling skip", | |
| "The car park resurfacing", "The uniform order", "The first aid cabinet", | |
| ] | |
| _VERBS = [ | |
| "was inspected on", "will be reviewed on", "is booked for", "was discussed at the meeting on", | |
| "has been rescheduled to", "was signed off on", "is due for maintenance on", "was repainted on", | |
| ] | |
| _DATES = [ | |
| "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "the 3rd", "the 12th", | |
| "the 19th", "the 26th", "the first of the month", "the last working day", | |
| ] | |
| _TAILS = [ | |
| "and no further action is needed.", "and the notes are on the shared drive.", | |
| "pending a quote from the contractor.", "with two staff attending.", | |
| "and the manager has been informed.", "as part of the quarterly plan.", | |
| "and the checklist was completed.", "following the usual procedure.", | |
| "and the supplier confirmed by phone.", "with photos attached to the ticket.", | |
| ] | |
| _POLICY = [ | |
| "Hard hats and boots must be worn beyond the yellow line in the yard.", | |
| "Forklift keys are returned to the office at the end of each shift.", | |
| "Visitors sign in at reception and are accompanied at all times.", | |
| "The canteen fridge is cleared every Friday afternoon.", | |
| "Annual leave requests go through the online portal with two weeks notice.", | |
| "Timber offcuts under one metre go in the blue skip, not the green one.", | |
| "Fire assembly point is the far corner of the staff car park.", | |
| "Deliveries are not accepted after four thirty without prior arrangement.", | |
| "Radios are charged overnight in the dispatch office.", | |
| "Spill kits are checked on the first Monday of each month.", | |
| ] | |
| def make_padding(n_tokens: int, seed: int = 7) -> str: | |
| """Return roughly n_tokens of neutral text as numbered paragraphs.""" | |
| if n_tokens <= 0: | |
| return "" | |
| rng = random.Random(seed) | |
| target_chars = n_tokens * CHARS_PER_TOKEN | |
| paragraphs = [] | |
| total = 0 | |
| i = 1 | |
| while total < target_chars: | |
| sentences = [ | |
| f"{rng.choice(_SUBJECTS)} {rng.choice(_VERBS)} {rng.choice(_DATES)} {rng.choice(_TAILS)}" | |
| for _ in range(rng.randint(3, 6)) | |
| ] | |
| if rng.random() < 0.3: | |
| sentences.append(rng.choice(_POLICY)) | |
| para = f"Note {i}. " + " ".join(sentences) | |
| paragraphs.append(para) | |
| total += len(para) + 2 | |
| i += 1 | |
| return "\n\n".join(paragraphs) | |
| def split_padding(padding: str, fraction: float) -> tuple[str, str]: | |
| """Split padding at a paragraph boundary near the given fraction of its length.""" | |
| if not padding: | |
| return "", "" | |
| cut = int(len(padding) * fraction) | |
| boundary = padding.rfind("\n\n", 0, cut) | |
| if boundary == -1: | |
| boundary = padding.find("\n\n", cut) | |
| if boundary == -1: | |
| return "", padding | |
| return padding[:boundary], padding[boundary + 2:] | |