모델을 고르기 전에 라우팅 작업을 측정한다
읽는 데 약 26분분 걸린다, 5절에 3개 예제이(가) 있음.
AI로 번역함. 영어 원문을 사람이 검증함. 우리가 책을 만드는 방식
영어판 2026.11.9판을 번역한 것이다. 원문 읽기
이 장을 마치면 이 책의 각 샘플이 무엇을 위한 것인지 설명할 수 있다. 라우터를 평가하는 세 가지 측정값을 분모와 함께 계산할 수 있다. 한 번 기록해 두고 모든 비교에 다시 쓰는 기준선도 읽을 수 있다.
현재는 호스팅 모델이 은행의 지원 수신함에 들어오는 메시지를 라우팅한다. 이 책의 라우터는 은행이 직접 운영할 수 있는 작은 오픈 모델이다. 문제는 이 모델이 자신이 맡기로 한 메시지에서 호스팅 모델과 대등한 성능을 낼 수 있는지, 그리고 메시지에 확신이 없을 때 그렇다고 알릴 수 있는지이다. 어떤 모델을 비교하든 그 전에 비교에 쓸 데이터, 샘플, 측정값이 고정되어 있어야 한다. 그렇지 않으면 비슷해 보이는 두 수치가 서로 다른 메시지에서 나왔거나, 서로 다른 개수로 나눈 값일 수 있다.
이 책은 호스팅 모델을 호출하지 않으므로 더 큰 오픈 모델인 Qwen3-4B-Instruct-2507을 대역으로 쓴다. 이 모델의 답은 제3자가 공개한 4비트 Q4_K_M GGUF 변환본에서 나오며, 고정된 리비전을 사용하고 답을 77개의 팀 이름으로 제한한다. 이 모델은 모든 테스트 메시지에 한 번씩 답하여 그 답을 기록해 두고, 예제는 이 답을 오프라인으로 읽는다. 따라서 누구나 결과를 재현할 수 있다. 자신의 모델이 있는 독자는 1장에서 보이는 방법대로 그 모델의 답을 같은 방식으로 기록할 수 있다.
데이터와 그 라이선스
라우터는 은행 업무 영역의 고객 서비스 문의를 모은 공개 데이터셋인 BANKING77로 학습하고 평가한다(Casanueva et al., 2020). 각 메시지에는 77개의 레이블 중 하나가 붙어 있다. BANKING77은 이 레이블을 인텐트라고 부르며, 이는 곧 받은편지함의 팀이다(1장).
Casanueva et al.(2020)은 *Efficient Intent Detection with Dual Sentence Encoders*에서 이 데이터셋을 소개했다. 이 논문은 Proceedings of the 2nd Workshop on Natural Language Processing for Conversational AI의 38–45쪽에 실려 있다(Anthology ID 2020.nlp4convai-1.5, arXiv 2003.04807). 초록은 이 데이터셋을 한 영역에서 나온 어려운 데이터셋이라고 설명하며, 77개 인텐트에 걸쳐 레이블이 붙은 예제가 13,083개라고 밝힌다. 논문의 3절도 BANKING 77이라고 이름 붙인 은행 업무 영역 데이터셋에 대해 같은 개수를 제시한다. 데이터 카드에는 파일을 가져온 커밋이 적혀 있다. 두 파일에는 합쳐서 같은 13,083개의 메시지가 들어 있으며, 이는 다음 절에서 센다.
데이터 카드는 이 책이 의존하는 사실도 밝힌다. 이 파일들은 원본이 제공하는 학습/테스트 분할을 그대로 복사한 것이며 다시 나누지 않았고, 모든 팀이 두 파일에 모두 나타난다. 학습 파일로 학습하고 테스트 파일로 점수를 매긴 라우터는 이 책이 고른 분할이 아니라 원본이 따로 떼어 둔 메시지로 평가받는 셈이다.
라이선스는 CC BY 4.0이다. 데이터와 함께 있는 LICENSE 파일은 "Attribution 4.0 International"로 시작한다. 이 라이선스에 따라 데이터는 공유하고 변형할 수 있으며, 단 출처를 밝혀야 한다. 이 책은 라이선스 파일을 데이터 옆에 두고 데이터 카드에 인용 정보를 실으므로, 파일을 재사용하는 독자는 라이선스가 요구하는 것을 갖추게 된다.
메시지는 공개된 그대로 둔다. 어떤 예제도 메시지 본문을 출력하지 않고 어떤 장도 메시지를 인용하지 않으므로, 메시지의 내용은 지면에 나오지 않는다. 예제가 데이터에서 출력하는 모든 것은 개수 또는 비율이다.
작업 규칙: 라이선스 파일은 데이터 옆에 두고, 논문은 데이터 카드에서 인용하며, 메시지 본문이 아니라 개수만 출력한다. 실제 고객 메시지로 이루어진 데이터셋을 재사용한다면, 그 데이터에서 무엇이든 출력하기 전에 데이터 카드를 읽고, 데이터가 문서화된 곳에 출처를 밝힌다.
이 부분은 아직 번역되지 않았으므로 영어로 표시된다.
Dev, test and fixed samples
The two files of the source split are not enough by themselves. A router needs messages to tune on, messages to report on, and a small set that examples can run in seconds. Each one has to be fixed in advance, or a later result can be explained by a different sample rather than by a different model.
The dev split is carved from the training file, never from the test file. For each team, in the order of the categories file, the book draws about a tenth of that team's training messages with a fixed seed, and it commits the row numbers to examples/data/banking77/samples.json. The training messages that are not in dev are the ones the models train on. Because the draw is made team by team, each team's share of dev follows its share of the training file, and a team with few training messages keeps a small dev share instead of none.
The test split is the source's own held-out file. The book draws one stratified sample from it, 13 messages for each team, which gives 1001 messages in all. The sample is shuffled once, with the same generator as the dev draw, continuing after it, and the shuffled order is committed. Three prefixes of that order are named. The first 40 messages of the shuffled test sample are test_40, the first 200 are test_200, and the whole sample is test_1001. A prefix of a shuffled sample is a random draw, so test_40 does not read the teams in order.
The counts come from the committed samples, and the book quotes only those. The first of them, count-the-splits, also checks that every dev row number is unique and falls inside the training file, so every dev message is a training row, and that test_40 and test_200 are the first 40 and first 200 of test_1001.
The first thing to see is how big each split is and how unevenly the teams are spread across them. Counting needs no model, so the reader can run it first. It reads the training file, the test file and the dev sample, and counts each split:
1"""Count each BANKING77 split and its messages per team, and check the committed samples; no model runs.23The prose's point rests on the four "per label" lines for the test and training files.4"""56import os78os.environ["HF_HUB_OFFLINE"] = "1"9os.environ["TRANSFORMERS_OFFLINE"] = "1"1011import torch # noqa: E4021213torch.set_num_threads(2)1415import router_lib # noqa: E40216from collections import Counter # noqa: E4021718router_lib.setup_runtime()1920train = router_lib.read_rows("train")21test = router_lib.read_rows("test")22dev = router_lib.read_sample("dev") # dev row numbers index train.csv, never test.csv2324assert len(set(dev)) == len(dev), "dev indices repeat"25assert max(dev) < len(train), "dev indices fall outside train.csv"2627train_per_label = Counter(label for _, label in train)28test_per_label = Counter(label for _, label in test)2930test_1001 = router_lib.read_sample("test_1001") # committed order: prefixes are the first n of it31test_40 = router_lib.read_sample("test_40")32test_200 = router_lib.read_sample("test_200")33# test_40 and test_200 are prefixes of the shuffled order, not new draws34assert test_1001[:40] == test_40, "test_40 is not the first 40 of test_1001"35assert test_1001[:200] == test_200, "test_200 is not the first 200 of test_1001"36sample_per_label = Counter(test[i][1] for i in test_1001) # rows are (text, label index); [1] is the label3738train_counts = [train_per_label[i] for i in range(len(router_lib.LABELS))] # one entry per team, so a team with no rows counts 039test_counts = [test_per_label[i] for i in range(len(router_lib.LABELS))]40sample_counts = [sample_per_label[i] for i in range(len(router_lib.LABELS))]4142print(f"train rows: {len(train)}")43print(f"dev rows: {len(dev)}")44print(f"test rows: {len(test)}")45print(f"labels: {len(router_lib.LABELS)}")46print(f"test per label min: {min(test_counts)}")47print(f"test per label max: {max(test_counts)}")48print(f"train per label min: {min(train_counts)}")49print(f"train per label max: {max(train_counts)}")50print(f"test_1001 per label min: {min(sample_counts)}")51print(f"test_1001 per label max: {max(sample_counts)}")
python count-the-splits.pytrain rows: 10003
dev rows: 1003
test rows: 3080
labels: 77
test per label min: 40
test per label max: 40
train per label min: 35
train per label max: 187
test_1001 per label min: 13
test_1001 per label max: 13
The test file is even, with the same count for every team, and the training file is not: its teams run from 35 messages to 187. That spread is why the dev draw is made team by team rather than as one random tenth of the file. The test file's own fewest and most, 40 and 40, are equal.
The stratified sample is even as well, at 13 to 13 messages a team.
The even test file is a property of the source, and the book relies on it. Equal counts per team mean that the test split does not reward a router for being good at the largest team. A router that does well on a sample with uneven counts can look better than it is, because most of its score comes from the teams with the most messages.
Chapter 5 chooses the hand-off threshold on dev, and it records the choice in the adapter's manifest. The rule behind that choice is to tune on dev, never on test. The prompt, the model and the recipe are fixed before any test result is read, and none is changed because of one, and the test results are read once, to report them, on the fixed samples above.
In production the same rule holds for the inbox. Keep a dev set drawn from messages the inbox already has, and keep a test set that nobody reads while the router is being tuned. A test set that is read during tuning still looks like a test set, but it stops measuring anything new, and a router that is later measured on it will look better than it will be on the traffic that follows.
Working rule: Draw dev from training rows only, team by team, with a fixed seed, and commit its row numbers. Draw each test sample once, commit its order, and read it only to report. Choose every threshold, prompt and setting on dev. When dev is too small to decide, draw more dev messages from the training file, never from the test file.
세 가지 측정값과 각각의 분모
표본은 어떤 메시지를 채점할지 정하고, 측정값은 무엇을 셀지 정한다. 팀, 확신도, 이관 여부 표시를 반환하는 라우터는 세 가지 방식으로 채점할 수 있으며, 각 방식은 이를 운영하는 은행에 각기 다른 질문의 답을 준다.
정확도는 라우터가 고른 팀이 얼마나 자주 올바른 팀인지를 묻는다. 이관율은 사람이 메시지를 읽어야 하는 경우가 얼마나 잦은지를 묻는다. 이관되지 않은 메시지의 정확도는 라우터가 직접 맡은 메시지에서 얼마나 자주 맞히는지를 묻는다. 각 질문은 고유한 분모를 가지며, 이 책은 모든 출력 줄에서 세 측정값을 구분하여 적는다. 확신도는 라우터가 자신이 고른 팀에 부여하는 확률이고, 임계값은 그 값 미만이면 메시지를 이관하는 기준값이다. 두 용어는 1장에서 정의한 대로이다.
| 측정값 | 세는 대상 | 나누는 수 |
|---|---|---|
| 정확도 | 팀이 정답 팀과 같은 메시지 | 표본의 모든 메시지 |
| 이관율 | 확신도가 임계값 미만인 메시지 | 표본의 모든 메시지 |
| 이관되지 않은 메시지의 정확도 | 이관되지 않은 메시지 중 맞힌 메시지 | 이관되지 않은 메시지 |
표본의 메시지가 N개일 때 공식으로 나타내면 다음과 같다. 정확도 = 맞힌 수 / N, 이관율 = 이관된 수 / N, 이관되지 않은 메시지의 정확도 = 유지된 메시지 중 맞힌 수 / 유지된 수이며, 유지된 수는 N에서 이관된 수를 뺀 값이다.
두 가지 규칙이 후보들 사이에서 이 측정값을 비교할 수 있게 해 준다. 첫째, 이관된 메시지도 정확도의 분모에 포함하며, 팀이 틀렸다면 틀린 것으로 센다. 정확도만으로는 이관에 보상이 주어지지 않는다. 이관된 메시지는 그 팀이 맞을 때에만 정답으로 채점되기 때문이다. 이관되지 않은 메시지의 정확도는 그것만 보면 이관의 비용을 가린다. 사람에게 넘어간 메시지를 정확히 제외하기 때문이다. 이관율이 그 비용을 보여 준다. 세 수치는 함께 읽어야 하며, 그중 하나만 더 좋은 라우터는 아직 더 낫다는 것을 보인 것이 아니다.
둘째 규칙은 출력에 관한 것이다. 모든 비율은 백분율로 소수점 아래 한 자리까지 반올림하고, 해당 개수와 나란히 출력한다. 그러면 독자가 직접 나눗셈을 하여 비율을 확인할 수 있다. 개수가 없는 비율은 확인할 수 없고, 분모 없이 출력된 비율은 표본을 감추는 방식으로 인용될 수 있다.
세 번째 측정값의 분모가 0이면 그 측정값은 정의되지 않는다. 모든 메시지가 이관되어 유지된 메시지가 하나도 없을 때 그렇게 된다. 이 경우 이 책은 기준선 절에서 보이듯이 "not defined"를 출력하고 0은 출력하지 않는다. 유지된 메시지가 아예 없는데 0이라고 하면 유지된 메시지가 모두 틀렸다는 뜻이 되기 때문이다.
이 측정값들은 라벨을 채점한다. 이 장의 스크립트와 1장 및 4장의 측정은 채점을 위해서만 팀을 반환하며, 호출자에게는 아무것도 반환하지 않는다. 팀을 호출자에게 반환하는 라우터는 1장에서 소개한 이관 규칙을 거쳐 그렇게 하므로, 임계값 미만의 메시지는 팀이 아니라 사람에게 간다.
운영 환경에서는 이관율이 가장 먼저 변하는 측정값이다. 메시지의 구성은 계절에 따라, 제품 출시에 따라, 또는 한 종류의 문의가 받은편지함에 쏟아지게 하는 장애에 따라 달라진다. 정확도가 유지되는 라우터도 개발 분할이 예측한 것보다 훨씬 많은 메시지를 이관할 수 있으며, 이를 알아내는 유일한 방법은 라우터가 실제로 받는 트래픽에서 비율을 개수와 함께 출력하는 것이다.
작업 규칙: 세 측정값을 각각 개수와 분모와 함께 출력하고, 모든 비율은 소수점 아래 한 자리로 반올림한다. 이관되지 않은 메시지의 정확도는 반드시 이관율과 함께 보고하고, 단독으로 보고하지 않는다. 유지된 메시지가 없으면 0 대신 "not defined"를 출력한다.
기록된 답변으로 구한 기준선
측정값은 그것으로 무언가를 채점해 보기 전까지는 의미가 크지 않다. 기준선은 대역 모델이 test_1001에서 얻은 점수이며, 10장의 최종 비교는 이 표본을 사용한다. 이후의 장들은 이 표본의 접두 구간인 test_40과 test_200에서 후보를 채점한다. 두 구간은 같은 고정 표본의 처음 40개 메시지와 처음 200개 메시지이다. 각 접두 구간은 같은 기록으로 채점하므로, 그 구간의 기준선은 같은 메시지에 대한 같은 답변이다.
대역 모델은 test_1001의 메시지 각각에 한 번씩 답했다. 답변은 기록 파일 examples/data/recorded/standin-baseline/answers.jsonl에 저장되어 있으며, 각 답변은 팀 하나를 지정하고 그 로그 확률을 제공한다. 기록 옆에는 매니페스트가 있다. 매니페스트에는 기록을 만든 스크립트, 모델과 고정된 리비전, 프롬프트의 해시, 디코딩 설정과 시드, 답변 파일의 해시가 적혀 있다. 코드는 답변 파일을 한 줄도 읽기 전에 이 해시와 대조하므로, 파일이 바뀌면 점수가 바뀌는 대신 실행이 실패한다.
기록은 읽는 것이지 실행하는 것이 아니다. 기준선을 사용하는 모든 예제는 같은 답변을 읽으므로, 기록을 만든 런타임이 나중에 갱신되더라도 기준선은 실행마다 달라지지 않는다. 예제마다 모델을 호출하지 않고 기록을 쓰는 이유는 버전을 고정하는 이유와 같다. 기록은 특정 리비전의 모델 하나가 낸 답변을 고정하므로, 나중에 같은 예제를 실행하는 독자도 같은 숫자를 본다. 이 책은 호스팅 API를 호출하지 않는다. 호스팅 모델의 답변은 같은 방식으로 고정되지 않기 때문이다. 대역 모델은 누구나 실행할 수 있는 오픈 모델이며, 이 책이 그 답변에 이르는 경로는 기록뿐이다.
기준선은 상한도 아니다. 기준선은 같은 메시지에서 후보가 넘어야 하는 점수일 뿐이며, 그 자체로는 인계 상충 관계에 대해 아무것도 말해 주지 않는다. 정확도에서 기준선을 넘는 후보도 지원 담당자가 읽을 수 있는 양보다 많은 메시지를 인계할 수 있으므로, 기준선은 항상 세 가지 측정값과 함께 읽어야 하며 하나의 숫자로 읽어서는 안 된다.
임시 임계값에는 어떤 비용이 드는가? test_1001에서 세 가지 측정값으로 채점하면, 대역 모델이 0.5의 임계값에서 몇 개의 메시지를 인계하는지, 나머지에서는 얼마나 자주 맞히는지 알 수 있다. 대역 모델의 확신도는 제약된 답변에 대해 llama-cpp-python이 반환하는 확률이며, 이는 기록된 로그 확률에 exp를 취한 값이다. 이 임계값은 1장의 임시 값이므로 그 인계 비율은 이 책의 최종 값이 아니며, 실제 임계값은 5장에서 dev로 정한다. 이 예제는 모든 확신도보다 높은 임계값도 적용하는데, 이 경우 모든 메시지가 인계된다.
1"""Score the stand-in's recorded answers on test_1001 with the three measures, at chapter 1's placeholder threshold and at one above every confidence; no model runs. The point rests on the accuracy and hand-off lines, and the answers' hash is checked first.2"""34import hashlib, json, math, os56os.environ.update(HF_HUB_OFFLINE="1", TRANSFORMERS_OFFLINE="1")78import torch # noqa: E402910torch.set_num_threads(2)1112import router_lib # noqa: E4021314router_lib.setup_runtime()1516PLACEHOLDER = 0.5 # Chapter 5 chooses the real threshold on the dev split.17ABOVE_ALL = 1.01 # Confidence is at most 1.0, so this hands off every message.18RECORDED = router_lib.HERE / "data" / "recorded" / "standin-baseline"19manifest = json.loads((RECORDED / "manifest.json").read_text())20raw = (RECORDED / "answers.jsonl").read_bytes()21assert hashlib.sha256(raw).hexdigest() == manifest["output_sha256"]["answers.jsonl"]2223answers = {row["index"]: row for row in map(json.loads, raw.decode().splitlines())} # keyed by test.csv row, not by sample position24rows = router_lib.read_rows("test")25sample = router_lib.read_sample("test_1001")26golds = [rows[i][1] for i in sample] # in the sample's committed order, so position k of each list is one message27preds = [answers[i]["label"] for i in sample]28# Confidence is the probability llama-cpp-python returns for the constrained answer: exp of its log-probability.29confs = [math.exp(answers[i]["logprob"]) for i in sample]3031n = len(sample)32first = router_lib.metrics(preds, golds, confs, PLACEHOLDER) # one call returns the counts and rates of all three measures33high = router_lib.metrics(preds, golds, confs, ABOVE_ALL)34print(f"messages: {n}")35print(f"placeholder threshold: {PLACEHOLDER}")36print(f"accuracy: {first['correct']}/{n} ({first['accuracy']:.1%})")37print(f"handed off: {first['handed_off']}/{n} ({first['handoff_rate']:.1%})")38m = first["not_handed_off"]39print(f"accuracy on messages not handed off: {first['correct_not_handed_off']}/{m} ({first['accuracy_not_handed_off']:.1%})")40print(f"threshold above every confidence: {ABOVE_ALL}")41print(f"handed off at that threshold: {high['handed_off']}/{n} ({high['handoff_rate']:.1%})")42if high["accuracy_not_handed_off"] is None: # None means no message is kept, so the measure has no denominator43 print("accuracy on messages not handed off at that threshold: not defined (0 messages not handed off)")44else:45 print(f"accuracy on messages not handed off at that threshold: {high['correct_not_handed_off']}/{high['not_handed_off']}")
python baseline-measures.pymessages: 1001
placeholder threshold: 0.5
accuracy: 560/1001 (55.9%)
handed off: 30/1001 (3.0%)
accuracy on messages not handed off: 554/971 (57.1%)
threshold above every confidence: 1.01
handed off at that threshold: 1001/1001 (100.0%)
accuracy on messages not handed off at that threshold: not defined (0 messages not handed off)
임시 임계값에서 대역 모델은 560/1001 (55.9%)을 맞히고 30/1001 (3.0%)을 인계한다. 인계하지 않은 메시지에서의 정확도는 554/971 (57.1%)이다.
모든 확신도보다 높은 임계값에서 인계 비율은 1001/1001 (100.0%)이며, 따라서 인계하지 않은 메시지의 정확도는 not defined (0 messages not handed off)이다.
독자가 직접 쓰는 호스팅 모델은 다른 기준선이다. 같은 메시지에서도 점수가 다르게 나올 것이며, 이 책은 대역 모델의 숫자가 받은 편지함의 숫자라고 주장하지 않는다. 독자의 기준선은 test_1001에서 그 모델이 기록한 답변을 이 장의 세 가지 측정값으로 채점한 것이다. 중요한 비교는 독자의 후보와 그 기준선 사이에서, 같은 메시지를 놓고 같은 개수로 이루어진다.
다음 절에서는 대역 모델의 오답을 세고, 그 오답이 어느 팀들 사이에서 나타나는지 보인다. 오답 수는 기준선의 첫 번째 숫자이다.
작업 규칙: 기준선은 모든 후보의 접두 구간이 나오는 고정 표본인 test_1001에서 한 번만 기록한다. 모델의 고정된 리비전, 프롬프트의 해시, 디코딩 설정을 매니페스트에 저장하고, 답변 파일은 한 줄도 읽기 전에 해시와 대조한다. 각 후보는 test_40, test_200, test_1001 중 어느 것이든 같은 메시지에서 채점한 기준선과만 비교한다. 직접 쓰는 호스팅 모델이 기준선일 때는 그 답변도 같은 방식으로 기록하고, 그 점수가 대역 모델의 점수와 다르다는 점을 보고서에 밝힌다.
레이블이 충돌하는 곳
기준선의 집계는 대체 모델이 얼마나 자주 틀리는지를 알려 준다. 그러나 어느 팀들을 혼동하는지는 알려 주지 않으며, 지원 담당자가 조치를 취할 수 있는 것은 바로 그 혼동이다. 라우터가 혼동하는 팀 쌍에는 더 명확한 팀 설명, 해당 쌍을 위한 규칙, 또는 두 팀 중 한 팀의 학습용 메시지를 늘리는 조치가 필요할 수 있다. 이 중 어느 것도 전체 집계만으로는 알 수 없으므로, 이 책은 어느 팀이 서로 가깝다고 가정하지 않고 기록된 답에서 쌍을 읽는다.
틀린 답을 세려면 기록 자체가 필요하므로, 다음 예제는 기록을 읽고 매니페스트와 대조하며, 기록이 정확히 test_1001의 메시지만 담고 있는지 확인한 다음, 틀린 답의 수와 가장 자주 나타나는 정답-응답 쌍 세 개를 센다. 동률은 범주 파일에서 각 팀의 위치에 따라 정리하므로, 같은 쌍이 실행할 때마다 같은 순서로 출력된다.
1"""Count the stand-in's wrong answers, its three most frequent gold-to-answer pairs and the teams it never answers, on test_1001; no model runs. The point rests on the "pair" and "never answered" lines.2"""34import hashlib, json, os56os.environ.update(HF_HUB_OFFLINE="1", TRANSFORMERS_OFFLINE="1")78import torch # noqa: E402910torch.set_num_threads(2)1112import router_lib # noqa: E40213from collections import Counter # noqa: E4021415router_lib.setup_runtime()1617RECORDED = router_lib.HERE / "data" / "recorded" / "standin-baseline"18manifest = json.loads((RECORDED / "manifest.json").read_text())19raw = (RECORDED / "answers.jsonl").read_bytes()20assert hashlib.sha256(raw).hexdigest() == manifest["output_sha256"]["answers.jsonl"]2122records = [json.loads(line) for line in raw.decode().splitlines()]23sample = router_lib.read_sample("test_1001")24assert sorted(r["index"] for r in records) == sorted(sample), "recorded rows differ from test_1001"25assert all(router_lib.LABELS[r["label"]] == r["team"] for r in records), "label and team disagree"26test, LABELS = router_lib.read_rows("test"), router_lib.LABELS2728gold_totals = Counter(test[i][1] for i in sample)29answered = Counter(r["label"] for r in records)30pairs = Counter((test[r["index"]][1], r["label"]) for r in records if r["label"] != test[r["index"]][1]) # (gold, answer); [1] is the gold label31wrong = sum(pairs.values())32# Ties break on the lower gold label index, then the lower answer index.33top = sorted(pairs.items(), key=lambda kv: (-kv[1], kv[0][0], kv[0][1]))[:3]34never = sorted(team for k, team in enumerate(LABELS) if answered[k] == 0) # sorted by name, so uppercase names print first3536print(f"messages: {len(sample)}")37print(f"wrong answers: {wrong}")38print(f"wrong rate: {100 * wrong / len(sample):.1f}% ({wrong} of {len(sample)})")39for rank, ((gold, answer), count) in enumerate(top, start=1):40 print(f"pair {rank} count: {count}")41 print(f"pair {rank} gold: {LABELS[gold]}")42 print(f"pair {rank} answer: {LABELS[answer]}")43 print(f"pair {rank} of gold team: {count}/{gold_totals[gold]}")44print(f"teams never answered: {len(never)}")45for rank, team in enumerate(never, start=1):46 gold = LABELS.index(team)47 count, answer = max(((c, a) for (g, a), c in pairs.items() if g == gold), key=lambda ca: (ca[0], -ca[1])) # most frequent wrong answer; ties go to the lower answer index48 print(f"never answered {rank} team: {team}")49 print(f"never answered {rank} messages: {gold_totals[gold]}")50 print(f"never answered {rank} most often as: {LABELS[answer]}")51 print(f"never answered {rank} most often count: {count}")
python confusions-in-the-baseline.pymessages: 1001
wrong answers: 441
wrong rate: 44.1% (441 of 1001)
pair 1 count: 13
pair 1 gold: Refund_not_showing_up
pair 1 answer: request_refund
pair 1 of gold team: 13/13
pair 2 count: 13
pair 2 gold: failed_transfer
pair 2 answer: transfer_not_received_by_recipient
pair 2 of gold team: 13/13
pair 3 count: 12
pair 3 gold: card_arrival
pair 3 answer: card_delivery_estimate
pair 3 of gold team: 12/13
teams never answered: 4
never answered 1 team: Refund_not_showing_up
never answered 1 messages: 13
never answered 1 most often as: request_refund
never answered 1 most often count: 13
never answered 2 team: card_arrival
never answered 2 messages: 13
never answered 2 most often as: card_delivery_estimate
never answered 2 most often count: 12
never answered 3 team: failed_transfer
never answered 3 messages: 13
never answered 3 most often as: transfer_not_received_by_recipient
never answered 3 most often count: 13
never answered 4 team: order_physical_card
never answered 4 messages: 13
never answered 4 most often as: get_physical_card
never answered 4 most often count: 10
대체 모델은 44.1% (441 of 1001)에서 틀린다. 임계값을 적용하지 않으면 오류율은 1에서 정확도를 뺀 값이므로, 이 오답률과 기준선 절의 정확도를 더하면 100%가 된다.
가장 빈번한 세 쌍은 각각 정답 팀의 표본 메시지 전부 또는 거의 전부를 차지한다. 첫 번째 쌍은 13/13, 두 번째는 13/13, 세 번째는 12/13을 차지하므로, 앞의 두 쌍은 정답 팀의 모든 메시지를, 세 번째 쌍은 한 건을 뺀 모든 메시지를 차지한다. 팀 이름에서 각 쌍의 이유를 짐작할 수 있다. 첫 번째는 환불, 두 번째는 이체, 세 번째는 카드의 도착과 배송 예상 시점에 관한 것이다. 이는 이름을 읽고 내린 해석일 뿐이다. 이 장은 메시지를 읽지 않으며 메시지를 출력하는 예제도 없으므로, 이 쌍들은 살펴볼 이유일 뿐 메시지 내용에 관한 발견이 아니다.
대체 모델은 77개 팀 중 4개 팀을 한 번도 답으로 내놓지 않으므로, 정답 팀이 그중 하나인 모든 메시지는 틀린다. 그런 팀 중 하나인 card_arrival의 경우 가장 흔한 오답은 card_delivery_estimate이며, 이 오답이 해당 팀 메시지의 12을 차지한다.
또 다른 팀인 order_physical_card의 경우 가장 흔한 오답은 get_physical_card이며, 이 오답이 해당 팀 메시지의 10을 차지한다. 기록만으로는 이 팀들이 왜 한 번도 주어지지 않는지 알 수 없으므로, 이 목록은 살펴볼 이유일 뿐이다.
이 쌍들은 이 표본에서의 대체 모델을 설명할 뿐, 팀이나 받은편지함을 설명하지 않는다. 독자의 모델에는 그 모델 고유의 쌍이 있으므로, 독자는 자신의 기록된 답에서 쌍을 세어야 한다. 쌍을 어떻게 고칠지가 문제라면, dev와 test 절이 요구하는 대로 dev에서 수정안을 선택하고 검증해야 한다. test_1001의 쌍을 읽고 선택한 변경은 test 분할에서 조정된 것이며, 그 분할의 결과를 라우터의 측정값으로 보고할 수 없다.
운영 환경에서 한 팀의 인계나 불만이 늘면 먼저 이 집계를 반복한다. 받은편지함 자체의 기록된 답에서 쌍을 다시 세고, 각 쌍을 그 횟수와 함께 출력한 다음, 그 목록을 기준선의 목록과 비교한다. 목록이 달라졌다면 전체 비율이 변하지 않았더라도 라우터의 동작이 어디로 옮겨 갔는지 알 수 있다.
이 장의 결정을 요약하면 다음과 같다.
- dev는 고정된 시드로 학습 파일에서 팀별로 추출하며, 그 행 번호를 커밋한다.
- test 표본은 순서를 고정하며, 보고할 때에만 읽는다.
- 각 측정값은 그 횟수 및 분모와 함께 출력하며, 분모가 0이면 "정의되지 않음"으로 대신한다.
test_1001에 대한 대체 모델의 기록된 답이 기준선이며, 매니페스트로 검증한 파일에서 읽는다.
기준선의 세 수치를 함께 읽으면, 후보가 같은 메시지에서 넘어서야 할 점수가 된다. 3장은 기반 모델을 고르기 전에 test_40에서 라우터 프롬프트의 토큰을 센다. 5장은 그곳에 명시된 규칙에 따라 dev에서 인계 임계값을 정한다. 10장은 같은 test_1001 표본에서 라우터를 기준선과 비교한다.
작업 규칙: 모든 후보에 대해 같은 표본에서 틀린 답과 가장 빈번한 쌍을 세고, 각 쌍을 그 횟수와 함께 출력한다. 쌍은 어디를 살펴볼지 알려 주는 목록으로 읽는다. 첫 번째 쌍만이 아니라 가장 빈번한 세 쌍을 출력한다. 쌍 하나만 보면 과도하게 해석하기 쉽고, 목록은 오류가 몰려 있는지 흩어져 있는지 보여 주기 때문이다. 어떤 수정이든 test 분할을 다시 읽기 전에 dev 분할에서 검증한다.
이 판의 이 장
2026.11.9판예제 통과 2026년 11월 20이 장에서 3개 예제개 중 3개가 통과한다
영어판 2026.11.9판을 번역한 것이다.