复合评分
把一个复杂判断拆分为原子化的评分,再与你在代码中掌控的权重组合。
我们常常想同时基于多项标准对一组条目排序。复合评分是思考这个问题的一种简单方式:把判断拆分成独立的维度,分别对每个维度评分,再用你在代码中掌控的权重组合它们。
示例:简历筛选
假设你正在处理工程岗位的简历。你想基于多项标准对候选人排序,并最终选出前 X 名候选人进入进一步审核。
%%{init: {"fontFamily": "Inter, sans-serif", "flowchart": {"rankSpacing": 35, "wrappingWidth": 300, "subGraphTitleMargin": {"top": 12, "bottom": 36}}}}%%
flowchart LR
resume["candidate resume"]
subgraph req["TypeSafe evaluates questions<br/>in parallel"]
direction TB
py["<b>Score:</b> Python depth"]
lead["<b>Score:</b> team leadership"]
arch["<b>Score:</b> system design"]
general["<b>Score:</b> generalist"]
%% Invisible links stack the questions; they are answered in parallel.
py ~~~ lead ~~~ arch ~~~ general
end
resume -- "one request<br/>resume + 4 questions" --> req
req -- "one response<br/>4 score answers" --> normalize["<b>normalize scores to 0–1</b><br/>divide each by 4 in your code"]
normalize --> ic["<b>senior IC weights</b><br/>40% Python + 10% leadership<br/>40% design + 10% generalist"]
normalize --> em["<b>engineering manager weights</b><br/>15% Python + 40% leadership<br/>20% design + 25% generalist"]
ic --> rank["rank candidates<br/>for each role"]
em --> rank%%{init: {"fontFamily": "Inter, sans-serif", "flowchart": {"rankSpacing": 35, "wrappingWidth": 300, "subGraphTitleMargin": {"top": 12, "bottom": 36}}}}%%
flowchart LR
resume["candidate resume"]
subgraph req["TypeSafe evaluates questions<br/>in parallel"]
direction TB
py["<b>Score:</b> Python depth"]
lead["<b>Score:</b> team leadership"]
arch["<b>Score:</b> system design"]
general["<b>Score:</b> generalist"]
%% Invisible links stack the questions; they are answered in parallel.
py ~~~ lead ~~~ arch ~~~ general
end
resume -- "one request<br/>resume + 4 questions" --> req
req -- "one response<br/>4 score answers" --> normalize["<b>normalize scores to 0–1</b><br/>divide each by 4 in your code"]
normalize --> ic["<b>senior IC weights</b><br/>40% Python + 10% leadership<br/>40% design + 10% generalist"]
normalize --> em["<b>engineering manager weights</b><br/>15% Python + 40% leadership<br/>20% design + 25% generalist"]
ic --> rank["rank candidates<br/>for each role"]
em --> rank
第 1 步:独立地对每个维度评分
questions
{
"questions": {
"python_depth": {
"type": "score",
"instructions": "How much depth of python experience does this candidate have, based on the supplied resume?",
"criteria": [
"No Python experience mentioned",
"Mentioned but no detail",
"Used in projects, some specifics",
"Primary language, multiple projects",
"Deep expertise: architecture, performance, libraries"
]
},
"team_leadership": {
"type": "score",
"instructions": "How much experience does this candidate have managing or leading engineering teams?",
"criteria": [
"No management experience mentioned",
"Informal mentorship or tech lead role",
"Led a small team or project",
"Managed a team with direct reports",
"Managed multiple teams or an engineering org"
]
},
"system_design": {
"type": "score",
"instructions": "How much experience does this candidate have designing large-scale or distributed systems?",
"criteria": [
"No architecture work mentioned",
"Contributed to design discussions",
"Designed components of a larger system",
"Owned architecture of a significant system",
"Designed systems at scale across multiple domains"
]
},
"generalist": {
"type": "score",
"instructions": "How much evidence is there that this candidate picks up unfamiliar tools, roles, or domains outside their core specialty?",
"criteria": [
"Only one domain or role mentioned",
"Some variety but within a narrow field",
"Worked across a few different areas or tech stacks",
"Regularly moved between domains, wore many hats",
"Track record of ramping up in unfamiliar areas and delivering"
]
}
}
}第 2 步:用权重组合
每个维度被归一化到 0–1 并加权。权重让你能够轻松调整每个维度的相对重要性,而不会丢失单个评分的任何细节。
scoring.py
py = response.answers["python_depth"].score / 4
lead = response.answers["team_leadership"].score / 4
arch = response.answers["system_design"].score / 4
general = response.answers["generalist"].score / 4
# Senior IC
ic_score = (0.40 * py) + (0.10 * lead) + (0.40 * arch) + (0.10 * general)
# Engineering Manager
em_score = (0.15 * py) + (0.40 * lead) + (0.20 * arch) + (0.25 * general)这让你能够基于综合得分对候选人排序。但更重要的是,它让你清楚地看到最终得分究竟是如何计算出来的。如果排名最高的候选人不符合你的预期,你可以调整权重来找到恰当的平衡。
🔬 交互实验室
改一改 state 或问题再运行,观察概率与置信度如何变化。默认运行本地演示(离线可用、
非真实模型输出,仅演示答案形状);填入 API Key 可尝试直连真实 API(官方暂未开放跨域时会给出一键复制的本地调用代码);也可一键到官方 Playground 在线试跑。
配套讲解见本页上方内容与「深入学习」素材。
Key 仅保存在本浏览器(localStorage),不会上传到本站。留空 = 本地演示。
📓 内嵌教程 · 第 3 章 · 架构模式实验笔记本(四种模式全套可运行实验)
像运行 notebook 一样逐步学习:点「下一步」逐格展开——代码格会先出现再"运行"出结果。内容来自教程仓库配套笔记本。
📖 想看带真实 API Key 的完整运行与源文件:
第 3 章 · 架构模式实验笔记本(四种模式全套可运行实验)(GitHub)↗