File size: 31,839 Bytes
6ae9156 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | """Deterministic synthetic intent examples with separate calibration phrasing.
The dataset teaches intent labels, not Lisp syntax. NAME is a placeholder for
one separately parsed buffer name, file path, or search string. Original benchmark paraphrases are excluded
even when embedded in a polite wrapper. Calibration templates are written
separately from training templates and are not generated by a random row split.
"""
import re
from actions import ActionKind
from expanded_data import (
CALIBRATION_FAMILIES as EXPANDED_CALIBRATION_FAMILIES,
CALIBRATION_REJECT_MIGRATIONS,
CALIBRATION_REJECT_REWRITES,
CALIBRATION_REJECTS as EXPANDED_CALIBRATION_REJECTS,
TRAINING_FAMILIES as EXPANDED_TRAINING_FAMILIES,
TRAINING_REJECT_MIGRATIONS,
TRAINING_REJECTS as EXPANDED_TRAINING_REJECTS,
)
import lispm_data
import contrastive_data
REJECT = "reject"
ORIGINAL_PARAPHRASES = [
"put a new window on the right",
"put a new window below",
"switch focus to the next window",
"close every other window",
"give the windows equal sizes",
"take me to the top of the buffer",
"take me to the bottom of the buffer",
"display the buffer named NAME",
]
_TRAINING_FAMILIES = {
ActionKind.SPLIT_RIGHT.value: (
"split right",
"split the window to the right",
"make a pane on the right",
"split this window to the right",
"split the current window on the right",
"split the active pane to its right",
"split this pane on the right side",
"create a window to the right",
"create another pane on the right",
"create a new right hand pane",
"add a window on the right",
"add another window to the right of this one",
"add a pane to the right of the current pane",
"make another window to my right",
"make a new pane to the right of this window",
"open a window on the right",
"open another pane to the right",
"open a new right side window",
"divide the window with a new pane on the right",
"divide this pane into side by side windows",
"split this window into two adjacent panes",
"make two windows side by side",
"make a rightward window split",
"split the selected window rightwards",
"on the right create another window",
"to the right add a new pane",
"on this window right side make a pane",
"give me a pane to the right",
"give me another window on the right side",
"put an additional pane on the right",
"put a second window to the right of this one",
"create a side by side split with the new window on the right",
),
ActionKind.SPLIT_BELOW.value: (
"split below",
"split the window below",
"make a pane below",
"split this window below",
"split the current window underneath",
"split the active pane below it",
"split this pane on the bottom side",
"create a window below",
"create another pane underneath",
"create a new lower pane",
"add a window below this one",
"add another window underneath this window",
"add a pane below the current pane",
"make another window underneath me",
"make a new pane below this window",
"open a window below",
"open another pane underneath",
"open a new bottom window",
"divide the window with a new pane below",
"divide this pane into stacked windows",
"split this window into two stacked panes",
"make two windows one above the other",
"make a downward window split",
"split the selected window downwards",
"below this window create another window",
"underneath add a new pane",
"at the bottom of this window make a pane",
"give me a pane below this one",
"give me another window underneath",
"put an additional pane below",
"put a second window underneath this one",
"create a stacked split with the new window below",
),
ActionKind.NEXT_WINDOW.value: (
"select the next window",
"focus the next pane",
"move to the next window",
"switch to the next window",
"switch to the next pane",
"go to the next window",
"go to the next pane",
"select the following window",
"select the following pane",
"focus the following window",
"focus the next window",
"activate the next pane",
"activate the next window",
"move focus to the next pane",
"move focus to the following window",
"move the cursor to the next window",
"cycle to the next window",
"cycle forward through the windows",
"cycle forward to another pane",
"advance to the next window",
"advance to the following pane",
"advance window focus by one",
"change focus to the next window",
"change the active window to the next one",
"choose the next pane",
"choose the next window",
"make the next pane active",
"bring the next window into focus",
"give the next pane focus",
"put focus in the next window",
"next window",
"next pane",
),
ActionKind.KEEP_WINDOW.value: (
"keep only this window",
"close the other panes",
"maximize this window",
"keep only the current window",
"keep only the active pane",
"keep this pane by closing the others",
"keep the selected window only",
"leave only this window",
"leave only the current pane",
"leave the active window open by closing the others",
"close all other windows",
"close all other panes",
"close the windows other than this one",
"close all panes other than the current pane",
"delete the other windows",
"delete all other panes",
"remove all other windows",
"remove the other panes",
"remove every pane other than this one",
"maximize the current window",
"maximize the active pane",
"expand this window to fill the frame",
"expand the selected pane to the whole frame",
"make this the only window",
"make the current pane the only pane",
"make this window fill the frame",
"show only the active window",
"show just this pane",
"use a single window keeping this one",
"reduce the layout to the current pane",
"keep this window by removing all its siblings",
"give all the frame space to the current window",
),
ActionKind.BALANCE_WINDOWS.value: (
"balance the windows",
"equalize pane sizes",
"make all panes equal",
"balance all windows",
"balance all panes",
"balance the pane layout",
"equalize the windows",
"equalize all window sizes",
"equalize the dimensions of the panes",
"make the windows the same size",
"make all windows equally sized",
"make every pane the same size",
"make pane sizes equal",
"make window sizes match",
"resize all panes equally",
"resize the windows to equal sizes",
"resize every window to the same size",
"distribute space equally between windows",
"distribute space evenly across panes",
"share the frame evenly among the windows",
"even out the window sizes",
"even out the pane sizes",
"evenly size all the windows",
"arrange the panes with equal sizes",
"arrange the windows evenly",
"set all pane sizes equal",
"set equal sizes for all windows",
"give each pane the same amount of space",
"give all windows an equal share of the frame",
"adjust the panes to equal sizes",
"restore equal window sizes",
"balance windows",
),
ActionKind.BUFFER_START.value: (
"go to buffer start",
"jump to the beginning",
"move to the top",
"go to the start of the buffer",
"go to the beginning of this buffer",
"go to the top of the current buffer",
"jump to buffer start",
"jump to the beginning of the buffer",
"jump to the top of this buffer",
"move to the start of the current buffer",
"move to the beginning of this buffer",
"move to the top of the buffer",
"move point to buffer start",
"move point to the beginning of the buffer",
"move the cursor to the start of this buffer",
"move the cursor to the very beginning",
"put the cursor at the beginning of the buffer",
"put point at the start of the buffer",
"position the cursor at buffer start",
"position point at the beginning",
"navigate to the start of the buffer",
"navigate to the top of the buffer",
"take me to buffer start",
"take the cursor to the beginning",
"return to the beginning of the buffer",
"return to buffer start",
"beginning of buffer",
"top of the buffer",
"start of this buffer",
"go to the first character of the buffer",
"move to the very first position in the buffer",
"jump all the way to the top",
),
ActionKind.BUFFER_END.value: (
"go to buffer end",
"jump to the end",
"move to the bottom",
"go to the end of the buffer",
"go to the end of this buffer",
"go to the bottom of the current buffer",
"jump to buffer end",
"jump to the end of the buffer",
"jump to the bottom of this buffer",
"move to the end of the current buffer",
"move to the end of this buffer",
"move to the bottom of the buffer",
"move point to buffer end",
"move point to the end of the buffer",
"move the cursor to the end of this buffer",
"move the cursor to the very end",
"put the cursor at the end of the buffer",
"put point at the end of the buffer",
"position the cursor at buffer end",
"position point at the end",
"navigate to the end of the buffer",
"navigate to the bottom of the buffer",
"take me to buffer end",
"take the cursor to the end",
"return to the end of the buffer",
"return to buffer end",
"end of buffer",
"bottom of the buffer",
"end of this buffer",
"go past the last character of the buffer",
"move to the final position in the buffer",
"jump all the way to the bottom",
),
ActionKind.SWITCH_BUFFER.value: (
"switch to buffer NAME",
"show buffer NAME",
"visit the buffer NAME",
"switch to the buffer NAME",
"switch to NAME",
"switch the current buffer to NAME",
"show the buffer NAME",
"show NAME",
"show the buffer called NAME",
"show the buffer with the name NAME",
"display buffer NAME",
"display the buffer NAME",
"display NAME",
"display the buffer called NAME",
"visit buffer NAME",
"visit NAME",
"open buffer NAME",
"open the buffer NAME",
"open the buffer called NAME",
"select buffer NAME",
"select the buffer NAME",
"select the buffer named NAME",
"activate buffer NAME",
"activate the buffer called NAME",
"change to buffer NAME",
"change the current buffer to NAME",
"bring up buffer NAME",
"bring NAME into view",
"bring the buffer NAME to the front",
"make buffer NAME current",
"make NAME the selected buffer",
"in this window show buffer NAME",
),
}
_REJECT_FAMILIES = (
# Selecting or moving a directional window does not create a new window.
"focus right", "focus left", "focus above", "focus below",
"select the right window", "select the left window",
"select the upper pane", "select the lower pane",
"switch to the window on the right", "switch to the window below",
"go to the right pane", "go to the pane above",
"move focus to the left", "move focus down", "move focus up",
"move the window to the right", "move this pane below the other one",
"swap the left and right windows", "swap the top and bottom panes",
"rotate the windows", "reorder the panes",
# Unsupported direction, unspecified split, or repeated/simultaneous intent.
"split left", "split above", "split the window to the left",
"create a window above", "make a pane on the left",
"add another pane above this one", "open a window on the left",
"split window", "split the window", "split this pane", "split",
"make a window", "create another pane", "add a new window",
"split right twice", "split below three times", "make three panes",
"create four windows on the right", "split right below",
"split the right window", "split the bottom pane",
# Next-window intent is distinct from previous or specific targets.
"select the previous window", "focus the previous pane",
"move to the previous window", "cycle backward through the windows",
"go back to the last pane", "activate the first window",
"select the second pane", "select the last window",
"skip the next window", "advance two windows", "focus another window",
"next buffer", "show the next buffer", "switch to the previous buffer",
"select the next tab", "switch to the next frame",
# Deleting the current/target buffer or window is not keeping the current one.
"close this window", "close the current pane", "delete the active window",
"remove this pane", "close all windows", "close every pane",
"close the next window", "delete the previous pane",
"keep the next window", "keep the left pane", "keep both windows",
"maximize other window", "maximize the next pane", "maximize all windows",
"minimize this window", "hide the current pane", "close the buffer",
"delete the buffer", "kill the current buffer", "close buffer NAME",
"delete buffer NAME", "kill buffer NAME", "close the buffer called NAME",
# Fixed-size resizing or an unequal layout is not balancing.
"make this window wider", "make the current pane narrower",
"make this pane taller", "make the active window shorter",
"enlarge this window", "shrink the current pane",
"resize the window", "resize this pane to half the frame",
"set the window width to eighty columns", "set the pane height to ten lines",
"increase the width by one column", "decrease the height by two lines",
"give the right window more space", "give the top pane less space",
"balance only the current buffer", "make all buffers equal",
"give the windows different sizes", "make the panes unequal",
# Motion target distinctions: line, word, visible area, middle, search.
"go to the start of the line", "go to the end of the line",
"move to line beginning", "move to line end",
"jump to the first word", "jump to the last word",
"go to buffer middle", "move to the middle of the buffer",
"move the cursor one line down", "move the cursor one character right",
"go to the top of the visible window", "go to the bottom of the screen",
"scroll to the top", "scroll to the bottom", "scroll down one page",
"go to line fifty", "jump to line ten", "go to the next paragraph",
"select the buffer contents", "delete everything in the buffer",
"insert text at buffer start", "append text to the end of the buffer",
"search for NAME", "find NAME in this buffer",
# File/metadata operations must not turn into switch-to-buffer.
"open file NAME", "open the file NAME", "visit file NAME",
"read the file NAME", "find file NAME", "load file NAME",
"save the buffer", "save buffer NAME", "save file NAME",
"write the buffer to NAME", "rename the buffer NAME",
"rename buffer NAME", "delete file NAME", "create file NAME",
"create directory NAME", "open directory NAME", "show folder NAME",
"show the contents of file NAME", "show all buffers", "list the buffers",
"list open windows", "show the buffer list", "show window NAME",
"open terminal NAME", "run command NAME", "execute NAME",
"change the buffer name to NAME", "copy buffer NAME",
# Incomplete arguments, conflicting targets, and out-of-domain requests.
"show buffer", "switch to buffer", "visit the buffer", "display the buffer",
"select the buffer named", "switch to", "show", "move to", "go to",
"right", "below", "start", "end", "top", "bottom", "window", "buffer",
"NAME", "NAME buffer", "NAME window", "name the buffer",
"go to the top bottom of the buffer", "select the next previous window",
"make panes equal unequal", "split right or below",
"hello", "hello world", "good morning", "thank you", "help me",
"what time is it", "tell me a joke", "calculate the total",
"explain the code", "install a package", "undo the last change",
"redo the edit", "quit emacs", "restart the editor",
"unicorns frobnicate", "purple banana windows", "wibble wobble",
"flarble the snorg", "zqxv blorp", "pane banana buffer",
"do not split right", "never close the other panes", "do nothing",
)
_CALIBRATION_FAMILIES = {
ActionKind.SPLIT_RIGHT.value: (
"divide this window so the added pane is on its right",
"create a companion pane to the right of this one",
"make room for another window on the right side",
"put an extra pane to the right of the active window",
"give this window a new neighbour on the right",
"open an additional window beside this one on its right",
),
ActionKind.SPLIT_BELOW.value: (
"divide this window so the added pane is underneath it",
"create a companion pane below this one",
"make room for another window under the active pane",
"put an extra pane underneath the selected window",
"give this window a new neighbour below it",
"open an additional window beneath this one",
),
ActionKind.NEXT_WINDOW.value: (
"activate the window following this one",
"give focus to the succeeding pane",
"make the next window active",
"continue to the next pane in window order",
"move window selection ahead by one",
"hand focus to the next window",
),
ActionKind.KEEP_WINDOW.value: (
"leave the selected window as the sole pane",
"remove all panes apart from the selected one",
"give the entire frame to this window",
"retain the active pane alone",
"close its siblings so this pane stays",
"let this window occupy the whole frame",
),
ActionKind.BALANCE_WINDOWS.value: (
"allocate equal space to all existing panes",
"adjust every window to have matching sizes",
"distribute frame space evenly among its windows",
"make the panes occupy equal portions of the frame",
"normalize the dimensions of the windows",
"use an even layout for the existing panes",
),
ActionKind.BUFFER_START.value: (
"place point at the earliest position in this buffer",
"navigate to where the current buffer begins",
"set point to the first position of the active buffer",
"head to the very top of the current buffer",
"start at the beginning of the active buffer",
"reposition the cursor at the buffer beginning",
),
ActionKind.BUFFER_END.value: (
"place point at the final position in this buffer",
"navigate to where the current buffer ends",
"set point past the last character of the active buffer",
"head to the very bottom of the current buffer",
"finish at the end of the active buffer",
"reposition the cursor at the buffer end",
),
ActionKind.SWITCH_BUFFER.value: (
"make NAME the active buffer",
"use NAME as the current buffer",
"bring the buffer called NAME into view",
"put buffer NAME into the selected window",
"turn attention to the buffer with name NAME",
"change the displayed buffer to NAME",
),
}
_CALIBRATION_REJECTS = (
"move the selected pane to the right",
"give focus to the window immediately to the right",
"rearrange this window beside the other one",
"activate the rightmost pane",
"put the current window on the left side",
"create an additional pane above this window",
"send the current window downward",
"select the pane underneath the active one",
"focus the bottommost window",
"move the lower window upward",
"create an extra pane without choosing a direction",
"divide this window into three equal panes",
"hand focus to the preceding window",
"move window selection back by one",
"advance to the next open buffer",
"continue to the next application",
"activate the third pane in window order",
"move forward by two panes",
"remove the selected window and keep the rest",
"leave the rightmost window as the sole pane",
"close the active pane alone",
"remove every window in the frame",
"hide all windows temporarily",
"discard the buffer called NAME",
"allocate more space to the current pane",
"make the right pane twice as wide",
"reduce this window to five lines high",
"set unequal proportions for the windows",
"normalize indentation in this buffer",
"balance the parentheses in the buffer",
"place point at the earliest position in this line",
"navigate to the beginning of the next paragraph",
"set point to the first position of the selected word",
"head to the topmost visible text",
"reposition the cursor in the middle of the buffer",
"highlight everything from the beginning of the buffer",
"place point at the final position in this line",
"navigate to the end of the current sentence",
"set point past the last character of the selected word",
"head to the bottom of the visible screen",
"delete text until the end of the buffer",
"insert a new line at the buffer end",
"use NAME as the new name for this buffer",
"bring the file called NAME into the editor",
"put buffer contents into the file NAME",
"change the directory to NAME",
"make NAME the active color theme",
"display documentation for NAME",
)
_TRAINING_WRAPPERS = (
"{}", "please {}", "could you {}", "can you {}",
"i would like you to {}", "{} please",
)
_CALIBRATION_WRAPPERS = ("{}", "would you please {}")
_WINDOW_WORDS = re.compile(r"\b(?:window|windows|pane|panes)\b")
_CURRENT_WORDS = re.compile(r"\b(?:current|active|selected)\b")
def _normalized(phrase):
return " ".join(phrase.casefold().split())
def _synonym_variants(phrase):
"""Apply the same small label-preserving vocabulary substitutions to all labels."""
nouns = [phrase]
for singular, plural in (("window", "windows"), ("pane", "panes")):
nouns.append(_WINDOW_WORDS.sub(
lambda match: plural if match.group().endswith("s") else singular,
phrase,
))
variants = []
for text in dict.fromkeys(nouns):
variants.append(text)
variants.extend(_CURRENT_WORDS.sub(word, text)
for word in ("current", "active", "selected"))
return tuple(dict.fromkeys(variants))
def _augment_training(authored, calibration_keys, forbidden):
"""Add systematic variants while preserving the separately authored holdouts."""
rows = list(authored)
seen = {_normalized(phrase): label for phrase, label in authored}
for phrase, label in authored:
for variant in _synonym_variants(phrase):
key = _normalized(variant)
previous = seen.get(key)
if previous is not None and previous != label:
raise ValueError(f"Synonym expansion produced contradictory labels: {variant!r}.")
if previous is not None:
continue
if key in calibration_keys or any(original in key for original in forbidden):
continue
if previous is None:
rows.append((variant, label))
seen[key] = label
return rows
def _expand(families, rejects, positive_wrappers, reject_wrappers):
rows = []
seen = {}
sources = [
(label, phrases, positive_wrappers)
for label, phrases in families.items()
] + [(REJECT, rejects, reject_wrappers)]
for label, phrases, wrappers in sources:
for phrase in phrases:
for wrapper in wrappers:
text = wrapper.format(phrase)
key = _normalized(text)
previous = seen.get(key)
if previous is not None and previous != label:
raise ValueError(f"Contradictory labels for {text!r}.")
if previous is None:
rows.append((text, label))
seen[key] = label
return rows
def _expanded_families(core, additions, rejects, migrations, rewrites=None):
"""Migrate newly supported old negatives before adding new action families."""
rewrites = rewrites or {}
if set(migrations) - set(rejects):
raise ValueError("A reject migration refers to a nonexistent source phrase.")
if set(rewrites) - set(migrations):
raise ValueError("Only explicitly migrated reject phrases can be rewritten.")
families = {label: tuple(phrases) for label, phrases in core.items()}
for label, phrases in additions.items():
if label in families:
raise ValueError(f"An expanded action duplicates a core label: {label!r}.")
families[label] = tuple(phrases)
for phrase, label in migrations.items():
if label not in families:
raise ValueError(f"A reject migration names an unsupported label: {label!r}.")
families[label] += (rewrites.get(phrase, phrase),)
remaining = tuple(phrase for phrase in rejects if phrase not in migrations)
return families, remaining
def _build_splits():
training_families, training_rejects = _expanded_families(
_TRAINING_FAMILIES, EXPANDED_TRAINING_FAMILIES, _REJECT_FAMILIES,
TRAINING_REJECT_MIGRATIONS,
)
calibration_families, calibration_rejects = _expanded_families(
_CALIBRATION_FAMILIES, EXPANDED_CALIBRATION_FAMILIES, _CALIBRATION_REJECTS,
CALIBRATION_REJECT_MIGRATIONS, CALIBRATION_REJECT_REWRITES,
)
training_rejects += EXPANDED_TRAINING_REJECTS
calibration_rejects += EXPANDED_CALIBRATION_REJECTS
training_families, training_rejects = _expanded_families(
training_families, lispm_data.TRAINING_FAMILIES, training_rejects,
lispm_data.TRAINING_REJECT_MIGRATIONS,
)
calibration_families, calibration_rejects = _expanded_families(
calibration_families, lispm_data.CALIBRATION_FAMILIES, calibration_rejects,
lispm_data.CALIBRATION_REJECT_MIGRATIONS,
)
training_rejects += lispm_data.TRAINING_REJECTS
calibration_rejects += lispm_data.CALIBRATION_REJECTS
train = _expand(training_families, training_rejects,
_TRAINING_WRAPPERS, _TRAINING_WRAPPERS)
calibration = _expand(calibration_families, calibration_rejects,
_CALIBRATION_WRAPPERS, _CALIBRATION_WRAPPERS)
train_keys = {_normalized(phrase) for phrase, _ in train}
calibration_keys = {_normalized(phrase) for phrase, _ in calibration}
if train_keys & calibration_keys:
raise ValueError("Training and calibration phrases overlap.")
forbidden = tuple(_normalized(phrase) for phrase in ORIGINAL_PARAPHRASES)
for phrase, _ in train + calibration:
normalized = _normalized(phrase)
if any(original in normalized for original in forbidden):
raise ValueError(f"Original benchmark phrase leaked into data: {phrase!r}.")
calibration_bases = tuple(
_normalized(phrase)
for phrases in list(calibration_families.values()) + [calibration_rejects]
for phrase in phrases
)
# A wrapped copy of a calibration base would still reveal its entire phrasing.
return _augment_training(train, calibration_keys, forbidden + calibration_bases), calibration
def _merge_consistent(rows):
"""Deduplicate normalized phrases without silently overwriting their labels."""
result, seen = [], {}
for phrase, label in rows:
key = _normalized(phrase)
if key in seen and seen[key] != label:
raise ValueError(f'Conflicting contrastive label for {phrase!r}.')
if key not in seen:
result.append((phrase, label))
seen[key] = label
return result
def _extend_splits(base_train, base_calibration):
"""Append disjoint contrastive examples and retain the original calibration prefix.
Every new calibration base and polite wrapper is excluded from training.
Keeping the original subset intact gives model selection a common coverage
reference, rather than changing the denominator when adding hard cases.
"""
added_train = _expand(contrastive_data.TRAINING_FAMILIES, contrastive_data.TRAINING_REJECTS,
_TRAINING_WRAPPERS, _TRAINING_WRAPPERS)
added_calibration = _expand(contrastive_data.CALIBRATION_FAMILIES,
contrastive_data.CALIBRATION_REJECTS,
_CALIBRATION_WRAPPERS, _CALIBRATION_WRAPPERS)
calibration = _merge_consistent(base_calibration + added_calibration)
calibration_keys = {_normalized(phrase) for phrase, _ in calibration}
new_bases = tuple(_normalized(phrase) for phrases in
list(contrastive_data.CALIBRATION_FAMILIES.values())
+ [contrastive_data.CALIBRATION_REJECTS] for phrase in phrases)
originals = tuple(_normalized(phrase) for phrase in ORIGINAL_PARAPHRASES)
forbidden = tuple(_normalized(phrase) for phrase, _ in base_calibration) + new_bases + originals
train = _merge_consistent(base_train + added_train)
train = [(phrase, label) for phrase, label in train
if _normalized(phrase) not in calibration_keys
and not any(base in _normalized(phrase) for base in new_bases + originals)]
train = _augment_training(train, calibration_keys, forbidden)
return train, calibration
# Immutable historical splits anchor fair before/after coverage comparisons.
_BASE_TRAINING_ROWS, _BASE_CALIBRATION_ROWS = _build_splits()
# Current training/model-selection data; independent test files are never read.
_TRAINING_ROWS, _CALIBRATION_ROWS = _extend_splits(_BASE_TRAINING_ROWS, _BASE_CALIBRATION_ROWS)
def training_rows(include_contrastive=True) -> list[tuple[str, str]]:
"""Return a fresh list of reproducible training phrases and intent labels."""
return list(_TRAINING_ROWS if include_contrastive else _BASE_TRAINING_ROWS)
def calibration_rows(include_contrastive=True) -> list[tuple[str, str]]:
"""Return disjoint phrasing families reserved for threshold calibration."""
return list(_CALIBRATION_ROWS if include_contrastive else _BASE_CALIBRATION_ROWS)
def hard_training_rows() -> list[tuple[str, str]]:
"""Return authored operation contrasts that survived all holdout exclusions."""
admitted = set(_TRAINING_ROWS)
return [row for row in contrastive_data.HARD_TRAINING_ROWS if row in admitted]
|