{"version":2,"relationshipURLBase":"https://codingai-lec03.pages.dev/course/notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e.html","relationshipResolution":"Resolve relative relationship URLs against relationshipURLBase; complete records and absolute URLs are in blocks.","title":"4. 逐问题读结果，别只看总准确率 · 实现代码","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e.html","markdown":"https://codingai-lec03.pages.dev/course/notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e.md","pages":[{"id":"reading-opening","title":"4. 逐问题读结果，别只看总准确率 · 实现代码","unit":"4. 逐问题读结果，别只看总准确率 · 实现代码","unitId":"notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e","chapter":"course","number":1}],"aliases":[{"oldId":"b-42d451b2a820742915903d9d","targetId":"b-42d451b2a820742915903d9d","page":"reading-opening","operation":"move","beforeSHA256":"926fc2429c1a5c837765e5152b3b61fda31c10537785a439d49dec46e82a8536","afterSHA256":"926fc2429c1a5c837765e5152b3b61fda31c10537785a439d49dec46e82a8536","reason":"Same source body in authored semantic page"},{"oldId":"b-f6a8e5a1d8ef9ff7be4f589b","targetId":"b-f6a8e5a1d8ef9ff7be4f589b","page":"reading-opening","operation":"move","beforeSHA256":"a94d1a04e3587ffd4792f50c7ab89eecd3b48fed97f28353836bf5d24a9bb20e","afterSHA256":"a94d1a04e3587ffd4792f50c7ab89eecd3b48fed97f28353836bf5d24a9bb20e","reason":"Same source body in authored semantic page"},{"oldId":"b-3f60dd33ba2a203195c73977","targetId":"b-3f60dd33ba2a203195c73977","page":"reading-opening","operation":"move","beforeSHA256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","afterSHA256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","reason":"Same source body in authored semantic page"},{"oldId":"b-32428dfd1db60b3ea16d5cd1","targetId":"b-32428dfd1db60b3ea16d5cd1","page":"reading-opening","operation":"move","beforeSHA256":"5790b0afb52508f0174b1bc581f7847035a51c5c2a46e5c821bcd9d5d61bcbb0","afterSHA256":"5790b0afb52508f0174b1bc581f7847035a51c5c2a46e5c821bcd9d5d61bcbb0","reason":"Same source body in authored semantic page"},{"oldId":"b-1bfc2e3ef97f8beeaf41b793","targetId":"b-1bfc2e3ef97f8beeaf41b793","page":"reading-opening","operation":"move","beforeSHA256":"8e18a29d7fa6b2a327c610746be654c9657a1db37fbbcdf87d48868eec182c2d","afterSHA256":"8e18a29d7fa6b2a327c610746be654c9657a1db37fbbcdf87d48868eec182c2d","reason":"Same source body in authored semantic page"}],"blocks":[{"id":"b-42d451b2a820742915903d9d","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e.html#b-42d451b2a820742915903d9d","content":"[LAB 14 · 图像问答：视觉条件与问题先验](/course/notebooks/11d9f74871544a77b42024a9fe06b81a.html)","sha256":"926fc2429c1a5c837765e5152b3b61fda31c10537785a439d49dec46e82a8536","chapter":{"id":"course","title":"4. 逐问题读结果，别只看总准确率 · 实现代码"},"unit":{"id":"notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e","title":"4. 逐问题读结果，别只看总准确率 · 实现代码"},"page":{"id":"reading-opening","title":"4. 逐问题读结果，别只看总准确率 · 实现代码","number":1},"sectionTitle":"4. 逐问题读结果，别只看总准确率 · 实现代码","currentQuestion":"4. 逐问题读结果，别只看总准确率 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":null,"nextBlock":"b-f6a8e5a1d8ef9ff7be4f589b","prerequisites":[],"relatedBlocks":[]},{"id":"b-f6a8e5a1d8ef9ff7be4f589b","type":"h1","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e.html#b-f6a8e5a1d8ef9ff7be4f589b","content":"# 4. 逐问题读结果，别只看总准确率 · 实现代码","sha256":"a94d1a04e3587ffd4792f50c7ab89eecd3b48fed97f28353836bf5d24a9bb20e","chapter":{"id":"course","title":"4. 逐问题读结果，别只看总准确率 · 实现代码"},"unit":{"id":"notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e","title":"4. 逐问题读结果，别只看总准确率 · 实现代码"},"page":{"id":"reading-opening","title":"4. 逐问题读结果，别只看总准确率 · 实现代码","number":1},"sectionTitle":"4. 逐问题读结果，别只看总准确率 · 实现代码","currentQuestion":"4. 逐问题读结果，别只看总准确率 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-42d451b2a820742915903d9d","nextBlock":"b-3f60dd33ba2a203195c73977","prerequisites":[{"id":"b-42d451b2a820742915903d9d","url":"#b-42d451b2a820742915903d9d","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-3f60dd33ba2a203195c73977","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e.html#b-3f60dd33ba2a203195c73977","content":"按问题继续","sha256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","chapter":{"id":"course","title":"4. 逐问题读结果，别只看总准确率 · 实现代码"},"unit":{"id":"notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e","title":"4. 逐问题读结果，别只看总准确率 · 实现代码"},"page":{"id":"reading-opening","title":"4. 逐问题读结果，别只看总准确率 · 实现代码","number":1},"sectionTitle":"4. 逐问题读结果，别只看总准确率 · 实现代码","currentQuestion":"4. 逐问题读结果，别只看总准确率 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-f6a8e5a1d8ef9ff7be4f589b","nextBlock":"b-32428dfd1db60b3ea16d5cd1","prerequisites":[{"id":"b-f6a8e5a1d8ef9ff7be4f589b","url":"#b-f6a8e5a1d8ef9ff7be4f589b","role":"section-title"},{"id":"b-42d451b2a820742915903d9d","url":"#b-42d451b2a820742915903d9d","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-32428dfd1db60b3ea16d5cd1","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e.html#b-32428dfd1db60b3ea16d5cd1","content":"RGB+问题输入、question-only对照、同图换问与同问换图","sha256":"5790b0afb52508f0174b1bc581f7847035a51c5c2a46e5c821bcd9d5d61bcbb0","chapter":{"id":"course","title":"4. 逐问题读结果，别只看总准确率 · 实现代码"},"unit":{"id":"notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e","title":"4. 逐问题读结果，别只看总准确率 · 实现代码"},"page":{"id":"reading-opening","title":"4. 逐问题读结果，别只看总准确率 · 实现代码","number":1},"sectionTitle":"4. 逐问题读结果，别只看总准确率 · 实现代码","currentQuestion":"4. 逐问题读结果，别只看总准确率 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-3f60dd33ba2a203195c73977","nextBlock":"b-1bfc2e3ef97f8beeaf41b793","prerequisites":[{"id":"b-f6a8e5a1d8ef9ff7be4f589b","url":"#b-f6a8e5a1d8ef9ff7be4f589b","role":"section-title"},{"id":"b-42d451b2a820742915903d9d","url":"#b-42d451b2a820742915903d9d","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-1bfc2e3ef97f8beeaf41b793","type":"pre","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e.html#b-1bfc2e3ef97f8beeaf41b793","content":"```\n@torch.no_grad()\ndef answer_all(net,images):\n    net.eval()\n    return torch.stack([net(images,torch.full((len(images),),q)).argmax(-1) for q in range(3)],1)\nnormal=answer_all(full,Xte);qo=answer_all(question_only,Xte)\nzero=answer_all(full,torch.zeros_like(Xte));shuffled=answer_all(full,Xte[torch.roll(torch.arange(len(Xte)),1)])\ntrain_full=answer_all(full,Xtr);train_qo=answer_all(question_only,Xtr)\ndef score(p,y):return {'overall':float(p.eq(y).float().mean()),**{QUESTIONS[q]:float(p[:,q].eq(y[:,q]).float().mean()) for q in range(3)}}\nmetrics={'test_image_question':score(normal,Yte),'test_question_only':score(qo,Yte),'test_zero_pixels':score(zero,Yte),'test_shuffled_pixels':score(shuffled,Yte),'train_image_question':score(train_full,Ytr),'train_question_only':score(train_qo,Ytr)}\nprint(json.dumps(metrics,indent=2))\n# Recreate two images with matched nuisance randomness, only left color differs.\ncontrol_specs=[(2,'red','square'),(2,'blue','square'),(1,'green','circle')]\ncontrols_x=torch.tensor(np.stack([draw_scene(*s,np.random.default_rng(444)) for s in control_specs])).permute(0,3,1,2)\ncontrols_pred=answer_all(full,controls_x);controls_qo=answer_all(question_only,controls_x)\ncontrols=[{'image_condition':list(s),'question':q,'image_question':ANSWERS[int(controls_pred[i,j])],'question_only':ANSWERS[int(controls_qo[i,j])]} for i,s in enumerate(control_specs) for j,q in enumerate(QUESTIONS)]\nprint('same image / changed question and same question / changed image:')\nfor row in controls:print(row)\n```","sha256":"8e18a29d7fa6b2a327c610746be654c9657a1db37fbbcdf87d48868eec182c2d","chapter":{"id":"course","title":"4. 逐问题读结果，别只看总准确率 · 实现代码"},"unit":{"id":"notebook-blocks/3ce456f62e2a4489be2b14a56d1b568e","title":"4. 逐问题读结果，别只看总准确率 · 实现代码"},"page":{"id":"reading-opening","title":"4. 逐问题读结果，别只看总准确率 · 实现代码","number":1},"sectionTitle":"4. 逐问题读结果，别只看总准确率 · 实现代码","currentQuestion":"4. 逐问题读结果，别只看总准确率 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-32428dfd1db60b3ea16d5cd1","nextBlock":null,"prerequisites":[{"id":"b-f6a8e5a1d8ef9ff7be4f589b","url":"#b-f6a8e5a1d8ef9ff7be4f589b","role":"section-title"},{"id":"b-42d451b2a820742915903d9d","url":"#b-42d451b2a820742915903d9d","role":"problem-context"}],"relatedBlocks":[]}]}
