[LAB 15 · 语言指代小练习:目标、参照与关系](/course/notebooks/7dc83786d067465aa76264475db2c62d.html) # 1. 让错误暴露,而不是把错误当正确示范 · 实现代码 [独立阅读](/course/notebook-blocks/56ecbeb770fc4539a3f66c6cf658820a.html) 按问题继续 RGB规则提框、错误关键词基线、目标/参照/关系与干预 展开完整实现代码 ``` # Detached readonly runs write only to an isolated ephemeral directory. import os, tempfile _LAB_WORKDIR = tempfile.mkdtemp(prefix="lecture03-lab15-") os.chdir(_LAB_WORKDIR) print("ephemeral workdir:", _LAB_WORKDIR) from pathlib import Path import json, hashlib, platform, sys from datetime import datetime, timezone import numpy as np from PIL import Image, ImageDraw import matplotlib if 'get_ipython' not in globals(): matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.patches import Rectangle OUT=Path('outputs/lab15');OUT.mkdir(parents=True,exist_ok=True) PALETTE={'red':(214,55,55),'blue':(40,105,218),'brown':(146,95,53)} boxes=['left-red','right-blue','book'] def keyword_match(phrase): if 'red' in phrase and 'left of' not in phrase:return boxes[0] if 'blue' in phrase:return boxes[1] return boxes[0] phrases=['red cup','blue cup','cup left of blue cup'] for p in phrases:print('historical keyword baseline:',p,'->',keyword_match(p)) assert keyword_match(phrases[-1])=='right-blue' # This is the demonstrated ERROR. ```