{"version":2,"relationshipURLBase":"https://codingai-lec03.pages.dev/course/notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18.html","relationshipResolution":"Resolve relative relationship URLs against relationshipURLBase; complete records and absolute URLs are in blocks.","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18.html","markdown":"https://codingai-lec03.pages.dev/course/notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18.md","pages":[{"id":"reading-opening","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","unit":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","unitId":"notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18","chapter":"course","number":1}],"aliases":[{"oldId":"b-3626839797c696d3a26d09c7","targetId":"b-3626839797c696d3a26d09c7","page":"reading-opening","operation":"move","beforeSHA256":"c566f7c3e33c01fd834bb24879f8335a3d1f33cd6fe14a13564a5e39fb396afe","afterSHA256":"c566f7c3e33c01fd834bb24879f8335a3d1f33cd6fe14a13564a5e39fb396afe","reason":"Same source body in authored semantic page"},{"oldId":"b-5e5c2d29997541afdc4a7fe6","targetId":"b-5e5c2d29997541afdc4a7fe6","page":"reading-opening","operation":"move","beforeSHA256":"de24482cc9132827812ab17c72a8c2c4bb43151414ef5d617c7d942d41c9be5b","afterSHA256":"de24482cc9132827812ab17c72a8c2c4bb43151414ef5d617c7d942d41c9be5b","reason":"Same source body in authored semantic page"},{"oldId":"b-274a46ecc72a6ea1af64a760","targetId":"b-274a46ecc72a6ea1af64a760","page":"reading-opening","operation":"move","beforeSHA256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","afterSHA256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","reason":"Same source body in authored semantic page"},{"oldId":"b-70193352516c59f7d1d5a884","targetId":"b-70193352516c59f7d1d5a884","page":"reading-opening","operation":"move","beforeSHA256":"acab63401590ec93c084e0b85d6377f8d181ccfd7b8a41fccc3b4e91a788f49b","afterSHA256":"acab63401590ec93c084e0b85d6377f8d181ccfd7b8a41fccc3b4e91a788f49b","reason":"Same source body in authored semantic page"},{"oldId":"b-cb2b843f4756caed5e4de320","targetId":"b-cb2b843f4756caed5e4de320","page":"reading-opening","operation":"move","beforeSHA256":"27b60dcda94fba59f6af2ff7c1b50efba3c5b073354ca4122c0762fb8a70a6ef","afterSHA256":"27b60dcda94fba59f6af2ff7c1b50efba3c5b073354ca4122c0762fb8a70a6ef","reason":"Same source body in authored semantic page"}],"blocks":[{"id":"b-3626839797c696d3a26d09c7","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18.html#b-3626839797c696d3a26d09c7","content":"[LAB 19 · 新域：捷径反转与少标签适配](/course/notebooks/c20ef6a65d184331b1b52bf351077504.html)","sha256":"c566f7c3e33c01fd834bb24879f8335a3d1f33cd6fe14a13564a5e39fb396afe","chapter":{"id":"course","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码"},"unit":{"id":"notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码"},"page":{"id":"reading-opening","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","number":1},"sectionTitle":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","currentQuestion":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":null,"nextBlock":"b-5e5c2d29997541afdc4a7fe6","prerequisites":[],"relatedBlocks":[]},{"id":"b-5e5c2d29997541afdc4a7fe6","type":"h1","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18.html#b-5e5c2d29997541afdc4a7fe6","content":"# LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","sha256":"de24482cc9132827812ab17c72a8c2c4bb43151414ef5d617c7d942d41c9be5b","chapter":{"id":"course","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码"},"unit":{"id":"notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码"},"page":{"id":"reading-opening","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","number":1},"sectionTitle":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","currentQuestion":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-3626839797c696d3a26d09c7","nextBlock":"b-274a46ecc72a6ea1af64a760","prerequisites":[{"id":"b-3626839797c696d3a26d09c7","url":"#b-3626839797c696d3a26d09c7","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-274a46ecc72a6ea1af64a760","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18.html#b-274a46ecc72a6ea1af64a760","content":"按问题继续","sha256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","chapter":{"id":"course","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码"},"unit":{"id":"notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码"},"page":{"id":"reading-opening","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","number":1},"sectionTitle":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","currentQuestion":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-5e5c2d29997541afdc4a7fe6","nextBlock":"b-70193352516c59f7d1d5a884","prerequisites":[{"id":"b-5e5c2d29997541afdc4a7fe6","url":"#b-5e5c2d29997541afdc4a7fe6","role":"section-title"},{"id":"b-3626839797c696d3a26d09c7","url":"#b-3626839797c696d3a26d09c7","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-70193352516c59f7d1d5a884","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18.html#b-70193352516c59f7d1d5a884","content":"源域捷径、目标域反转、少标签适配与同预算scratch","sha256":"acab63401590ec93c084e0b85d6377f8d181ccfd7b8a41fccc3b4e91a788f49b","chapter":{"id":"course","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码"},"unit":{"id":"notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码"},"page":{"id":"reading-opening","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","number":1},"sectionTitle":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","currentQuestion":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-274a46ecc72a6ea1af64a760","nextBlock":"b-cb2b843f4756caed5e4de320","prerequisites":[{"id":"b-5e5c2d29997541afdc4a7fe6","url":"#b-5e5c2d29997541afdc4a7fe6","role":"section-title"},{"id":"b-3626839797c696d3a26d09c7","url":"#b-3626839797c696d3a26d09c7","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-cb2b843f4756caed5e4de320","type":"pre","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18.html#b-cb2b843f4756caed5e4de320","content":"```\n# Writable ephemeral workspace for detached readonly cloud runs.\nimport os, tempfile\nos.chdir(tempfile.mkdtemp(prefix='lec03_lab22_'))\n\nimport numpy as np\ndef data(seed,n,environment):\n    r=np.random.default_rng(seed); y=r.integers(0,2,n); sign=2*y-1\n    x=np.c_[sign+r.normal(0,1.,n),environment*sign+r.normal(0,.15,n),np.ones(n)]\n    return x,y\ndef train(x,y,w,steps,lr=.1,l2=.01):\n    w=w.copy()\n    for _ in range(steps):\n        p=1/(1+np.exp(-np.clip(x@w,-30,30))); w-=lr*(x.T@(p-y)/len(y)+l2*np.r_[w[:2],0])\n    return w\ndef acc(w,d): x,y=d; return float(((x@w>=0)==y).mean())\nsource=data(220,512,1); source_test=data(221,512,1); adapt=data(222,32,-1); target_test=data(223,512,-1)\nw=train(*source,np.zeros(3),500); adapted=train(*adapt,w,150); scratch=train(*adapt,np.zeros(3),150)\nprint('source-trained weights stable/spurious/bias',w.round(3).tolist())\nresult={'source_holdout':acc(w,source_test),'target_zero_shot':acc(w,target_test),'target_adapt32':acc(adapted,target_test),'target_scratch32':acc(scratch,target_test)}\nprint(result); print('adaptation gain over zero-shot',round(result['target_adapt32']-result['target_zero_shot'],4),'transfer advantage vs scratch',round(result['target_adapt32']-result['target_scratch32'],4))\nprint('test seeds 221/223 never used by optimizer; adaptation seed222 only')\n```","sha256":"27b60dcda94fba59f6af2ff7c1b50efba3c5b073354ca4122c0762fb8a70a6ef","chapter":{"id":"course","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码"},"unit":{"id":"notebook-blocks/57aeca83ffea4a7c9f6d46529f58fa18","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码"},"page":{"id":"reading-opening","title":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","number":1},"sectionTitle":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","currentQuestion":"LAB 19 · 新域：捷径反转与少标签适配 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-70193352516c59f7d1d5a884","nextBlock":null,"prerequisites":[{"id":"b-5e5c2d29997541afdc4a7fe6","url":"#b-5e5c2d29997541afdc4a7fe6","role":"section-title"},{"id":"b-3626839797c696d3a26d09c7","url":"#b-3626839797c696d3a26d09c7","role":"problem-context"}],"relatedBlocks":[]}]}
