Eric-Yyvuw commited on
Commit
3ddadd8
·
verified ·
1 Parent(s): a4aff25

sync: 2026-10-28 04:40 Dublin

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
dw_lb/d0.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys; sys.path.insert(0,'/workspace/huawei/dw_lb')
2
+ from lib import *
3
+ import dwcommon as D, pickle, time
4
+ t=time.time(); d=D.Data(); print('data',time.time()-t, d.NE, d.NU, d.NI)
5
+ ec=d.Y.max(1) # event has click
6
+ print('event click rate',ec.mean())
7
+ # user heterogeneity: split-half reliability
8
+ u=d.EU; order=np.lexsort((d.ETS,u));
9
+ us=u[order]; bounds=np.r_[0,np.flatnonzero(np.diff(us))+1,len(us)]
10
+ n=np.diff(bounds); print('events/user mean',n.mean(),'median',np.median(n), 'min',n.min(),'max',n.max())
11
+ ecs=ec[order]; e1=[];e2=[];ns=[]
12
+ for a,b in zip(bounds[:-1],bounds[1:]):
13
+ if b-a>=8:
14
+ h=(b-a)//2; e1.append(ecs[a:a+h].mean()); e2.append(ecs[b-h:b].mean()); ns.append(h)
15
+ e1=np.array(e1);e2=np.array(e2); print('users>=8 ev',len(e1),'corr halves',np.corrcoef(e1,e2)[0,1],'mean ns',np.mean(ns))
16
+ # expected corr under homogeneity is 0; also compare to simulated binomial var
17
+ print('var of half-rate',e1.var(),'binomial var',np.mean(ec.mean()*(1-ec.mean())/np.array(ns)))
18
+ # by hour of day, by time since last event
19
+ ts=d.ETS; hr=((ts%DAY)//3600)
20
+ print('click rate by hour',[round(ec[hr==h].mean(),3) for h in range(24)])
21
+ gap=np.full(len(ts),np.nan); o=order; g=np.diff(ts[o]); same=(us[1:]==us[:-1]); tmp=np.full(len(o),np.nan); tmp[1:]=np.where(same,g,np.nan); gap[o]=tmp
22
+ for lo,hi in [(0,1800),(1800,3600*3),(3*3600,6*3600),(6*3600,12*3600),(12*3600,24*3600),(24*3600,48*3600),(48*3600,1e9)]:
23
+ m=(gap>=lo)&(gap<hi); print('gap',lo/3600,hi/3600,m.sum(),round(ec[m].mean(),4))
dw_lb/feat_prop.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Priority 3: user click-propensity / activity features for val events (leak-safe: snapshot = events ts<C, + the event's own history)."""
2
+ import sys; sys.path.insert(0,'/workspace/huawei/dw_lb')
3
+ from lib import *
4
+ import dwcommon as D
5
+ def user_event_table(d):
6
+ return np.lexsort((d.ETS,d.EU))
7
+ def build(d,c,F):
8
+ C=Jd(c); v=d.val(c); e=v['e'][::10]; nE=len(e)
9
+ ec=d.Y.max(1).astype(np.float32); ts=d.ETS; u=d.EU
10
+ nX=int(np.searchsorted(ts,C)) # events before C
11
+ # per-user aggregates over events with ts<C
12
+ n_ev=np.bincount(u[:nX],minlength=d.NU).astype(np.float32); n_cl=np.bincount(u[:nX],weights=ec[:nX],minlength=d.NU)
13
+ first=np.full(d.NU,np.inf); np.minimum.at(first,u[:nX],ts[:nX]); last=np.full(d.NU,-np.inf); np.maximum.at(last,u[:nX],ts[:nX])
14
+ # last-3 events click rate before C, trailing no-click streak
15
+ o=np.lexsort((ts[:nX],u[:nX])); us=u[:nX][o]; ecs=ec[:nX][o]; tss=ts[:nX][o]
16
+ b=np.r_[0,np.flatnonzero(np.diff(us))+1,len(us)]
17
+ l3=np.full(d.NU,np.nan,np.float32); streak=np.zeros(d.NU,np.float32); gapm=np.full(d.NU,np.nan,np.float32); gapsd=np.full(d.NU,np.nan,np.float32)
18
+ for a,bb in zip(b[:-1],b[1:]):
19
+ uu=us[a]; seg=ecs[a:bb]; l3[uu]=seg[-3:].mean(); r=0
20
+ for x in seg[::-1]:
21
+ if x==0: r+=1
22
+ else: break
23
+ streak[uu]=r
24
+ if bb-a>=2: g=np.diff(tss[a:bb]); gapm[uu]=g.mean(); gapsd[uu]=g.std()
25
+ ue=u[e]; tev=ts[e]
26
+ shrink=(n_cl[ue]+0.63*3)/(n_ev[ue]+3)
27
+ days=(C-J20)/DAY
28
+ col={}
29
+ col['p_nev']=n_ev[ue]; col['p_evrate']=n_ev[ue]/days; col['p_ctr']=np.where(n_ev[ue]>0,n_cl[ue]/np.maximum(n_ev[ue],1),np.nan); col['p_ctr_s']=shrink
30
+ col['p_l3']=l3[ue]; col['p_streak']=streak[ue]; col['p_gapm']=gapm[ue]/3600; col['p_gapsd']=gapsd[ue]/3600
31
+ col['p_since_ev']=np.where(np.isfinite(last[ue]),(tev-last[ue])/3600,np.nan); col['p_since_first']=np.where(np.isfinite(first[ue]),(tev-first[ue])/3600,np.nan)
32
+ col['p_gap_ratio']=col['p_since_ev']/(col['p_gapm']+1)
33
+ # own history
34
+ hl=d.Hlen[e]; col['h_len']=hl.astype(np.float32)
35
+ hmin=np.full(nE,np.nan); hmax=np.full(nE,np.nan); hgm=np.full(nE,np.nan); hgsd=np.full(nE,np.nan); hglast=np.full(nE,np.nan); h1=np.zeros(nE); h3=np.zeros(nE); h7=np.zeros(nE); hwarm=np.zeros(nE); hwin=np.zeros(nE); huniq=np.zeros(nE)
36
+ for i,ee in enumerate(e):
37
+ a,bb=d.OFF[ee],d.OFF[ee+1]
38
+ if bb-a==0: continue
39
+ t=d.HT[a:bb]; it=d.HI[a:bb]; tt=tev[i]
40
+ hmin[i]=(tt-t[0])/3600; hmax[i]=(tt-t[-1])/3600; huniq[i]=len(set(it.tolist()))
41
+ h1[i]=(t>tt-DAY).sum(); h3[i]=(t>tt-3*DAY).sum(); h7[i]=(t>tt-7*DAY).sum(); hwarm[i]=(t<J20).sum(); hwin[i]=(t>=J20).sum()
42
+ if bb-a>=2: g=np.diff(t); hgm[i]=g.mean()/3600; hgsd[i]=g.std()/3600; hglast[i]=g[-1]/3600
43
+ col.update(h_span=hmin,h_since_last=hmax,h_gap_mean=hgm,h_gap_sd=hgsd,h_gap_last=hglast,h_1d=h1,h_3d=h3,h_7d=h7,h_warm=hwarm,h_win=hwin,h_uniq=huniq,h_uniq_ratio=huniq/np.maximum(hl,1))
44
+ col['h_rate_day']=np.where(hl>=2,(hl-1)/np.maximum(hmin-hmax,1e-3)*24,np.nan)
45
+ # clicks per event: window clicks (in train, ts<C) / events
46
+ col['p_clk_per_ev']=n_cl[ue]/np.maximum(n_ev[ue],1)
47
+ # history density per unit time vs event rate: implied clicks per event = click_rate/event_rate
48
+ erate=np.where(n_ev[ue]>0,n_ev[ue]/np.maximum((C-J20)/3600/24,1e-3),np.nan) # events per day
49
+ col['implied_cpe']=col['h_rate_day']/(erate+0.5)
50
+ col['gap_over_hgap']=col['p_gapm']/(col['h_gap_mean']+1)
51
+ X=np.column_stack([np.repeat(np.asarray(col[k],np.float32),10) for k in col]).astype(np.float32)
52
+ return X,list(col)
53
+ if __name__=='__main__':
54
+ d=D.Data()
55
+ for c in [int(x) for x in sys.argv[1].split(',')]:
56
+ F=load_cut(c); v=d.val(c); assert (v['rowid']==F['rowid']).all()
57
+ X,names=build(d,c,F); np.save(f'/workspace/huawei/dw_lb/cache_prop_c{c}.npy',X); json.dump(names,open('/workspace/huawei/dw_lb/prop_names.json','w'))
58
+ print(c,X.shape,flush=True)
dw_lb/feat_tx.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Priority 5 (TRANSDUCTIVE, label-free): statistics over the unlabelled TARGET rows (validation first-event rows when validating; evaluation rows for v14).
2
+ Uses only: target slates (10 candidate items), target event ts, target histories (items+ts), and train-side exposure/CTR strictly before C (labels of ts<C only).
3
+ No target-window labels are used anywhere."""
4
+ import sys; sys.path.insert(0,'/workspace/huawei/dw_lb')
5
+ from lib import *
6
+ from scipy.sparse import csr_matrix
7
+ import dwcommon as D
8
+ FAMS=['f1','f2','f3','f4']
9
+ def train_ref(d,C):
10
+ """train-side reference from events ts<C (labels of ts<C only, allowed)"""
11
+ nX=int(np.searchsorted(d.ETS,C)); nL=int(np.searchsorted(d.ETS,C-DAY))
12
+ ex_all=np.bincount(d.RI[:nX].ravel(),minlength=d.NI).astype(np.float32); cl_all=np.bincount(d.RI[:nX].ravel(),weights=d.Y[:nX].ravel(),minlength=d.NI).astype(np.float32)
13
+ ex_l=np.bincount(d.RI[nL:nX].ravel(),minlength=d.NI).astype(np.float32); cl_l=np.bincount(d.RI[nL:nX].ravel(),weights=d.Y[nL:nX].ravel(),minlength=d.NI).astype(np.float32)
14
+ return dict(nX=nX,nL=nX-nL,ex_all=ex_all,cl_all=cl_all,ex_l=ex_l,cl_l=cl_l)
15
+ def target_from_data(d,e):
16
+ """target events e (indices into d) -> slates, ts, histories (as unlabeled inputs)"""
17
+ S=d.RI[e]; ts=d.ETS[e]; hi=[d.HI[d.OFF[x]:d.OFF[x+1]] for x in e]; ht=[d.HT[d.OFF[x]:d.OFF[x+1]] for x in e]
18
+ return S,ts,hi,ht
19
+ def zrk(x):
20
+ m=x.reshape(-1,10); mu=np.nanmean(m,1,keepdims=True); sd=np.nanstd(m,1,keepdims=True)+1e-6
21
+ return ((m-mu)/sd).ravel(),(m-mu).ravel(),m.argsort(1).argsort(1).astype(np.float32).ravel()
22
+ def build_tx(S,ts,hi,ht,C,ref,NI,fams=FAMS):
23
+ n=len(S); col={}; fl=S.ravel(); rep=lambda a:np.repeat(np.asarray(a,np.float32),10)
24
+ cnt=np.bincount(fl,minlength=NI).astype(np.float32) # exposure in target slates (includes own slot)
25
+ # ---- family 1: item exposure in target slates
26
+ if 'f1' in fams:
27
+ c1=cnt[fl]-1; col['f1_cnt']=c1/n*1e4
28
+ o=np.argsort(ts,kind='stable'); tss=ts[o]
29
+ # time-windowed exposure: key=(item,ts) of every target slot
30
+ its=np.repeat(S[o].ravel(),1); kt=np.repeat(tss,10); key=np.sort(its.astype(np.int64)*(1<<33)+kt)
31
+ base=fl.astype(np.int64)*(1<<33); tr=np.repeat(ts,10).astype(np.int64)
32
+ for nm,w in (('h1',3600),('h6',6*3600),('h24',24*3600)):
33
+ lo=np.searchsorted(key,base+tr-w,'left'); hi_=np.searchsorted(key,base+tr+w,'right'); cw=(hi_-lo-1).astype(np.float32)
34
+ nev=(np.searchsorted(tss,ts+w,'right')-np.searchsorted(tss,ts-w,'left')).astype(np.float32) # #target events in the window
35
+ col['f1_cnt_'+nm]=cw/np.repeat(nev,10)*1e3 # per-event normalised local exposure share
36
+ if nm=='h6': col['f1_cnt_h6_raw']=cw
37
+ expl=ref['ex_l'][fl]/max(ref['nL'],1)*1e3; col['f1_late_exp']=expl; col['f1_late_ctr']=(ref['cl_l'][fl]+0.2)/(ref['ex_l'][fl]+2)
38
+ col['f1_ratio_late']=(c1/n+1e-4)/((ref['ex_l'][fl]+0.5)/max(ref['nL'],1)); col['f1_ratio_all']=(c1/n+1e-4)/((ref['ex_all'][fl]+0.5)/max(ref['nX'],1))
39
+ col['f1_exp_x_ctr']=col['f1_cnt']*col['f1_late_ctr']
40
+ for k in ('f1_cnt','f1_cnt_h6','f1_ratio_late'):
41
+ z,dm,rk=zrk(col[k]); col[k+'_z']=z; col[k+'_dm']=dm; col[k+'_rk']=rk
42
+ col['f1_slate_mean']=np.repeat(col['f1_cnt'].reshape(-1,10).mean(1),10)
43
+ # ---- family 3: popularity in the histories of target users (items clicked; incl. post-cutoff clicks visible in histories)
44
+ hlen=np.array([len(x) for x in hi]); hI=np.concatenate(hi).astype(np.int64) if hlen.sum() else np.zeros(0,np.int64); hT=np.concatenate(ht).astype(np.int64)
45
+ hu=np.repeat(np.arange(n),hlen); pos_from_end=np.concatenate([np.arange(l)[::-1] for l in hlen]) if hlen.sum() else np.zeros(0)
46
+ if 'f3' in fams:
47
+ hc=np.bincount(hI,minlength=NI).astype(np.float32); col['f3_hpop']=hc[fl]/n*1e4
48
+ wl=np.bincount(hI,weights=(pos_from_end<3)/(1.0+pos_from_end),minlength=NI).astype(np.float32); col['f3_hpop_l3']=wl[fl]/n*1e4
49
+ l1=np.bincount(hI[pos_from_end==0],minlength=NI).astype(np.float32); col['f3_hpop_l1']=l1[fl]/n*1e4
50
+ post=hT>=C; hp=np.bincount(hI[post],minlength=NI).astype(np.float32); col['f3_hpost']=hp[fl]/n*1e4
51
+ hk=np.sort(hI*(1<<33)+hT); base=fl.astype(np.int64)*(1<<33); tr=np.repeat(ts,10).astype(np.int64)
52
+ for nm,w in (('6h',6*3600),('24h',24*3600)):
53
+ lo=np.searchsorted(hk,base+tr-w,'left'); hi_=np.searchsorted(hk,base+tr,'left'); col['f3_hrecent_'+nm]=(hi_-lo).astype(np.float32) # others' clicks on j in the w hours before this event (visible in target histories)
54
+ lo2=np.searchsorted(hk,base+tr,'left'); hi2=np.searchsorted(hk,base+tr+w,'right'); col['f3_hnext_'+nm]=(hi2-lo2).astype(np.float32)
55
+ # own-history subtraction for the "post" count: own clicks of j in own history
56
+ own=np.zeros(n*10,np.float32)
57
+ for i in range(n):
58
+ if hlen[i]:
59
+ h=hi[i]; own[i*10:(i+1)*10]=(S[i][:,None]==h[None,:]).sum(1)
60
+ col['f3_own_cnt']=own; col['f3_hpop_excl_own']=col['f3_hpop']-own/n*1e4
61
+ for k in ('f3_hpop','f3_hpost','f3_hrecent_24h'):
62
+ z,dm,rk=zrk(col[k]); col[k+'_z']=z; col[k+'_dm']=dm; col[k+'_rk']=rk
63
+ col['f3_hpost_vs_train_ctr']=col['f3_hpost']/(ref['cl_all'][fl]/max(ref['nX'],1)*1e4+1.0)
64
+ # ---- family 2: co-occurrence in target slates + last-click share among target users
65
+ if 'f2' in fams:
66
+ B=csr_matrix((np.ones(n*10,np.float32),(np.repeat(np.arange(n),10),fl)),shape=(n,NI)); CC=(B.T@B).tocsr()
67
+ ri=np.repeat(S,10,axis=1).ravel(); ci=np.tile(S,(1,10)).ravel() # all 100 pairs per event
68
+ v=np.asarray(CC[ri,ci]).ravel().reshape(n,10,10)-1.0 # LOO own
69
+ offd=~np.eye(10,dtype=bool); cj=(cnt[S]-1) # (n,10)
70
+ norm=np.sqrt((cj[:,:,None]+1)*(cj[:,None,:]+1))
71
+ coo=(v/norm)[:,offd].reshape(n,10,9) if False else None
72
+ vm=np.where(offd[None],v/norm,0).sum(2)/9; col['f2_cooc_norm']=vm.ravel()
73
+ col['f2_cooc_raw']=(np.where(offd[None],v,0).sum(2)/9).ravel()
74
+ # last-click share: users whose last click was h -> share of slates containing j
75
+ last=np.array([x[-1] if len(x) else -1 for x in hi],np.int64); l3=[x[-3:] for x in hi]
76
+ H=csr_matrix((np.ones((last>=0).sum(),np.float32),(np.flatnonzero(last>=0),last[last>=0])),shape=(n,NI)); A=(H.T@B).tocsr(); nh=np.asarray(H.sum(0)).ravel()
77
+ lsh=np.full((n,10),np.nan,np.float32)
78
+ ok=np.flatnonzero(last>=0)
79
+ if len(ok):
80
+ a=np.asarray(A[np.repeat(last[ok],10),S[ok].ravel()]).ravel().reshape(-1,10)-1.0; den=np.maximum(nh[last[ok]]-1,0)[:,None]
81
+ lsh[ok]=np.where(den>0,a/np.maximum(den,1),np.nan)
82
+ col['f2_lastshare_n']=np.repeat(np.where(nh[last]>0,nh[last]-1,np.nan),10).astype(np.float32)
83
+ col['f2_lastshare']=lsh.ravel()
84
+ # any of last-3 clicks (weighted share)
85
+ H3=csr_matrix((np.concatenate([np.ones(len(x),np.float32) for x in l3]),(np.repeat(np.arange(n),[len(x) for x in l3]),np.concatenate(l3).astype(np.int64) if sum(len(x) for x in l3) else [])),shape=(n,NI)); A3=(H3.T@B).tocsr(); nh3=np.asarray(H3.sum(0)).ravel()
86
+ s3=np.zeros((n,10),np.float32); d3=np.zeros(n,np.float32)
87
+ for k in range(3):
88
+ idx=[i for i in range(n) if len(l3[i])>k]
89
+ if not idx: continue
90
+ idx=np.array(idx); h=np.array([l3[i][-1-k] for i in idx],np.int64)
91
+ a=np.asarray(A3[np.repeat(h,10),S[idx].ravel()]).ravel().reshape(-1,10)-1.0
92
+ s3[idx]+=a; d3[idx]+=np.maximum(nh3[h]-1,0)
93
+ col['f2_l3share']=np.where(d3[:,None]>0,s3/np.maximum(d3[:,None],1),np.nan).ravel()
94
+ for k in ('f2_cooc_norm','f2_lastshare','f2_l3share'):
95
+ z,dm,rk=zrk(col[k]); col[k+'_z']=z; col[k+'_dm']=dm; col[k+'_rk']=rk
96
+ # ---- family 4: timing among target events
97
+ if 'f4' in fams:
98
+ o=np.argsort(ts,kind='stable'); rk_=np.empty(n); rk_[o]=np.arange(n); tss=ts[o]
99
+ col['f4_trel_h']=rep((ts-C)/3600); col['f4_trank']=rep(rk_/n)
100
+ col['f4_n_same_h']=rep(np.searchsorted(tss,ts+1800,'right')-np.searchsorted(tss,ts-1800,'left'))
101
+ col['f4_n_6h']=rep(np.searchsorted(tss,ts+6*3600,'right')-np.searchsorted(tss,ts-6*3600,'left'))
102
+ col['f4_n_before_frac']=rep(rk_/n)
103
+ col['f4_hist_n']=rep(hlen)
104
+ names=list(col); X=np.column_stack([np.asarray(col[k],np.float32) for k in names]).astype(np.float32)
105
+ return X,names
106
+ def build_val(d,c,fams=FAMS):
107
+ C=Jd(c); v=d.val(c); e=v['e'][::10]; S,ts,hi,ht=target_from_data(d,e)
108
+ # sanity: slate order must match val row order
109
+ S=v['item'].reshape(-1,10).astype(np.int64) # slate in val-row order
110
+ assert (np.sort(S,1)==np.sort(d.RI[e],1)).all()
111
+ return build_tx(S,ts,hi,ht,C,train_ref(d,C),d.NI,fams)
112
+ if __name__=='__main__':
113
+ d=D.Data()
114
+ for c in [int(x) for x in sys.argv[1].split(',')]:
115
+ X,names=build_val(d,c); np.save(f'/workspace/huawei/dw_lb/cache_tx_c{c}.npy',X); json.dump(names,open(f'/workspace/huawei/dw_lb/tx_names.json','w')); print(c,X.shape,flush=True)
dw_lb/findings.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # dw_lb findings — what could close 0.818 → 0.83? (Grok Bot / Eric, 2026-10-28)
2
+ All Δ = global AUC vs a control model (same residual LGB on v12 logits with z-derived context only), user-grouped 5-fold CV, event bootstrap 95% CI. v12 val logits reproduced exactly (C25 0.81723, C23 0.79566). Null-noise feature: Δ −0.00006 (C25), 0.00000 (C23) → harness false-positive floor ≈ ±0.0001.
3
+
4
+ ## 1. Public intel (honest: nothing concrete exists)
5
+ - Official description only: "Competing in the Intelligent Marketplace: Generative Sequential Recommendation Under Constraints" — feedback loop, multiple agents competing, compute/runtime constraints. https://huaweiireland.teamtailor.com/jobs/8447633-huawei-ireland-tech-arena-2026 , https://www.siliconrepublic.com/machines/how-huaweis-tech-arena-2026-aims-to-develop-irelands-ai-talent , https://www.hackathon.com/event/huawei-ireland-tech-arena-2026-6ac54367612836bf413df387 (Phase 1 Oct 21–Nov 4, top 15 announced Nov 9).
6
+ - No public Phase-1 solutions, leaderboard write-ups or CTR/AUC specifics found. The 0.83 figure is hearsay; unverifiable. Older edition posts (LinkedIn, e.g. https://www.linkedin.com/posts/rahulraj1406_huawei-techarena-llm-activity-7397952145213292544-JDot) concern a different task.
7
+
8
+ ## 2. Ranked ΔAUC (C25 / C23)
9
+ | # | lever | C25 | C23 | verdict |
10
+ |---|---|---|---|---|
11
+ | 1 | User click-propensity (28 feats, feat_prop.py) | +0.00020 [+0.00008,+0.00033] | +0.00026 [+0.00012,+0.00043] | real but tiny |
12
+ | 2 | Transductive family f2 co-occurrence (VAL only) | +0.00013 [+0.00004,+0.00023] (seed1 +0.00012) | −0.00005 | ≈0 |
13
+ | 3 | Transductive f3 history popularity | +0.00010 / +0.00013 | +0.00009 | ≈0 (CI spans 0) |
14
+ | 4 | Transductive all 60 | +0.00010 [−0.00008,+0.00024] | +0.00012 [−0.00004,+0.00028] | ≈0 |
15
+ | 5 | Transductive f1 exposure | −0.00002 / −0.00005 | +0.00008 | 0 |
16
+ | 6 | Transductive f4 timing | +0.00003 / +0.00005 | +0.00007 | 0 |
17
+ | 7 | transductive + propensity (88) | +0.00018 [−0.00001,+0.00033] | +0.00029 [+0.00013,+0.00047] | = propensity alone |
18
+ | 8 | Two-stage event model P(ev)·softmax (ctx / ctx+prop) | glob 0.81707 / 0.81720 vs z 0.81723 | 0.79508 / 0.79525 vs 0.79566 | negative |
19
+ | 9 | More training events (learning curve, 1→4 pseudo-folds, same LGB, cut 25) | 0.8142 / 0.8158 / 0.8162 / 0.8160 | – | saturated after ~2–3 folds → all-events rebuild est. ≤ +0.001 |
20
+ | 10 | From-scratch softmax+outside-option latent model (torch, all events) | alone 0.58–0.60 | – | useless: sparse (50k items, 53k users, 687k events), overfits |
21
+
22
+ ## 3. Simulator facts learned
23
+ - **Each event has at most ONE click** (0.366 no-click, 0.634 one click, nothing else) → single-choice softmax with an outside option; v12's binary logits sum to 0.98 per slate vs 0.63 observed (calibrated within-event ranking is what matters).
24
+ - P(no click) falls with slate logsumexp but is more consistent with a taste-dependent outside option than a constant one: constant-outside prediction overshoots P0 (e.g. top decile pred 0.31 vs obs 0.17).
25
+ - Event "any click" AUC: lse 0.668 → +z-context LGB 0.671 → + user propensity 0.672 (C25); C23 0.644→0.649→0.652. Oracle event label would give 0.894 (C25). So the 0.83 gap would have to come from event-level prediction ≈0.74+ (headroom sim: event AUC 0.76 ⇒ +0.0075), which is not reachable from user propensity (split-half user corr only 0.39, event click rate flat in hour/gap) nor from slate/exposure aggregates.
26
+ - Transductive univariates ≤0.53 within-event AUC; stationary data; exposure unrelated to click; post-cutoff clicks in histories ≈0.500.
27
+
28
+ ## 4. Which lever most likely explains 0.83?
29
+ None of the five measured levers can: sum of all positive finds ≈ +0.0005–0.001. The gap (if real) is most plausibly better **item–user taste modelling** (a better preference model improves both within-event ranking and event-level lse), not data volume, propensity, or eval aggregates. My own end-to-end latent softmax failed because of sparsity, so any win there needs the strong CF-style features v12 already has (+ ensembling of many diverse models). Cheap remaining idea within v12's paradigm: more diverse seeds/learners (blend gains in v12 notes were ~+0.001 each).
30
+
31
+ ## 5. Value of transductive features (information only, for Eric)
32
+ Measured cost of the eval-aggregate ban: **≈ +0.0001 (CI spans 0) on C25/C23** — not worth lifting the ban. v14 README written in /workspace/huawei/v14_transductive/, submission NOT built (nothing gained).
33
+
34
+ ## 6. Code paths (all in /workspace/huawei/dw_lb/)
35
+ lib.py (z12, load_cut, oof, boot_delta, report) · feat_prop.py → cache_prop_c{25,23}.npy (propensity, ready to hand to v12 as new feature family; leak-safe: snapshot ts<C + own history) · feat_tx.py (transductive, `build_tx`) · run_tx.py / run_prop.py / run_p4.py (tests) · p4_softmax.py (torch single-choice model) · lc/lc.sh (learning curve) · results*.jsonl · logs.
dw_lb/lc/cl.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared loader + feature-matrix cache (step C). Matrices cached as parquet keyed by hash(table names, feature list, sample)."""
2
+ import os, sys, hashlib, json, gc, numpy as np, polars as pl
3
+ sys.path.insert(0,'/workspace/huawei/v9'); sys.path.insert(1,'/workspace/huawei/v3')
4
+ from feats import DROP
5
+ from features import feature_cols, GROUPS
6
+ V9='/workspace/huawei/v9'; D='/workspace/huawei/v12'; P2=f'{V9}/feat'; P3=f'{V9}/feat_v3'; CACHE='/workspace/huawei/v9d/val/cache_mx' # read-only base cache
7
+ V2_OF={'val23':'val23','f1':'h1','f2':'h2','f3':'h3','f4':'h4','f5':'h5','f6':'val26','val25':'val25','val26':'val26','eval':'eval'}
8
+ V2_OF.update({f'{p}{k}':f'{p}{k}' for p in 'eEd' for k in range(1,7)})
9
+ TIME=['tm_stale','tm_hour','tm_tb','tm_dt','v2_tb','v2_dt','v2_stale','v2_hour']
10
+ KEEP=['rowid','eid','u','ts','clicked','us_cold','us_nohist','tm_stale']
11
+ def load_tab(n, extra=(), variant='notime'):
12
+ a=pl.read_parquet(f'{P3}/{n}.parquet'); b=pl.read_parquet(f'{P2}/{V2_OF[n]}.parquet')
13
+ f2=[c for c in b.columns if c not in DROP]
14
+ a=a.join(b.select(['rowid']+f2).rename({c:'v2_'+c for c in f2}),on='rowid',how='left')
15
+ for sub in (os.environ.get('XDIR','feat_x'),)+(('feat_x2',) if os.path.isdir(f'{D}/feat_x2') else ())+tuple(extra):
16
+ a=a.join(pl.read_parquet(f'{D}/{sub}/{n}.parquet'),on='rowid',how='left')
17
+ if '+' in variant:
18
+ import mods; a=mods.apply(a,n,variant)
19
+ return a
20
+ def featlist(df, variant='notime'):
21
+ f=feature_cols(df,GROUPS)+[c for c in df.columns if c.startswith(('v2_','x_','r_','s_','ev2_','rc_','sh_','hs_','lr','tA_','tB_','uw_','la_','sq_'))]
22
+ if 'notime' in variant: f=[c for c in f if c not in TIME]
23
+ if variant.split('+')[0]=='stale': f=[c for c in f if c not in TIME or c=='tm_stale']
24
+ return f
25
+ def usample(df, frac):
26
+ if frac>=1: return df
27
+ return df.filter((pl.col('u').hash(seed=7) % 10000) < int(frac*10000))
28
+ FL=[None]
29
+ def load_tab_rows(n, rid, extra=(), variant='notime'):
30
+ """same as load_tab but restricted to rowids rid (polars Series) -> low memory"""
31
+ a=pl.scan_parquet(f'{P3}/{n}.parquet').filter(pl.col('rowid').is_in(rid)).collect()
32
+ b=pl.scan_parquet(f'{P2}/{V2_OF[n]}.parquet').filter(pl.col('rowid').is_in(rid)).collect()
33
+ f2=[c for c in b.columns if c not in DROP]
34
+ a=a.join(b.select(['rowid']+f2).rename({c:'v2_'+c for c in f2}),on='rowid',how='left')
35
+ for sub in (os.environ.get('XDIR','feat_x'),)+(('feat_x2',) if os.path.isdir(f'{D}/feat_x2') else ())+tuple(extra):
36
+ a=a.join(pl.scan_parquet(f'{D}/{sub}/{n}.parquet').filter(pl.col('rowid').is_in(rid)).collect(),on='rowid',how='left')
37
+ return a
38
+ def build_chunked(n, extra, variant, frac, nch=4):
39
+ rid_all=pl.read_parquet(f'{P3}/{n}.parquet',columns=['rowid'])['rowid']; parts=[]
40
+ step=(len(rid_all)+nch-1)//nch
41
+ for i in range(nch):
42
+ rid=rid_all.slice(i*step,step); t=usample(load_tab_rows(n,rid,extra,variant),frac)
43
+ # restore original order within chunk
44
+ t=pl.DataFrame({'rowid':rid}).join(t,on='rowid',how='inner',maintain_order='left')
45
+ fl=featlist(t,variant); FL[0]=fl
46
+ t=t.select(list(dict.fromkeys([c for c in KEEP if c in t.columns]+fl)))
47
+ t=t.with_columns([pl.col(c).cast(pl.Float32) for c in fl if t[c].dtype!=pl.Float32 and c not in KEEP])
48
+ parts.append(t); gc.collect()
49
+ return pl.concat(parts)
50
+ BASE=('feat_lr2','feat_tt','feat_pp')
51
+ def matrix(n, frac=1.0, variant='notime', extra=()):
52
+ """v9: base = cached v8-lite matrix (read-only, from v9d/val/cache_mx); new dirs (feat_tm*) joined on rowid.
53
+ returns (X float32, meta DataFrame, feats)."""
54
+ base=tuple(e for e in extra if e in BASE); new=[e for e in extra if e not in BASE]; assert base==BASE, extra
55
+ key=hashlib.md5(json.dumps([n,frac,variant,list(base),os.path.getmtime(f'{P3}/{n}.parquet')]).encode()).hexdigest()[:12]
56
+ fp=f'{CACHE}/{n}_{key}.parquet'; assert os.path.exists(fp), fp
57
+ fl=json.load(open(fp+'.json')); t=pl.read_parquet(fp)
58
+ for sub in new:
59
+ e=pl.read_parquet(f'{D}/{sub}/{n}.parquet'); nc=[c for c in e.columns if c!='rowid' and c not in fl]
60
+ t=t.join(e.select(['rowid']+nc),on='rowid',how='left',maintain_order='left'); fl=fl+nc
61
+ drop=os.environ.get('V9DROP')
62
+ if drop:
63
+ import re; fl=[c for c in fl if not re.search(drop,c)]
64
+ X=t.select(fl).cast(pl.Float32).to_numpy(); meta=t.select([c for c in KEEP if c in t.columns]); del t; gc.collect()
65
+ return X, meta, fl
dw_lb/lc/ens.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Phase 1 ensemble components. python ens.py CUT TAG [--seeds 0,1] [--folds f|fe] [--stale] [--rc] [--drop re] [--params json] [--rounds 400]
2
+ CUT=25/26: train f1..f(CUT-21) (+e/d folds) full data, predict val{CUT}; CUT=27: train f1..f6 (+E1..E6), predict eval.
3
+ Saves ens/{tag}_c{CUT}_s{seed}.npy with raw scores at rounds 300,400(,500) (columns)."""
4
+ import sys, re, json, gc, time, argparse, numpy as np, lightgbm as lgb
5
+ from cl import matrix
6
+ from sklearn.metrics import roc_auc_score
7
+ ap=argparse.ArgumentParser(); ap.add_argument('cut',type=int); ap.add_argument('tag'); ap.add_argument('--seeds',default='0')
8
+ ap.add_argument('--folds',default='f'); ap.add_argument('--stale',action='store_true'); ap.add_argument('--rc',action='store_true')
9
+ ap.add_argument('--drop',default=None); ap.add_argument('--params',default='{}'); ap.add_argument('--rounds',type=int,default=400); ap.add_argument('--threads',type=int,default=5); ap.add_argument('--lr',default=''); ap.add_argument('--nfolds',type=int,default=99); ap.add_argument('--negfrac',type=float,default=1.0); ap.add_argument('--keep',default=''); ap.add_argument('--wtag',default=''); ap.add_argument('--wpow',type=float,default=1.0); ap.add_argument('--agew',type=float,default=0); ap.add_argument('--save',default='300,400,500')
10
+ a=ap.parse_args(); t0=time.time()
11
+ extra=(('feat_rc',) if a.rc else ())+tuple(x for x in a.lr.split(',') if x); var='stale' if a.stale else 'notime'
12
+ efold={23:[],25:[f'e{k}' for k in range(1,5)],26:[f'd{k}' for k in range(1,6)],27:[f'E{k}' for k in range(1,7)]}[a.cut]
13
+ trn=([f'f{k}' for k in range(max(1,a.cut-20-a.nfolds),a.cut-20)] if 'f' in a.folds else [])+(efold if 'e' in a.folds else [])
14
+ import polars as pl
15
+ lens=[pl.read_parquet_schema and len(pl.read_parquet(f'feat_v3/{n}.parquet',columns=['rowid'])) for n in trn]
16
+ rs=np.random.RandomState(123); R=rs.rand(sum(lens)) if a.negfrac<1 else None
17
+ Xs=[];ys=[];ws=[];feats=None;off=0
18
+ for n,L in zip(trn,lens):
19
+ X,m,f=matrix(n,1.0,variant=var,extra=extra); feats=f; yy=m['clicked'].to_numpy(); assert len(yy)==L
20
+ sel=(yy==1)|(R[off:off+L]<a.negfrac) if R is not None else np.ones(L,bool); off+=L
21
+ if a.wtag: ws.append(np.load(f'ens/w_{a.wtag}_{n}.npy')[sel]**a.wpow)
22
+ if a.agew: ws.append(np.full(int(sel.sum()),a.agew**(len(trn)-1-trn.index(n)),np.float32))
23
+ Xs.append(X[sel]); ys.append(yy[sel]); del X,m; gc.collect()
24
+ X=np.concatenate(Xs); del Xs; gc.collect(); y=np.concatenate(ys); W=np.concatenate(ws) if ws else None
25
+ if W is not None: W=W/W.mean(); print('weights: mean',W.mean(),'p01/p50/p99',np.percentile(W,[1,50,99]),'ESS frac',W.sum()**2/(W**2).sum()/len(W),flush=True)
26
+ keep=[i for i,c in enumerate(feats) if not (a.drop and re.search(a.drop,c))]; fl=[feats[i] for i in keep]
27
+ if a.keep: KS=set(open(a.keep).read().split()); keep=[i for i in keep if feats[i] in KS]; fl=[feats[i] for i in keep]
28
+ if len(keep)<len(feats): X=np.ascontiguousarray(X[:,keep])
29
+ P=dict(objective='binary',learning_rate=0.05,num_leaves=63,min_data_in_leaf=200,feature_fraction=0.7,bagging_fraction=0.8,
30
+ bagging_freq=1,lambda_l2=10.0,verbose=-1,num_threads=a.threads); P.update(json.loads(a.params))
31
+ t_load=time.time()-t0; t_ds=time.time(); ds=lgb.Dataset(X,y,weight=W,feature_name=fl,free_raw_data=True,params={k:P[k] for k in ('max_bin','force_col_wise') if k in P}).construct(); t_ds=time.time()-t_ds; del X; gc.collect()
32
+ vn='eval' if a.cut==27 else f'val{a.cut}'
33
+ Xv,mv,fv=matrix(vn,1.0,variant=var,extra=extra); Xv=Xv[:,[fv.index(c) for c in fl]]
34
+ RS=[int(r) for r in a.save.split(',') if int(r)<=a.rounds]
35
+ for s in map(int,a.seeds.split(',')):
36
+ t1=time.time(); import os; mdl=lgb.train(dict(P,seed=42+s+int(os.environ.get('V9SEED','0'))),ds,a.rounds); t_fit=time.time()-t1; t1=time.time()
37
+ S=np.stack([mdl.predict(Xv,num_iteration=r,raw_score=True) for r in RS],1)
38
+ t_pred=time.time()-t1; np.save(f'ens/{a.tag}_c{a.cut}_s{s}.npy',S.astype(np.float32))
39
+ msg=dict(cut=a.cut,tag=a.tag,seed=s,n=len(y),nf=len(fl),min=round((time.time()-t0)/60,1),load_s=round(t_load),ds_s=round(t_ds),fit_s=round(t_fit),pred_s=round(t_pred))
40
+ if a.cut!=27: msg['auc']={r:round(roc_auc_score(mv['clicked'].to_numpy(),S[:,i]),5) for i,r in enumerate(RS)}
41
+ print(json.dumps(msg),flush=True); open('ens/ens_log.jsonl','a').write(json.dumps(msg)+'\n')
dw_lb/lc/lc.log ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {"cut": 25, "tag": "lc_nf1", "seed": 0, "n": 186120, "nf": 435, "min": 0.4, "load_s": 2, "ds_s": 3, "fit_s": 15, "pred_s": 6, "auc": {"400": 0.81419, "500": 0.81376}}
2
+ {"cut": 25, "tag": "lc_nf2", "seed": 0, "n": 371507, "nf": 435, "min": 0.6, "load_s": 3, "ds_s": 4, "fit_s": 25, "pred_s": 6, "auc": {"400": 0.8158, "500": 0.81562}}
3
+ {"cut": 25, "tag": "lc_nf3", "seed": 0, "n": 558606, "nf": 435, "min": 0.9, "load_s": 5, "ds_s": 5, "fit_s": 37, "pred_s": 5, "auc": {"400": 0.81618, "500": 0.81618}}
4
+ {"cut": 25, "tag": "lc_nf4", "seed": 0, "n": 745456, "nf": 435, "min": 1.1, "load_s": 7, "ds_s": 5, "fit_s": 46, "pred_s": 5, "auc": {"400": 0.81589, "500": 0.81595}}
5
+ LC_DONE
dw_lb/lc/lc.sh ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ cd /workspace/huawei/dw_lb/lc
3
+ export POLARS_MAX_THREADS=6 OMP_NUM_THREADS=6 PYTHONUNBUFFERED=1
4
+ SLOW='{"learning_rate":0.03,"feature_fraction":0.55,"num_leaves":95,"lambda_l2":30,"max_bin":63,"force_col_wise":true}'
5
+ L=feat_lr2,feat_tt,feat_pp,feat_sqC,feat_dw
6
+ for nf in 1 2 3 4; do
7
+ for c in 25; do
8
+ /workspace/venv/bin/python ens.py $c lc_nf$nf --seeds 0 --threads 6 --lr $L --negfrac 0.5 --nfolds $nf --rounds 500 --save 400,500 --params "$SLOW" --drop '^sq_(pdot|pcos|mdot|mcos)$' 2>&1 | grep -v Warn | tail -2
9
+ done
10
+ done
11
+ echo LC_DONE
dw_lb/lib.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys, os, json, numpy as np, polars as pl, lightgbm as lgb, warnings; warnings.filterwarnings('ignore')
2
+ sys.dont_write_bytecode=True
3
+ sys.path.insert(0,'/workspace/huawei/dw_levers'); sys.path.insert(1,'/workspace/huawei/dw_signals')
4
+ from sklearn.metrics import roc_auc_score as A
5
+ from sklearn.model_selection import GroupKFold
6
+ H='/workspace/huawei'; DAY=86400; J20=1737331200
7
+ def Jd(d): return J20+(d-20)*DAY
8
+ def z12(c):
9
+ s=lambda t,k:np.load(f'{H}/v12/ens/{t}_c{c}_s0.npy')[:,k]
10
+ m=np.mean([np.load(f'{H}/v12/ens/dwmlp_c{c}_s{k}.npy')[:,3] for k in (range(3) if c!=26 else [0])],0)
11
+ return ((s('dwbig',1)+s('dw_s',1)+2*m)/4).astype(np.float64)
12
+ def meta(c): return pl.read_parquet(f'{H}/v10/feat_v3/val{c}.parquet',columns=['rowid','eid','u','ts','clicked'])
13
+ def base_ctx(z):
14
+ Z=z.reshape(-1,10); mu=Z.mean(1,keepdims=True); sd=Z.std(1,keepdims=True)+1e-6
15
+ rk=Z.argsort(1).argsort(1).astype(np.float32)
16
+ lse=np.log(np.exp(Z).sum(1,keepdims=True))
17
+ cols=[z,((Z-mu)/sd).ravel(),(Z-mu).ravel(),rk.ravel(),np.repeat(lse,10,1).ravel(),np.repeat(Z.max(1,keepdims=True),10,1).ravel(),np.repeat(mu,10,1).ravel(),np.repeat(sd,10,1).ravel()]
18
+ return np.column_stack(cols).astype(np.float32)
19
+ PI=dict(objective='binary',learning_rate=0.03,num_leaves=15,min_data_in_leaf=500,feature_fraction=0.8,bagging_fraction=0.8,bagging_freq=1,lambda_l2=30,max_bin=127,verbose=-1,num_threads=4)
20
+ def oof(X,y,z,user,seed=0,rounds=200,k=5,params=None):
21
+ p=np.zeros(len(y)); P={**PI,**(params or {})}
22
+ for tr,te in GroupKFold(k).split(X,y,user):
23
+ m=lgb.train({**P,'seed':seed},lgb.Dataset(X[tr],y[tr],init_score=z[tr]),rounds); p[te]=m.predict(X[te],raw_score=True)+z[te]
24
+ return p
25
+ def boot_delta(y,p0,p1,ev,nb=200,seed=0):
26
+ """bootstrap over events (10 rows each) of AUC(p1)-AUC(p0)"""
27
+ rs=np.random.RandomState(seed); n=len(y)//10; Y=y.reshape(n,10); a=p0.reshape(n,10); b=p1.reshape(n,10); out=[]
28
+ for _ in range(nb):
29
+ i=rs.randint(0,n,n); yy=Y[i].ravel(); out.append(A(yy,b[i].ravel())-A(yy,a[i].ravel()))
30
+ return np.percentile(out,[2.5,97.5]), np.std(out)
31
+ def load_cut(c):
32
+ m=meta(c); z=z12(c); assert len(z)==m.height
33
+ return dict(c=c,y=m['clicked'].to_numpy().astype(int),z=z,user=m['u'].to_numpy(),rowid=m['rowid'].to_numpy(),ts=m['ts'].to_numpy(),Xb=base_ctx(z))
34
+ def report(name,F,Xnew,seeds=(0,),log='results.jsonl',control_cols=None):
35
+ """F: cut dict; Xnew: (n,k) new feats. control = Xb only; test = Xb+Xnew. returns delta vs z and vs control"""
36
+ y,z,u=F['y'],F['z'],F['user']; res=dict(name=name,cut=F['c'],nfeat=Xnew.shape[1],base=A(y,z))
37
+ pc=np.mean([oof(F['Xb'],y,z,u,s) for s in seeds],0); X=np.hstack([F['Xb'],Xnew]); pt=np.mean([oof(X,y,z,u,s) for s in seeds],0)
38
+ res.update(control=A(y,pc),test=A(y,pt)); res['d_vs_z']=res['test']-res['base']; res['d_vs_ctrl']=res['test']-res['control']
39
+ ci,sd=boot_delta(y,pc,pt,None); res['ci_vs_ctrl']=[float(ci[0]),float(ci[1])]; res['sd']=float(sd)
40
+ ev=lambda p: A((y.reshape(-1,10).max(1)),np.log(np.exp(p.reshape(-1,10)).sum(1)))
41
+ res['evAUC_base']=ev(z); res['evAUC_test']=ev(pt)
42
+ print(json.dumps({k:(round(v,5) if isinstance(v,float) else v) for k,v in res.items()}),flush=True)
43
+ open(f'/workspace/huawei/dw_lb/{log}','a').write(json.dumps(res)+'\n'); return res,pt
dw_lb/p4.log ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ {"cut": 25, "ev_lse": 0.66805, "ev_max": 0.62214, "ev_ctx": 0.67124, "ev_ctx_prop": 0.6723, "glob_ctx": 0.81707, "glob_ctx_prop": 0.8172, "glob_z": 0.81723, "glob_oracle_ev": 0.89396}
2
+ {"cut": 23, "ev_lse": 0.64445, "ev_max": 0.60332, "ev_ctx": 0.6488, "ev_ctx_prop": 0.65235, "glob_ctx": 0.79508, "glob_ctx_prop": 0.79525, "glob_z": 0.79566, "glob_oracle_ev": 0.88174}
dw_lb/p4_softmax.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Priority 4: parametric single-choice softmax + user-specific outside option, trained end-to-end on ALL events with ts<C (torch, CPU).
2
+ score_j = <u,v_j> + b_j + g(match(j in history)); outside logit o = MLP(u,...). P(click j)=exp(s_j)/(exp(o)+sum exp s_k). Outputs val logit log P(click j)."""
3
+ import sys, time; sys.path.insert(0,'/workspace/huawei/dw_lb')
4
+ from lib import *
5
+ import torch, torch.nn as nn, torch.nn.functional as Fn
6
+ import dwcommon as D
7
+ torch.set_num_threads(4); import os; USEU=int(os.environ.get('USEU','1')); TIE=int(os.environ.get('TIE','0'))
8
+
9
+ def pad_hist(d,ev,L=20):
10
+ n=len(ev); Hp=np.full((n,L),-1,np.int64); Tp=np.zeros((n,L),np.float32)
11
+ for i,e in enumerate(ev):
12
+ a,b=d.OFF[e],d.OFF[e+1]; k=b-a
13
+ if k: Hp[i,L-k:]=d.HI[a:b]; Tp[i,L-k:]=(d.ETS[e]-d.HT[a:b])/3600.
14
+ return Hp,Tp
15
+ class M(nn.Module):
16
+ def __init__(s,NU,NI,k=32):
17
+ super().__init__(); s.Eu=nn.Embedding(NU,k); s.Ei=nn.Embedding(NI,k); s.Eh=nn.Embedding(NI+1,k,padding_idx=NI); s.bi=nn.Embedding(NI,1)
18
+ s.pw=nn.Parameter(torch.zeros(20)); s.proj=nn.Linear(k,k); s.match=nn.Sequential(nn.Linear(4,16),nn.ReLU(),nn.Linear(16,1))
19
+ s.out=nn.Sequential(nn.Linear(k+3,32),nn.ReLU(),nn.Linear(32,1)); s.k=k
20
+ for e in (s.Eu,s.Ei,s.Eh): nn.init.normal_(e.weight,0,0.05)
21
+ nn.init.zeros_(s.bi.weight)
22
+ def forward(s,u,S,Hp,Tp,gap):
23
+ if TIE: s.Eh.weight.data[:-1]=s.Ei.weight.data if False else s.Eh.weight.data[:-1]
24
+ NI=s.Ei.num_embeddings; valid=(Hp>=0); Hq=torch.where(valid,Hp,torch.full_like(Hp,NI))
25
+ w=torch.softmax(s.pw[None]+torch.where(valid,0.,-1e4),1)*valid.any(1,keepdim=True)
26
+ pool=(s.Eh(Hq)*w[:,:,None]).sum(1); uv=(s.Eu(u) if USEU else 0)+s.proj(pool)
27
+ sc=(s.Ei(S)*uv[:,None,:]).sum(2)+s.bi(S).squeeze(2)
28
+ m=(S[:,:,None]==Hp[:,None,:])&valid[:,None,:]; cnt=m.sum(2).float(); pos=torch.where(m,torch.arange(20,device=S.device)[None,None,:].float(),torch.full((1,),-1.,device=S.device)).max(2).values; rec=torch.where(cnt>0,(pos+1)/20.,torch.zeros_like(pos))
29
+ age=torch.where(m,Tp[:,None,:],torch.zeros_like(Tp[:,None,:])).sum(2)/torch.clamp(cnt,min=1)
30
+ mf=torch.stack([(cnt>0).float(),torch.log1p(cnt),rec,torch.log1p(age)/5],2); sc=sc+s.match(mf).squeeze(2)
31
+ hl=valid.sum(1,keepdim=True).float()
32
+ o=s.out(torch.cat([uv,hl/20,torch.log1p(gap)[:,None]/5,(hl==0).float()],1)).squeeze(1)
33
+ return sc,o
34
+ def run(c,epochs=6,k=32,seed=0,lam=1e-2,lr=3e-3,tag=''):
35
+ torch.manual_seed(seed); d=D.Data(); C=Jd(c); nX=int(np.searchsorted(d.ETS,C)); v=d.val(c); ev=v['e'][::10]
36
+ tr=np.arange(nX); Htr,Ttr=pad_hist(d,tr); Hv,Tv=pad_hist(d,ev)
37
+ gap=lambda e: np.zeros(len(e),np.float32)
38
+ ys=d.Y[:nX]; lab=np.where(ys.sum(1)>0,ys.argmax(1)+1,0) # 0=no click(outside)
39
+ S=torch.tensor(d.RI[:nX].astype(np.int64)); U=torch.tensor(d.EU[:nX].astype(np.int64)); Hp=torch.tensor(Htr); Tp=torch.tensor(Ttr); L=torch.tensor(lab); G=torch.zeros(nX)
40
+ Sv=torch.tensor(v['item'].reshape(-1,10).astype(np.int64)); Uv=torch.tensor(v['user'][::10].astype(np.int64)); Hvt=torch.tensor(Hv); Tvt=torch.tensor(Tv); Gv=torch.zeros(len(ev))
41
+ m=M(d.NU,d.NI,k); opt=torch.optim.Adam(m.parameters(),lr=lr); yv=v['y']
42
+ def predict():
43
+ m.eval(); out=[]
44
+ with torch.no_grad():
45
+ for i in range(0,len(ev),8192):
46
+ sc,o=m(Uv[i:i+8192],Sv[i:i+8192],Hvt[i:i+8192],Tvt[i:i+8192],Gv[i:i+8192]); lse=torch.logsumexp(torch.cat([o[:,None],sc],1),1,keepdim=True); out.append((sc-lse).numpy())
47
+ m.train(); return np.concatenate(out)
48
+ bs=2048; t0=time.time()
49
+ for epc in range(epochs):
50
+ perm=torch.randperm(nX)
51
+ for i in range(0,nX,bs):
52
+ b=perm[i:i+bs]; sc,o=m(U[b],S[b],Hp[b],Tp[b],G[b]); logit=torch.cat([o[:,None],sc],1); loss=Fn.cross_entropy(logit,L[b])+lam*((m.Eu(U[b])**2).sum(1).mean()+(m.Ei(S[b])**2).sum(2).mean()+(m.Eh.weight[Hp[b].clamp(min=0)]**2).sum(2).mean())
53
+ opt.zero_grad(); loss.backward(); opt.step()
54
+ p=predict(); print(f'c{c} ep{epc} loss {loss.item():.4f} val AUC logP {A(yv,p.ravel()):.5f} t={time.time()-t0:.0f}s',flush=True)
55
+ np.save(f'/workspace/huawei/dw_lb/cache_sm{tag}_c{c}.npy',p.ravel().astype(np.float32))
56
+ if __name__=='__main__': run(int(sys.argv[1]),int(sys.argv[2]),int(sys.argv[3]),0,float(sys.argv[4]),float(sys.argv[5]),sys.argv[6] if len(sys.argv)>6 else '')
dw_lb/prop23.log ADDED
@@ -0,0 +1 @@
 
 
1
+ 23 (501550, 28)
dw_lb/prop_names.json ADDED
@@ -0,0 +1 @@
 
 
1
+ ["p_nev", "p_evrate", "p_ctr", "p_ctr_s", "p_l3", "p_streak", "p_gapm", "p_gapsd", "p_since_ev", "p_since_first", "p_gap_ratio", "h_len", "h_span", "h_since_last", "h_gap_mean", "h_gap_sd", "h_gap_last", "h_1d", "h_3d", "h_7d", "h_warm", "h_win", "h_uniq", "h_uniq_ratio", "h_rate_day", "p_clk_per_ev", "implied_cpe", "gap_over_hgap"]
dw_lb/results.jsonl ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {"name": "null_event_noise", "cut": 25, "nfeat": 1, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8171577530714159, "d_vs_z": -6.819451209449934e-05, "d_vs_ctrl": -6.17451939234348e-05, "ci_vs_ctrl": [-0.00010993807087290585, -7.890079290281935e-06], "sd": 2.8203555989303043e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6656587077481898}
2
+ {"name": "prop_all", "cut": 25, "nfeat": 28, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8174189331936028, "d_vs_z": 0.0001929856100923999, "d_vs_ctrl": 0.00019943492826346443, "ci_vs_ctrl": [8.425431766705683e-05, 0.00032945002107639954], "sd": 6.277318634322474e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6671521893599606}
3
+ {"name": "null_event_noise", "cut": 23, "nfeat": 1, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7955480279490578, "d_vs_z": -0.00010774943840785589, "d_vs_ctrl": 2.5894856480190853e-06, "ci_vs_ctrl": [-6.393072952146084e-05, 7.37865104797425e-05], "sd": 3.50022857311498e-05, "evAUC_base": 0.644454956712242, "evAUC_test": 0.6441126350872265}
4
+ {"name": "prop_all", "cut": 23, "nfeat": 28, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7958092803166474, "d_vs_z": 0.00015350292918181463, "d_vs_ctrl": 0.0002638418532376896, "ci_vs_ctrl": [0.00011603082194248937, 0.000432235776237011], "sd": 8.091216243359532e-05, "evAUC_base": 0.644454956712242, "evAUC_test": 0.6479624908242326}
dw_lb/results_p4.jsonl ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ {"cut": 25, "ev_lse": 0.6680507246702352, "ev_max": 0.6221356536575582, "ev_ctx": 0.6712369663700499, "ev_ctx_prop": 0.6723044047655211, "glob_ctx": 0.8170725392055592, "glob_ctx_prop": 0.8171975022435236, "glob_z": 0.8172259475835104, "glob_oracle_ev": 0.8939614341668701}
2
+ {"cut": 23, "ev_lse": 0.644454956712242, "ev_max": 0.6033170604590983, "ev_ctx": 0.6487983224904563, "ev_ctx_prop": 0.6523494305713399, "glob_ctx": 0.7950750830226788, "glob_ctx_prop": 0.7952474179617948, "glob_z": 0.7956557773874656, "glob_oracle_ev": 0.881737373317231}
dw_lb/results_tx.jsonl ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"name": "tx_f1", "cut": 25, "seed": 0, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8172027883512023, "d_vs_ctrl": -1.6709914137047477e-05, "ci": [-0.00014349266344125257, 0.00014587432118149673], "sd": 7.394595909960953e-05, "nfeat": 20}
2
+ {"name": "tx_f2", "cut": 25, "seed": 0, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8173499925039057, "d_vs_ctrl": 0.00013049423856636988, "ci": [3.9790617533291826e-05, 0.00023067132830789097], "sd": 5.150322756776621e-05, "nfeat": 14}
3
+ {"name": "tx_f3", "cut": 25, "seed": 0, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8173169526524945, "d_vs_ctrl": 9.74543871551381e-05, "ci": [-5.4981787659713624e-05, 0.00021526865679996352], "sd": 7.300359621086734e-05, "nfeat": 20}
4
+ {"name": "tx_f4", "cut": 25, "seed": 0, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8172527064819, "d_vs_ctrl": 3.320821656060957e-05, "ci": [-5.4703244326295694e-05, 0.00011614454119170672], "sd": 4.313636553203988e-05, "nfeat": 6}
5
+ {"name": "tx_all", "cut": 25, "seed": 0, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8173167974531333, "d_vs_ctrl": 9.729918779399771e-05, "ci": [-7.801107898108007e-05, 0.00023711497566265008], "sd": 8.903256137410697e-05, "nfeat": 60}
6
+ {"name": "tx_all+prop", "cut": 25, "seed": 0, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8173983206258677, "d_vs_ctrl": 0.00017882236052835232, "ci": [-5.831556720231612e-06, 0.00032584640888283224], "sd": 8.898557768981401e-05, "nfeat": 88}
7
+ {"name": "tx_f1", "cut": 23, "seed": 0, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7956233103415669, "d_vs_ctrl": 7.787187815710972e-05, "ci": [-7.479367148836014e-05, 0.00026347507973854004], "sd": 8.39083487483491e-05, "nfeat": 20}
8
+ {"name": "tx_f2", "cut": 23, "seed": 0, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7954944826046069, "d_vs_ctrl": -5.095585880288134e-05, "ci": [-0.00013868587711693414, 4.4620645681803275e-05], "sd": 4.891152042204878e-05, "nfeat": 14}
9
+ {"name": "tx_f3", "cut": 23, "seed": 0, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7956304922619755, "d_vs_ctrl": 8.505379856571516e-05, "ci": [-4.9795107496017343e-05, 0.00022870341233730828], "sd": 7.476699867419253e-05, "nfeat": 20}
10
+ {"name": "tx_f4", "cut": 23, "seed": 0, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7956183987133403, "d_vs_ctrl": 7.296024993053152e-05, "ci": [-3.4362482472535814e-05, 0.0001534660315574921], "sd": 4.601110414256159e-05, "nfeat": 6}
11
+ {"name": "tx_all", "cut": 23, "seed": 0, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7956668950159012, "d_vs_ctrl": 0.00012145655249140574, "ci": [-4.162412313422625e-05, 0.0002827905883446003], "sd": 8.632411276152597e-05, "nfeat": 60}
12
+ {"name": "tx_all+prop", "cut": 23, "seed": 0, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7958353874293667, "d_vs_ctrl": 0.0002899489659569099, "ci": [0.00012652061304543327, 0.00046809093858551367], "sd": 8.882145961222389e-05, "nfeat": 88}
13
+ {"name": "tx_f1", "cut": 25, "seed": 1, "base": 0.8172259475835104, "control": 0.8172012726289022, "test": 0.8171540011704558, "d_vs_ctrl": -4.7271458446407344e-05, "ci": [-0.00019061083887653984, 9.264123771784986e-05], "sd": 8.080654707256493e-05, "nfeat": 20}
14
+ {"name": "tx_f2", "cut": 25, "seed": 1, "base": 0.8172259475835104, "control": 0.8172012726289022, "test": 0.8173168932756604, "d_vs_ctrl": 0.00011562064675818551, "ci": [3.137035239061392e-05, 0.0002165138368945774], "sd": 4.745692855025363e-05, "nfeat": 14}
15
+ {"name": "tx_f3", "cut": 25, "seed": 1, "base": 0.8172259475835104, "control": 0.8172012726289022, "test": 0.8173267896762714, "d_vs_ctrl": 0.00012551704736918357, "ci": [-1.1038759591067149e-05, 0.0002785910167285549], "sd": 7.539173816284816e-05, "nfeat": 20}
16
+ {"name": "tx_f4", "cut": 25, "seed": 1, "base": 0.8172259475835104, "control": 0.8172012726289022, "test": 0.8172492119677455, "d_vs_ctrl": 4.793933884328361e-05, "ci": [-4.7446992155203425e-05, 0.00013619981497832174], "sd": 4.878073514728382e-05, "nfeat": 6}
17
+ {"name": "tx_all", "cut": 25, "seed": 1, "base": 0.8172259475835104, "control": 0.8172012726289022, "test": 0.817286679273291, "d_vs_ctrl": 8.540664438883017e-05, "ci": [-9.598281369740669e-05, 0.00025745601599898863], "sd": 8.95598780600043e-05, "nfeat": 60}
18
+ {"name": "tx_all+prop", "cut": 25, "seed": 1, "base": 0.8172259475835104, "control": 0.8172012726289022, "test": 0.8173714409684247, "d_vs_ctrl": 0.00017016833952254729, "ci": [9.941956942391419e-06, 0.00032593622615555433], "sd": 8.941576662609524e-05, "nfeat": 88}
dw_lb/run_p4.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lib import *
2
+ import sys
3
+ out=[]
4
+ for c in (25,23):
5
+ F=load_cut(c); P=np.load(f'cache_prop_c{c}.npy'); names=json.load(open('prop_names.json')); y,z,u=F['y'],F['z'],F['user']
6
+ n=len(y)//10; Z=z.reshape(n,10); Y=y.reshape(n,10); ey=Y.max(1); eu=u[::10]
7
+ lse=np.log(np.exp(Z).sum(1)); sm=np.exp(Z-lse[:,None])/1 ; mx=Z.max(1); P1=P[::10]
8
+ def ev(f): return A(ey,f)
9
+ ctx=np.column_stack([lse,mx,Z.mean(1),Z.std(1),np.sort(Z,1)[:,-2]])
10
+ def evlgb(X,rounds=150):
11
+ o=np.zeros(n);
12
+ for tr,te in GroupKFold(5).split(X,ey,eu):
13
+ m=lgb.train({**PI,'min_data_in_leaf':200,'num_leaves':7},lgb.Dataset(X[tr],ey[tr]),rounds); o[te]=m.predict(X[te],raw_score=True)
14
+ return o
15
+ r=dict(cut=c,ev_lse=ev(lse),ev_max=ev(mx))
16
+ o1=evlgb(ctx); o2=evlgb(np.hstack([ctx,P1])); r.update(ev_ctx=ev(o1),ev_ctx_prop=ev(o2))
17
+ # 2-stage global score: logit of P(click_j)=P(ev)*softmax_j
18
+ lp=lambda o:(np.log(1/(1+np.exp(-o)))[:,None]+Z-lse[:,None]).ravel()
19
+ for nm,o in (('ctx',o1),('ctx_prop',o2)):
20
+ s=lp(o); r['glob_'+nm]=A(y,s)
21
+ r['glob_z']=A(y,z)
22
+ # oracle softmax with perfect event label
23
+ r['glob_oracle_ev']=A(y,(np.log(np.clip(np.repeat(ey,10),1e-3,1))+ (Z-lse[:,None]).ravel()))
24
+ print(json.dumps({k:(round(v,5) if isinstance(v,float) else v) for k,v in r.items()}),flush=True); open('results_p4.jsonl','a').write(json.dumps(r)+'\n')
dw_lb/run_prop.log ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ 25 (439640, 28)
2
+ {"name": "null_event_noise", "cut": 25, "nfeat": 1, "base": 0.81723, "control": 0.81722, "test": 0.81716, "d_vs_z": -7e-05, "d_vs_ctrl": -6e-05, "ci_vs_ctrl": [-0.00010993807087290585, -7.890079290281935e-06], "sd": 3e-05, "evAUC_base": 0.66805, "evAUC_test": 0.66566}
3
+ {"name": "prop_all", "cut": 25, "nfeat": 28, "base": 0.81723, "control": 0.81722, "test": 0.81742, "d_vs_z": 0.00019, "d_vs_ctrl": 0.0002, "ci_vs_ctrl": [8.425431766705683e-05, 0.00032945002107639954], "sd": 6e-05, "evAUC_base": 0.66805, "evAUC_test": 0.66715}
4
+ 23 (501550, 28)
5
+ {"name": "null_event_noise", "cut": 23, "nfeat": 1, "base": 0.79566, "control": 0.79555, "test": 0.79555, "d_vs_z": -0.00011, "d_vs_ctrl": 0.0, "ci_vs_ctrl": [-6.393072952146084e-05, 7.37865104797425e-05], "sd": 4e-05, "evAUC_base": 0.64445, "evAUC_test": 0.64411}
6
+ {"name": "prop_all", "cut": 23, "nfeat": 28, "base": 0.79566, "control": 0.79555, "test": 0.79581, "d_vs_z": 0.00015, "d_vs_ctrl": 0.00026, "ci_vs_ctrl": [0.00011603082194248937, 0.000432235776237011], "sd": 8e-05, "evAUC_base": 0.64445, "evAUC_test": 0.64796}
dw_lb/run_prop.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from lib import *
2
+ rng=np.random.RandomState(0)
3
+ for c in (25,23):
4
+ F=load_cut(c); P=np.load(f'cache_prop_c{c}.npy'); names=json.load(open('prop_names.json'))
5
+ print(c,P.shape,flush=True)
6
+ noise=np.repeat(rng.randn(len(F['y'])//10,1).astype(np.float32),10,1).reshape(-1,1)
7
+ report('null_event_noise',F,noise)
8
+ report('prop_all',F,P)
dw_lb/run_tx.log ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"name": "tx_f1", "cut": 25, "seed": 0, "base": 0.81723, "control": 0.81722, "test": 0.8172, "d_vs_ctrl": -2e-05, "ci": [-0.00014349266344125257, 0.00014587432118149673], "sd": 7e-05, "nfeat": 20}
2
+ {"name": "tx_f2", "cut": 25, "seed": 0, "base": 0.81723, "control": 0.81722, "test": 0.81735, "d_vs_ctrl": 0.00013, "ci": [3.9790617533291826e-05, 0.00023067132830789097], "sd": 5e-05, "nfeat": 14}
3
+ {"name": "tx_f3", "cut": 25, "seed": 0, "base": 0.81723, "control": 0.81722, "test": 0.81732, "d_vs_ctrl": 0.0001, "ci": [-5.4981787659713624e-05, 0.00021526865679996352], "sd": 7e-05, "nfeat": 20}
4
+ {"name": "tx_f4", "cut": 25, "seed": 0, "base": 0.81723, "control": 0.81722, "test": 0.81725, "d_vs_ctrl": 3e-05, "ci": [-5.4703244326295694e-05, 0.00011614454119170672], "sd": 4e-05, "nfeat": 6}
5
+ {"name": "tx_all", "cut": 25, "seed": 0, "base": 0.81723, "control": 0.81722, "test": 0.81732, "d_vs_ctrl": 0.0001, "ci": [-7.801107898108007e-05, 0.00023711497566265008], "sd": 9e-05, "nfeat": 60}
6
+ {"name": "tx_all+prop", "cut": 25, "seed": 0, "base": 0.81723, "control": 0.81722, "test": 0.8174, "d_vs_ctrl": 0.00018, "ci": [-5.831556720231612e-06, 0.00032584640888283224], "sd": 9e-05, "nfeat": 88}
7
+ {"name": "tx_f1", "cut": 23, "seed": 0, "base": 0.79566, "control": 0.79555, "test": 0.79562, "d_vs_ctrl": 8e-05, "ci": [-7.479367148836014e-05, 0.00026347507973854004], "sd": 8e-05, "nfeat": 20}
8
+ {"name": "tx_f2", "cut": 23, "seed": 0, "base": 0.79566, "control": 0.79555, "test": 0.79549, "d_vs_ctrl": -5e-05, "ci": [-0.00013868587711693414, 4.4620645681803275e-05], "sd": 5e-05, "nfeat": 14}
9
+ {"name": "tx_f3", "cut": 23, "seed": 0, "base": 0.79566, "control": 0.79555, "test": 0.79563, "d_vs_ctrl": 9e-05, "ci": [-4.9795107496017343e-05, 0.00022870341233730828], "sd": 7e-05, "nfeat": 20}
10
+ {"name": "tx_f4", "cut": 23, "seed": 0, "base": 0.79566, "control": 0.79555, "test": 0.79562, "d_vs_ctrl": 7e-05, "ci": [-3.4362482472535814e-05, 0.0001534660315574921], "sd": 5e-05, "nfeat": 6}
11
+ {"name": "tx_all", "cut": 23, "seed": 0, "base": 0.79566, "control": 0.79555, "test": 0.79567, "d_vs_ctrl": 0.00012, "ci": [-4.162412313422625e-05, 0.0002827905883446003], "sd": 9e-05, "nfeat": 60}
12
+ {"name": "tx_all+prop", "cut": 23, "seed": 0, "base": 0.79566, "control": 0.79555, "test": 0.79584, "d_vs_ctrl": 0.00029, "ci": [0.00012652061304543327, 0.00046809093858551367], "sd": 9e-05, "nfeat": 88}
dw_lb/run_tx.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lib import *
2
+ import sys
3
+ cuts=[int(x) for x in sys.argv[1].split(',')]; seeds=[int(x) for x in sys.argv[2].split(',')]
4
+ names=json.load(open('tx_names.json')); fam={f:[i for i,n in enumerate(names) if n.startswith(f)] for f in ['f1','f2','f3','f4']}
5
+ sets=dict(f1=fam['f1'],f2=fam['f2'],f3=fam['f3'],f4=fam['f4'],all=list(range(len(names))))
6
+ for c in cuts:
7
+ F=load_cut(c); T=np.load(f'cache_tx_c{c}.npy'); P=np.load(f'cache_prop_c{c}.npy'); y,z,u=F['y'],F['z'],F['user']
8
+ for s in seeds:
9
+ pc=oof(F['Xb'],y,z,u,s);
10
+ for nm,idx in list(sets.items())+[('all+prop',None)]:
11
+ X=np.hstack([F['Xb'],T if idx is None else T[:,idx]]+([P] if idx is None else []))
12
+ pt=oof(X,y,z,u,s); ci,sd=boot_delta(y,pc,pt,None,nb=150)
13
+ r=dict(name='tx_'+nm,cut=c,seed=s,base=A(y,z),control=A(y,pc),test=A(y,pt),d_vs_ctrl=A(y,pt)-A(y,pc),ci=[float(ci[0]),float(ci[1])],sd=float(sd),nfeat=X.shape[1]-F['Xb'].shape[1])
14
+ print(json.dumps({k:(round(v,5) if isinstance(v,float) else v) for k,v in r.items()}),flush=True); open('results_tx.jsonl','a').write(json.dumps(r)+'\n')
dw_lb/run_tx_s1.log ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {"name": "tx_f1", "cut": 25, "seed": 1, "base": 0.81723, "control": 0.8172, "test": 0.81715, "d_vs_ctrl": -5e-05, "ci": [-0.00019061083887653984, 9.264123771784986e-05], "sd": 8e-05, "nfeat": 20}
2
+ {"name": "tx_f2", "cut": 25, "seed": 1, "base": 0.81723, "control": 0.8172, "test": 0.81732, "d_vs_ctrl": 0.00012, "ci": [3.137035239061392e-05, 0.0002165138368945774], "sd": 5e-05, "nfeat": 14}
3
+ {"name": "tx_f3", "cut": 25, "seed": 1, "base": 0.81723, "control": 0.8172, "test": 0.81733, "d_vs_ctrl": 0.00013, "ci": [-1.1038759591067149e-05, 0.0002785910167285549], "sd": 8e-05, "nfeat": 20}
4
+ {"name": "tx_f4", "cut": 25, "seed": 1, "base": 0.81723, "control": 0.8172, "test": 0.81725, "d_vs_ctrl": 5e-05, "ci": [-4.7446992155203425e-05, 0.00013619981497832174], "sd": 5e-05, "nfeat": 6}
5
+ {"name": "tx_all", "cut": 25, "seed": 1, "base": 0.81723, "control": 0.8172, "test": 0.81729, "d_vs_ctrl": 9e-05, "ci": [-9.598281369740669e-05, 0.00025745601599898863], "sd": 9e-05, "nfeat": 60}
6
+ {"name": "tx_all+prop", "cut": 25, "seed": 1, "base": 0.81723, "control": 0.8172, "test": 0.81737, "d_vs_ctrl": 0.00017, "ci": [9.941956942391419e-06, 0.00032593622615555433], "sd": 9e-05, "nfeat": 88}
dw_lb/sm25.log ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ c25 ep0 loss 1.9891 val AUC logP 0.60193 t=6s
2
+ c25 ep1 loss 1.9703 val AUC logP 0.59845 t=10s
3
+ c25 ep2 loss 1.8355 val AUC logP 0.59332 t=13s
4
+ c25 ep3 loss 1.6177 val AUC logP 0.58636 t=17s
5
+ c25 ep4 loss 1.3677 val AUC logP 0.58078 t=20s
6
+ c25 ep5 loss 1.0478 val AUC logP 0.57815 t=24s
dw_lb/tx25.log ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ 25 (439640, 60)
2
+ 23 (501550, 60)
dw_lb/tx_names.json ADDED
@@ -0,0 +1 @@
 
 
1
+ ["f1_cnt", "f1_cnt_h1", "f1_cnt_h6", "f1_cnt_h6_raw", "f1_cnt_h24", "f1_late_exp", "f1_late_ctr", "f1_ratio_late", "f1_ratio_all", "f1_exp_x_ctr", "f1_cnt_z", "f1_cnt_dm", "f1_cnt_rk", "f1_cnt_h6_z", "f1_cnt_h6_dm", "f1_cnt_h6_rk", "f1_ratio_late_z", "f1_ratio_late_dm", "f1_ratio_late_rk", "f1_slate_mean", "f3_hpop", "f3_hpop_l3", "f3_hpop_l1", "f3_hpost", "f3_hrecent_6h", "f3_hnext_6h", "f3_hrecent_24h", "f3_hnext_24h", "f3_own_cnt", "f3_hpop_excl_own", "f3_hpop_z", "f3_hpop_dm", "f3_hpop_rk", "f3_hpost_z", "f3_hpost_dm", "f3_hpost_rk", "f3_hrecent_24h_z", "f3_hrecent_24h_dm", "f3_hrecent_24h_rk", "f3_hpost_vs_train_ctr", "f2_cooc_norm", "f2_cooc_raw", "f2_lastshare_n", "f2_lastshare", "f2_l3share", "f2_cooc_norm_z", "f2_cooc_norm_dm", "f2_cooc_norm_rk", "f2_lastshare_z", "f2_lastshare_dm", "f2_lastshare_rk", "f2_l3share_z", "f2_l3share_dm", "f2_l3share_rk", "f4_trel_h", "f4_trank", "f4_n_same_h", "f4_n_6h", "f4_n_before_frac", "f4_hist_n"]
dw_levers/blend_div.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys, numpy as np, polars as pl, glob
2
+ sys.path.insert(0,'/workspace/huawei/dw_levers')
3
+ from common import z12, A, H
4
+ from scipy.stats import rankdata
5
+ for c in (25,23):
6
+ y=pl.read_parquet(f'{H}/v10/feat_v3/val{c}.parquet',columns=['clicked']).to_series().to_numpy().astype(int)
7
+ z=z12(c); print(f'== C{c} z12 {A(y,z):.5f}')
8
+ M={}
9
+ for f in sorted(glob.glob(f'{H}/v12/ens/*_c{c}_s*.npy')):
10
+ a=np.load(f); nm=f.split('/')[-1][:-4]
11
+ if a.ndim==1: a=a[:,None]
12
+ for k in range(a.shape[1]): M[f'{nm}[{k}]']=a[:,k]
13
+ for nm,a in M.items():
14
+ if np.isnan(a).any() or len(a)!=len(y): continue
15
+ r=A(y,a);
16
+ if r<0.7: continue
17
+ # incremental: best w in z + w*zscore(a)
18
+ zs=(a-a.mean())/a.std(); best=max((A(y,z+w*zs*z.std()),w) for w in (0,0.05,0.1,0.2,0.4))
19
+ print(f' {nm:18s} AUC {r:.5f} corr(z) {np.corrcoef(z,a)[0,1]:.3f} best blend {best[0]-A(y,z):+.5f} w={best[1]}')
dw_levers/cfg1.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {"d":32,"ep":3,"lr":0.001}
2
+ {"d":32,"ep":3,"lr":0.001,"l2":0.01}
3
+ {"d":32,"ep":3,"lr":0.001,"l2":0.1}
4
+ {"d":32,"ep":3,"lr":0.001,"hist_drop":0.3,"l2":0.01}
5
+ {"d":32,"ep":3,"lr":0.001,"att":true,"l2":0.01}
6
+ {"d":64,"ep":3,"lr":0.001,"l2":0.03}
dw_levers/cfg2.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {"d":32,"ep":6,"lr":0.003,"elr":0.0}
2
+ {"d":32,"ep":6,"lr":0.003,"elr":0.05}
3
+ {"d":32,"ep":6,"lr":0.003,"elr":0.15,"hist_drop":0.2}
dw_levers/choice.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Choice model with outside option (CPU PyTorch). P(click i | slate) = exp(s_i)/(exp(o)+sum_j exp(s_j)), s_i=<u,E_i>+b_i,
2
+ u = sum_h w(age_h) * Eh[h] / n^a (+ optional free user vec). Trained on train events with ts<X only (+ their own pre-ts histories).
3
+ Entry points: fit_choice(D,X,cfg) -> model ; score(model,D,ev_idx) -> (n,10) log-prob (and (n,) log p_none)"""
4
+ import numpy as np, torch, torch.nn as nn, time, sys
5
+ sys.path.insert(0,'/workspace/huawei/dw_levers')
6
+ from dwcommon import *
7
+ from common import A
8
+ torch.set_num_threads(4)
9
+ HL=20
10
+ def build_hist(D):
11
+ if hasattr(D,'H'): return
12
+ n=D.NE; H=np.full((n,HL),D.NI,np.int32); G=np.zeros((n,HL),np.int8)
13
+ rows=np.repeat(np.arange(n),D.Hlen); cols=np.arange(len(D.HI))-np.repeat(D.OFF[:-1],D.Hlen)
14
+ H[rows,cols]=D.HI; gap=np.maximum(D.ETS[rows]-D.HT,60)
15
+ G[rows,cols]=1+np.clip(np.log2(gap/60),0,19).astype(np.int8)
16
+ D.H=H; D.G=G
17
+ class CM(nn.Module):
18
+ def __init__(s,NI,NU,V0,d,free_user,att):
19
+ super().__init__(); s.NI=NI
20
+ s.E=nn.Embedding(NI+1,d,padding_idx=NI); s.Eh=nn.Embedding(NI+1,d,padding_idx=NI); s.b=nn.Embedding(NI+1,1,padding_idx=NI)
21
+ with torch.no_grad():
22
+ k=V0.shape[1]; E0=torch.randn(NI+1,d)*0.01; E0[:NI,:k]=torch.from_numpy(V0); E0[NI]=0
23
+ s.E.weight.copy_(E0); s.Eh.weight.copy_(E0); s.b.weight.zero_()
24
+ s.gw=nn.Embedding(HL+2,1); nn.init.zeros_(s.gw.weight) # age weight logits
25
+ s.scale=nn.Parameter(torch.tensor(3.0)); s.alpha=nn.Parameter(torch.tensor(0.5))
26
+ s.free=nn.Embedding(NU,d) if free_user else None
27
+ if free_user: nn.init.zeros_(s.free.weight)
28
+ s.att=att
29
+ if att: s.Wq=nn.Linear(d,d,bias=False); nn.init.eye_(s.Wq.weight)
30
+ s.out=nn.Sequential(nn.Linear(4,16),nn.ReLU(),nn.Linear(16,1)) # outside logit from user/ctx stats
31
+ s.ob=nn.Embedding(NU,1) if free_user else None
32
+ if free_user: nn.init.zeros_(s.ob.weight)
33
+ def forward(s,H,G,cand,u,ctx):
34
+ valid=(H!=s.NI).float(); nh=valid.sum(1,keepdim=True)
35
+ eh=s.Eh(H); w=torch.sigmoid(s.gw(G.long()).squeeze(-1)+1.0)*valid # (B,T)
36
+ q=s.E(cand) # (B,10,d)
37
+ if s.att:
38
+ a=torch.einsum('bcd,btd->bct',s.Wq(q),eh)/eh.shape[-1]**0.5*s.scale; a=a.masked_fill(valid[:,None,:]==0,-1e9)
39
+ wt=torch.softmax(a,-1)*(nh>0).float()[:,:,None]; ur=torch.einsum('bct,btd->bcd',wt*w[:,None,:],eh) # per-candidate user rep
40
+ sc=(ur*q).sum(-1)*s.scale/ (w.sum(1,keepdim=True)+1e-3).clamp(min=1)**0.0
41
+ else:
42
+ ur=(eh*w[:,:,None]).sum(1)/(nh+1.0)**s.alpha # (B,d)
43
+ if s.free is not None: ur=ur+s.free(u)
44
+ sc=torch.einsum('bd,bcd->bc',ur,q)*s.scale
45
+ sc=sc+s.b(cand).squeeze(-1)
46
+ f=torch.cat([torch.log1p(nh),ctx],1) # ctx: (B,3)
47
+ o=s.out(f)+(s.ob(u) if s.ob is not None else 0)
48
+ return sc,o.squeeze(-1)
49
+ def ctx_feats(D,ev):
50
+ tb=((D.ETS[ev]-J20)%DAY)/DAY; dt=(((D.ETS[ev]-J20)//DAY))%7/7.0
51
+ nlast=np.where(D.Hlen[ev]>0,D.G[ev].max(1),0)/20.0 # gap-bucket of the oldest? (crude recency) -> use min nonzero below
52
+ G=D.G[ev].astype(np.float32); G[G==0]=99; rec=np.where(D.Hlen[ev]>0,G.min(1),0)/20.0
53
+ return np.stack([tb,dt,rec],1).astype(np.float32)
54
+ def fit_choice(D,X,cfg,log_every=1,val=None):
55
+ build_hist(D); t0=time.time(); torch.manual_seed(cfg.get('seed',0)); np.random.seed(cfg.get('seed',0))
56
+ nX=int(np.searchsorted(D.ETS,X)); idx=np.arange(nX)
57
+ d=cfg.get('d',32); S=D.snap(X); V0,_=click_svd(S,D,k=min(d,cfg.get('k',32))); log('svd done')
58
+ V0=V0*cfg.get('v0scale',1.0)
59
+ m=CM(D.NI,D.NU,V0,d,cfg.get('free_user',False),cfg.get('att',False))
60
+ tH=torch.from_numpy(D.H.astype(np.int64)); tG=torch.from_numpy(D.G.astype(np.int64)); tC=torch.from_numpy(D.RI.astype(np.int64)); tU=torch.from_numpy(D.EU.astype(np.int64))
61
+ ctx=torch.from_numpy(ctx_feats(D,np.arange(D.NE)))
62
+ yidx=np.where(D.Y.sum(1)>0,D.Y.argmax(1),10); tY=torch.from_numpy(yidx.astype(np.int64))
63
+ opt=torch.optim.Adam([{'params':[p for n_,p in m.named_parameters() if n_.split('.')[0] not in ('free','ob','E','Eh','b')]},
64
+ {'params':list(m.E.parameters())+list(m.Eh.parameters())+list(m.b.parameters()),'weight_decay':0.0,'lr':cfg.get('lr',2e-3)*cfg.get('elr',1.0)},
65
+ {'params':(list(m.free.parameters())+list(m.ob.parameters())) if m.free is not None else [],'weight_decay':0.0}],lr=cfg.get('lr',2e-3))
66
+ bs=cfg.get('bs',512); wd=cfg.get('l2',0.0); fl2=cfg.get('free_l2',1e-4); ep=cfg.get('ep',4); hid=cfg.get('hist_drop',0.0)
67
+ # held-out tail of fit window for early stopping (last 5% of events by time)
68
+ ntr=int(nX*0.95); hold=np.arange(ntr,nX); idx=np.arange(ntr)
69
+ best=(1e9,None)
70
+ for e in range(ep):
71
+ m.train(); perm=torch.from_numpy(np.random.permutation(idx)); tl=0; nb=0
72
+ for b in range(0,len(perm),bs):
73
+ j=perm[b:b+bs]; H=tH[j]
74
+ if hid>0: H=torch.where(torch.rand(H.shape)<hid,torch.full_like(H,D.NI),H)
75
+ sc,o=m(H,tG[j],tC[j],tU[j],ctx[j]); lg=torch.cat([sc,o[:,None]],1); loss=nn.functional.cross_entropy(lg,tY[j])
76
+ if wd>0:
77
+ loss=loss+wd*((m.E(tC[j])**2).sum(-1).mean()+(m.Eh(H)**2).sum(-1).mean())
78
+ if m.free is not None and fl2>0: loss=loss+fl2*(m.free(tU[j])**2).sum(-1).mean()
79
+ opt.zero_grad(); loss.backward(); opt.step(); tl+=loss.item(); nb+=1
80
+ m.eval(); hl=eval_loss(m,D,hold,tH,tG,tC,tU,ctx,tY); msg=f' ep{e} train {tl/nb:.4f} hold {hl:.4f} {time.time()-t0:.0f}s'
81
+ if val is not None:
82
+ lp,_=score(m,D,val['e'][::10],tH,tG,tC,tU,ctx); lp=to_val(lp,val['col']); msg+=f" valAUC {A(val['y'],lp.ravel()):.5f}"
83
+ log(msg)
84
+ if hl<best[0]: best=(hl,{k:v.clone() for k,v in m.state_dict().items()})
85
+ m.load_state_dict(best[1]); m.eval(); m.cache=(tH,tG,tC,tU,ctx); return m
86
+ @torch.no_grad()
87
+ def eval_loss(m,D,ev,tH,tG,tC,tU,ctx,tY):
88
+ tot=0
89
+ for b in range(0,len(ev),8192):
90
+ j=torch.from_numpy(ev[b:b+8192]); sc,o=m(tH[j],tG[j],tC[j],tU[j],ctx[j]); tot+=nn.functional.cross_entropy(torch.cat([sc,o[:,None]],1),tY[j],reduction='sum').item()
91
+ return tot/len(ev)
92
+ @torch.no_grad()
93
+ def score(m,D,ev,tH=None,tG=None,tC=None,tU=None,ctx=None):
94
+ if tH is None: tH,tG,tC,tU,ctx=m.cache
95
+ out=[];on=[]
96
+ for b in range(0,len(ev),8192):
97
+ j=torch.from_numpy(np.asarray(ev[b:b+8192])); sc,o=m(tH[j],tG[j],tC[j],tU[j],ctx[j]); lg=torch.cat([sc,o[:,None]],1); lp=torch.log_softmax(lg,1); out.append(lp[:,:10].numpy()); on.append(lp[:,10].numpy())
98
+ return np.concatenate(out),np.concatenate(on)
99
+ def align(D,v):
100
+ """column index (n,10) such that val row (event r, pos p) == D.RI[e_r, col[r,p]]"""
101
+ ev=v['e'][::10]; n=len(ev); RI=D.RI[ev]; vi=v['item'].reshape(n,10)
102
+ pd_=np.argsort(RI,1,kind='stable'); ov=np.argsort(vi,1,kind='stable')
103
+ assert (np.take_along_axis(RI,pd_,1)==np.take_along_axis(vi,ov,1)).all()
104
+ col=np.zeros((n,10),np.int64); np.put_along_axis(col,ov,pd_,1); return col
105
+ def to_val(lp,col): return np.take_along_axis(lp,col,1)
dw_levers/choice_sweep.jsonl ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {"cfg": {"d": 32, "ep": 3, "lr": 0.001}, "cut": 25, "auc": 0.7776973973402646, "blend": {"0.1": -8e-05, "0.2": -0.00076, "0.4": -0.00295}}
2
+ {"cfg": {"d": 32, "ep": 3, "lr": 0.001, "l2": 0.01}, "cut": 25, "auc": 0.777737651041082, "blend": {"0.1": -8e-05, "0.2": -0.00075, "0.4": -0.00294}}
3
+ {"cfg": {"d": 32, "ep": 3, "lr": 0.001, "l2": 0.1}, "cut": 25, "auc": 0.7778433663501874, "blend": {"0.1": -7e-05, "0.2": -0.00071, "0.4": -0.00281}}
4
+ {"cfg": {"d": 32, "ep": 3, "lr": 0.001, "hist_drop": 0.3, "l2": 0.01}, "cut": 25, "auc": 0.775251609736144, "blend": {"0.1": -0.00018, "0.2": -0.00114, "0.4": -0.004}}
5
+ {"cfg": {"d": 32, "ep": 3, "lr": 0.001, "att": true, "l2": 0.01}, "cut": 25, "auc": 0.768316048958352, "blend": {"0.1": -8e-05, "0.2": -0.00059, "0.4": -0.00232}}
6
+ {"cfg": {"d": 64, "ep": 3, "lr": 0.001, "l2": 0.03}, "cut": 25, "auc": 0.7772370992714306, "blend": {"0.1": -7e-05, "0.2": -0.00076, "0.4": -0.00298}}
7
+ {"cfg": {"d": 32, "ep": 6, "lr": 0.003, "elr": 0.0}, "cut": 25, "auc": 0.7527770901981062, "blend": {"0.1": -0.00053, "0.2": -0.00182, "0.4": -0.00551}}
8
+ {"cfg": {"d": 32, "ep": 6, "lr": 0.003, "elr": 0.05}, "cut": 25, "auc": 0.7696136210745811, "blend": {"0.1": -0.00039, "0.2": -0.00168, "0.4": -0.00529}}
9
+ {"cfg": {"d": 32, "ep": 6, "lr": 0.003, "elr": 0.15, "hist_drop": 0.2}, "cut": 25, "auc": 0.766880051741821, "blend": {"0.1": -0.00038, "0.2": -0.00157, "0.4": -0.00497}}
dw_levers/common.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np, polars as pl
2
+ from sklearn.metrics import roc_auc_score as A
3
+ H='/workspace/huawei'
4
+ def z12(c):
5
+ s=lambda t,k:np.load(f'{H}/v12/ens/{t}_c{c}_s0.npy')[:,k]
6
+ m=np.mean([np.load(f'{H}/v12/ens/dwmlp_c{c}_s{k}.npy')[:,3] for k in (range(3) if c!=26 else [0])],0)
7
+ return ((s('dwbig',1)+s('dw_s',1)+2*m)/4).astype(np.float64)
8
+ def meta(c):
9
+ return pl.read_parquet(f'{H}/v10/feat_v3/val{c}.parquet',columns=['rowid','eid','u','ts','clicked','tm_stale'])
10
+ def stale_hours(c):
11
+ return None
12
+ def fastauc(y,s):
13
+ return A(y,s)
dw_levers/decomp.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"25": {"cut": 25, "events": 43964, "pos": 27852, "ev_click_rate": 0.6335183331816941, "auc": 0.8172259475835104, "within_pair_share": 2.1855906437292975e-05, "auc_within_pooled": 0.8258040087760128, "auc_global_soft": 0.8110968754468042, "auc_event_lse": 0.6680507246702352, "auc_event_pany": 0.672879467007552, "auc_global_lse_only": 0.5657530883825374, "auc_pos_vs_negNoClickEv": 0.8117911215809311, "auc_pos_vs_negClickEv(incl same)": 0.8207192501412185, "n_neg_noclick": 161120, "n_neg_click": 250668, "oracle_event_label": 0.8908663025498532, "oracle_event_label_only": 0.695634646954258, "oracle_within": 1.0, "oracle_within_delta1": 0.9911582433074853, "oracle_within_delta2": 0.9999964869142365, "oracle_within_delta3": 1.0, "oracle_noclick_shift0.5": 0.8436367361165743, "oracle_noclick_shift1": 0.8625684532677933, "oracle_noclick_shift2": 0.882637173319801, "z+-0.5lse": 0.8159626553877453, "z+-0.25lse": 0.81702514306448, "z+0.25lse": 0.8166164911142868, "z+0.5lse": 0.8152550994949205}, "23": {"cut": 23, "events": 50155, "pos": 31556, "ev_click_rate": 0.6291695743196092, "auc": 0.7956557773874656, "within_pair_share": 1.9149180627837803e-05, "auc_within_pooled": 0.8042889361940629, "auc_global_soft": 0.7899638895663363, "auc_event_lse": 0.644454956712242, "auc_event_pany": 0.6498087959114907, "auc_global_lse_only": 0.5571649369968763, "auc_pos_vs_negNoClickEv": 0.789327452198109, "auc_pos_vs_negClickEv(incl same)": 0.7998001035306483, "n_neg_noclick": 185990, "n_neg_click": 284004, "oracle_event_label": 0.8790248994734363, "oracle_event_label_only": 0.6978642280539751, "oracle_within": 1.0, "oracle_within_delta1": 0.9920346074971375, "oracle_within_delta2": 0.9999991132840579, "oracle_within_delta3": 1.0, "oracle_noclick_shift0.5": 0.8244924136958571, "oracle_noclick_shift1": 0.8456763409444128, "oracle_noclick_shift2": 0.8689719891540698, "z+-0.5lse": 0.7945047642660293, "z+-0.25lse": 0.7954959693422332, "z+0.25lse": 0.7950221704013974, "z+0.5lse": 0.7936385446708382}}
dw_levers/decomp.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np, json
2
+ from common import *
3
+ out={}
4
+ for c in (25,23):
5
+ m=meta(c); y=m['clicked'].to_numpy(); z=z12(c); n=len(y)//10
6
+ assert (m['eid'].to_numpy().reshape(n,10)==m['eid'].to_numpy().reshape(n,10)[:,:1]).all()
7
+ Y=y.reshape(n,10); Z=z.reshape(n,10); yev=Y.max(1); P=y.sum(); N=len(y)-P
8
+ lse=np.log(np.exp(Z).sum(1)); soft=Z-lse[:,None]
9
+ r=dict(cut=c,events=n,pos=int(P),ev_click_rate=float(yev.mean()),auc=A(y,z))
10
+ # pair counts
11
+ npos_ev=Y.sum(1); within=int((npos_ev*(10-npos_ev)).sum()); total=int(P*N)
12
+ r['within_pair_share']=within/total
13
+ # within-event AUC (pooled over click events)
14
+ ce=yev==1
15
+ r['auc_within_pooled']=A(Y[ce].ravel(),soft[ce].ravel()) # same as z within-event since subtracting const
16
+ # mean per-event AUC
17
+ r['auc_global_soft']=A(y,soft.ravel())
18
+ r['auc_event_lse']=A(yev,lse); r['auc_event_pany']=A(yev,np.log1p(-np.prod(1-1/(1+np.exp(-Z)),1)*0.9999999))
19
+ r['auc_global_lse_only']=A(y,np.repeat(lse,10))
20
+ # between-event split: negatives from no-click events vs click events(other events)
21
+ # AUC of pos vs negs in no-click events
22
+ pos_s=z[y==1];
23
+ negs_nc=Z[~ce].ravel(); negs_c=Z[ce].ravel() # includes pos in ce -> need only negatives
24
+ negs_c=Z[ce][Y[ce]==0]
25
+ from scipy.stats import rankdata
26
+ def auc2(p,q):
27
+ a=np.concatenate([p,q]); r_=rankdata(a); return (r_[:len(p)].sum()-len(p)*(len(p)+1)/2)/(len(p)*len(q))
28
+ r['auc_pos_vs_negNoClickEv']=auc2(pos_s,negs_nc); r['auc_pos_vs_negClickEv(incl same)']=auc2(pos_s,negs_c)
29
+ r['n_neg_noclick']=len(negs_nc); r['n_neg_click']=len(negs_c)
30
+ # oracles
31
+ r['oracle_event_label']=A(y,np.repeat(yev,10)*100+z) # perfect any-click, model within
32
+ r['oracle_event_label_only']=A(y,np.repeat(yev,10))
33
+ r['oracle_within']=A(y,np.where(y==1,1,0)*100+ (np.repeat(lse,10))*0 + np.repeat(lse,10)*0 + z*0+ np.repeat(lse,10)) # perfect within-ranking (clicked row top of event), event score lse as before
34
+ # perfect within, event score = softmax mass: row score = lse + big*y? use lse + y*delta (delta modest = within gap)
35
+ for dl in (1,2,3):
36
+ r[f'oracle_within_delta{dl}']=A(y,np.repeat(lse,10)+dl*y*(np.repeat(yev,10)))
37
+ # oracle on no-click events: those would be known as no-click, push down by k
38
+ for k in (0.5,1,2):
39
+ r[f'oracle_noclick_shift{k}']=A(y,z-k*np.repeat(1-yev,10))
40
+ # score mixing: z + a*lse
41
+ for a in (-0.5,-0.25,0.25,0.5):
42
+ r[f'z+{a}lse']=A(y,z+a*np.repeat(lse,10))
43
+ out[c]=r; print(json.dumps({k:(round(v,5) if isinstance(v,float) else v) for k,v in r.items()}),flush=True)
44
+ json.dump(out,open('decomp.json','w'))
dw_levers/dwcommon.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared loader for dw_signals. READ-ONLY on everything outside /workspace/huawei/dw_signals.
2
+ Snapshot(C): everything known from train events with ts < C (rows+labels of those events, plus click log reconstructed from their histories).
3
+ Val(C): each user's first event with ts in [C, Jan27) (rows in the same order as v10/feat_v3/val{C}.parquet == v11/ens/*_c{C}_*.npy rows)."""
4
+ import numpy as np, polars as pl, time, gc
5
+ from scipy.sparse import csr_matrix
6
+ from scipy.sparse.linalg import svds
7
+ L='/workspace/huawei/lite'; DAY=86400; J20=1737331200
8
+ def Jd(d): return J20+(d-20)*DAY
9
+ T0=time.time()
10
+ def log(*a): print(f'[{time.time()-T0:6.0f}s]',*a,flush=True)
11
+
12
+ class Data:
13
+ def __init__(s):
14
+ ev=pl.read_parquet(f'{L}/train_events.parquet').sort('ts').with_row_index('e')
15
+ rows=pl.read_parquet(f'{L}/train_rows.parquet').join(ev.select('eid','e'),on='eid').sort(['e','item'])
16
+ s.NE=ev.height; assert rows.height==s.NE*10
17
+ s.ETS=ev['ts'].to_numpy(); s.EID=ev['eid'].to_numpy()
18
+ uu,s.EU=np.unique(ev['user'].to_numpy(),return_inverse=True); s.EU=s.EU.astype(np.int32); s.NU=len(uu); s.uu=uu
19
+ s.Hlen=ev['h_items'].list.len().to_numpy().astype(np.int64)
20
+ s.OFF=np.zeros(s.NE+1,np.int64); s.OFF[1:]=np.cumsum(s.Hlen)
21
+ hi=ev['h_items'].explode().drop_nulls().to_numpy(); s.HT=ev['h_ts'].explode().drop_nulls().to_numpy().astype(np.int64)
22
+ rr=rows['item'].to_numpy()
23
+ s.items=np.unique(np.concatenate([np.unique(rr),np.unique(hi)])); s.NI=len(s.items)
24
+ s.HI=np.searchsorted(s.items,hi).astype(np.int32); s.RI=np.searchsorted(s.items,rr).astype(np.int32).reshape(s.NE,10)
25
+ s.Y=rows['clicked'].to_numpy().astype(np.int8).reshape(s.NE,10)
26
+ s.rowid=rows['rowid'].to_numpy().reshape(s.NE,10)
27
+ s.eid2e={} # not needed
28
+ s.ev=ev.select('e','eid','user','ts'); s.rows_rowid=rows.select('rowid','e','item')
29
+ del ev,rows; gc.collect()
30
+ def val(s,c):
31
+ """returns dict with aligned arrays for val cut c: rowid, y, e (event idx), j(row pos in event), item idx, user idx, ts"""
32
+ v=pl.read_parquet(f'/workspace/huawei/v10/feat_v3/val{c}.parquet',columns=['rowid','clicked'])
33
+ m=v.join(s.rows_rowid,on='rowid',how='left',maintain_order='left')
34
+ e=m['e'].to_numpy().astype(np.int64); it=np.searchsorted(s.items,m['item'].to_numpy()).astype(np.int32)
35
+ assert (e[::10]==e.reshape(-1,10)[:,0]).all() and (e.reshape(-1,10)==e.reshape(-1,10)[:,:1]).all()
36
+ return dict(rowid=v['rowid'].to_numpy(),y=v['clicked'].to_numpy().astype(np.int8),e=e,item=it,user=s.EU[e],ts=s.ETS[e])
37
+ def snap(s,X):
38
+ """click log (user,item,ts) from events with ts<X (dedup) + counts. returns dict"""
39
+ nX=int(np.searchsorted(s.ETS,X))
40
+ hu=np.repeat(s.EU[:nX],s.Hlen[:nX]); hi=s.HI[:s.OFF[nX]]; ht=s.HT[:s.OFF[nX]]
41
+ ce,cj=np.nonzero(s.Y[:nX]);
42
+ cu=np.concatenate([hu,s.EU[ce]]); ci=np.concatenate([hi,s.RI[ce,cj]]); ct=np.concatenate([ht,s.ETS[ce]])
43
+ tm=(ct-Jd(1))//60
44
+ key=np.unique((cu.astype(np.int64)*s.NI+ci)*(1<<20)+tm)
45
+ ui=key>>20; tm=key&((1<<20)-1)
46
+ return dict(nX=nX,cu=(ui//s.NI).astype(np.int32),ci=(ui%s.NI).astype(np.int32),ct=tm*60+Jd(1))
47
+
48
+ def click_svd(S,D,k=32):
49
+ """item/user taste vectors from dedup click log (binary, 1/sqrt((nu+1)(ni+1)) scaling). returns item vec (V*s) L2-normed, user vec"""
50
+ u,i=S['cu'],S['ci']; key=np.unique(u.astype(np.int64)*D.NI+i); uu=(key//D.NI).astype(np.int32); ii=(key%D.NI).astype(np.int32)
51
+ nu=np.bincount(uu,minlength=D.NU).astype(np.float32); ni=np.bincount(ii,minlength=D.NI).astype(np.float32)
52
+ M=csr_matrix((1/np.sqrt((nu[uu]+1)*(ni[ii]+1)),(uu,ii)),shape=(D.NU,D.NI),dtype=np.float32)
53
+ U,sv,Vt=svds(M,k=k,random_state=0)
54
+ V=(Vt.T*sv); V/= np.linalg.norm(V,axis=1,keepdims=True)+1e-9
55
+ return V.astype(np.float32),(U*sv).astype(np.float32)
56
+ def norm(x): return x/(np.linalg.norm(x,axis=-1,keepdims=True)+1e-9)
57
+ def event_view(a): return a.reshape(-1,10)
58
+ def within_event(x):
59
+ """z-score, demeaned, rank (0..9 ascending) within the 10-row events; x aligned with val rows"""
60
+ m=x.reshape(-1,10); mu=np.nanmean(m,1,keepdims=True); sd=np.nanstd(m,1,keepdims=True)+1e-6
61
+ rk=m.argsort(1).argsort(1).astype(np.float32)
62
+ return ((m-mu)/sd).ravel(),(m-mu).ravel(),rk.ravel()
63
+
64
+ V11='/workspace/huawei/v11'
65
+ def v11_pred(c):
66
+ a=np.load(f'{V11}/ens/sCbig_c{c}_s0.npy')[:,1]; b=np.load(f'{V11}/ens/sC_s_c{c}_s0.npy')[:,1]
67
+ m=np.mean([np.load(f'{V11}/ens/mlp2_c{c}_s{k}.npy')[:,3] for k in range(3)],0)
68
+ return (a+b+2*m)/4
69
+ def segs(c):
70
+ m=pl.read_parquet(f'/workspace/huawei/v10/feat_v3/val{c}.parquet',columns=['us_cold','us_nohist'])
71
+ st=pl.read_parquet(f'/workspace/huawei/v10/feat_tmB2/val{c}.parquet')['tmR_stale_h'].to_numpy()
72
+ return dict(nohist=m['us_nohist'].to_numpy(),cold=m['us_cold'].to_numpy(),stale=st)
dw_levers/findings.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # dw_levers findings (Europe/Dublin, 2026-10-28)
2
+ Baseline = v12 z12 blend (C25 0.81723, C23 0.79566). All numbers on val rows (user's first event after cutoff).
3
+
4
+ ## AUC decomposition (decomp.json)
5
+ | | C25 | C23 |
6
+ |---|---|---|
7
+ | Global AUC | 0.8172 | 0.7957 |
8
+ | Within-event pooled AUC | 0.8258 | 0.8043 |
9
+ | Event "any click" AUC of 1-prod(1-p) | 0.673 | 0.650 |
10
+ | Oracle event label + model within-event | 0.891 | 0.879 |
11
+ | Within-event pair share of all pairs | 2e-5 | 2e-5 |
12
+ Global AUC is almost entirely between-event, so it is set by cross-event calibration (a mix of item quality + event-level click propensity). Headroom sim (headroom_sim.json): event AUC 0.673->0.709 = +0.003, ->0.758 = +0.0075, ->0.80 ≈ +0.012. A +0.012 gain from the event lever alone needs event AUC ≈0.80 (from 0.67), not realistic: v13 exp1 event residual models were negative, my choice-model "no-click" head has event AUC 0.62 (<0.673).
13
+
14
+ ## Ranked levers (ΔAUC over z12, C25)
15
+ | # | lever | result |
16
+ |---|---|---|
17
+ | 1 | Event-level model (headroom + v13 + choice outside option) | long shot, needs event AUC +0.13; every attempt ≤0 |
18
+ | 2 | Choice model w/ outside option, PyTorch end-to-end (choice.py) | standalone 0.778 (lr1e-3, 1 epoch; best-by-holdout), blend with z: -0.0001 (w=.1) to -0.003 (w=.4); LGBM residual stacking with lp/slate-rank/outside logit vs control with only z-derived feats: +0.00008 [95% CI +0.00002,+0.00015] (event bootstrap) = negligible |
19
+ | 3 | Two-tower/seq/LightGCN | Not built separately: choice model is effectively this (SVD-init item/user-hist embeddings + softmax) and reached only 0.78; frozen SVD embeddings 0.753; attention 0.768; hist dropout / l2 / lr sweeps (sweep_choice.py, choice_sweep.jsonl) all 0.75-0.778 and overfit after 1 epoch (holdout loss min at epoch 0). Earlier DIN 0.534. Not worth blending |
20
+ | 4 | Rank/linear blend diversity (blend_div.py) | all 44 existing ens members (dw_s, dwbig, dwmlp, mlp2, sC, sCbig × seeds) correlate .97-.995 with z12; best incremental blend +0.00007 (dwbig seed1). Ensemble is saturated |
21
+ | 5 | Error analysis / cross-segment recalibration (seg.py, recal.py) | Per-segment Platt recalibration by us_hlen, it_imp, us_nev (+ crosses), user-grouped CV: Δ -0.0003..+0.00006 → score already calibrated across segments, no headroom |
22
+
23
+ Stale rows: `tm_stale` in val parquet is not hours (all >48), so C23 stale slice was not separable via it; no model in the ensemble or the choice model is better on any slice—ens members all correlated ≥.97.
24
+
25
+ ## Where the weakness is (AUC within segment)
26
+ C25: hist len ≤6: 0.755 (18% rows) vs hist 17-20: 0.836 (49%); users with ≤2 events 0.767 vs ≥10 events 0.84; low-impression items (it_imp<61) 0.78 vs >237 0.84. C23: hlen≤5 0.730 (21%), us_nev≤1 0.751 (24%), it_imp≤36 0.757. So cold users/cold items are the weak spots — information-limited (no history), not model-limited; every learned model fails there too.
27
+
28
+ ## Honest notes / failures
29
+ - First choice-model run was invalid (val AUC 0.496): scores were in D.RI order (rows sorted by item), val labels in parquet order. Fixed with align()/to_val() in choice.py.
30
+ - Choice model overfits: 50k×32 free item embeddings on ~490k events; best-by-holdout is epoch 0-1. l2 / hist-dropout / low emb-lr don't get above 0.778 (SVD frozen 0.753).
31
+ - Everything ≥ plateau; no lever found with ≥+0.001. Gap to 0.83 is not closable by blend/stack/neural diversity on the current information set.
32
+
33
+ ## Files
34
+ common.py, dwcommon.py, decomp.py/json, headroom_sim.py/json, choice.py (CM, fit_choice, score, align, to_val), run_choice.py, sweep_choice.py + cfg1/2.txt + choice_sweep.jsonl, stack_choice.py (LGBM residual stacking test), blend_div.py, seg.py, recal.py, logs/.
35
+ Run e.g.: /workspace/venv/bin/python stack_choice.py 25 '{"d":32,"ep":1,"lr":0.001}' ep1
dw_levers/headroom_sim.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"25": {"base_global": 0.8172259475835104, "base_event": 0.672879467007552, "rows": [{"g": 0.0, "event_auc": 0.6729, "global_auc": 0.81723, "delta": 0.0}, {"g": 0.1, "event_auc": 0.675, "global_auc": 0.81738, "delta": 0.00015}, {"g": 0.2, "event_auc": 0.6801, "global_auc": 0.8178, "delta": 0.00057}, {"g": 0.3, "event_auc": 0.6858, "global_auc": 0.81828, "delta": 0.00106}, {"g": 0.5, "event_auc": 0.7093, "global_auc": 0.82044, "delta": 0.00321}, {"g": 0.8, "event_auc": 0.7583, "global_auc": 0.82473, "delta": 0.0075}, {"g": 1.2, "event_auc": 0.8279, "global_auc": 0.83223, "delta": 0.015}]}, "23": {"base_global": 0.7956557773874656, "base_event": 0.6498087959114907, "rows": [{"g": 0.0, "event_auc": 0.6498, "global_auc": 0.79566, "delta": 0.0}, {"g": 0.1, "event_auc": 0.6515, "global_auc": 0.79581, "delta": 0.00015}, {"g": 0.2, "event_auc": 0.6599, "global_auc": 0.79636, "delta": 0.0007}, {"g": 0.3, "event_auc": 0.6688, "global_auc": 0.79701, "delta": 0.00136}, {"g": 0.5, "event_auc": 0.6956, "global_auc": 0.79926, "delta": 0.0036}, {"g": 0.8, "event_auc": 0.7517, "global_auc": 0.80431, "delta": 0.00865}, {"g": 1.2, "event_auc": 0.8219, "global_auc": 0.81275, "delta": 0.01709}]}}
dw_levers/headroom_sim.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np, json
2
+ from common import *
3
+ rng=np.random.default_rng(0); out={}
4
+ for c in (25,23):
5
+ m=meta(c); y=m['clicked'].to_numpy(); z=z12(c); n=len(y)//10; Z=z.reshape(n,10); yev=y.reshape(n,10).max(1)
6
+ pany=1-np.prod(1-1/(1+np.exp(-Z)),1); e0=np.log(pany/(1-pany)); base_ev=A(yev,e0); base=A(y,z); res=[]
7
+ for g in (0.0,0.1,0.2,0.3,0.5,0.8,1.2):
8
+ s=(yev-.5)*g+rng.normal(size=n); llr=g*s # Bayes update for N(+-g/2,1) side-information
9
+ # row logit: p_row=q*softmax -> shifting event log-odds by llr approx shifts row logit by llr*(1-q)
10
+ q=pany[:,None]; zz=(Z+llr[:,None]*(1-q)).ravel()
11
+ res.append(dict(g=g,event_auc=round(A(yev,e0+llr),4),global_auc=round(A(y,zz),5),delta=round(A(y,zz)-base,5)))
12
+ out[c]=dict(base_global=base,base_event=base_ev,rows=res); print(c,base_ev,json.dumps(res),flush=True)
13
+ json.dump(out,open('headroom_sim.json','w'))
dw_levers/logs/blend_div.log ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ == C25 z12 0.81723
2
+ dw_s_c25_s0[0] AUC 0.81589 corr(z) 0.994 best blend +0.00000 w=0
3
+ dw_s_c25_s0[1] AUC 0.81595 corr(z) 0.995 best blend +0.00000 w=0
4
+ dw_s_c25_s1[0] AUC 0.81610 corr(z) 0.993 best blend +0.00001 w=0.05
5
+ dw_s_c25_s1[1] AUC 0.81621 corr(z) 0.993 best blend +0.00002 w=0.1
6
+ dwbig_c25_s0[0] AUC 0.81647 corr(z) 0.995 best blend +0.00001 w=0.1
7
+ dwbig_c25_s0[1] AUC 0.81658 corr(z) 0.995 best blend +0.00003 w=0.2
8
+ dwbig_c25_s0[2] AUC 0.81654 corr(z) 0.995 best blend +0.00003 w=0.2
9
+ dwbig_c25_s1[0] AUC 0.81651 corr(z) 0.994 best blend +0.00003 w=0.2
10
+ dwbig_c25_s1[1] AUC 0.81652 corr(z) 0.995 best blend +0.00004 w=0.2
11
+ dwbig_c25_s1[2] AUC 0.81651 corr(z) 0.994 best blend +0.00005 w=0.2
12
+ dwmlp_c25_s0[0] AUC 0.81185 corr(z) 0.976 best blend +0.00000 w=0
13
+ dwmlp_c25_s0[1] AUC 0.81507 corr(z) 0.984 best blend +0.00000 w=0
14
+ dwmlp_c25_s0[2] AUC 0.81588 corr(z) 0.993 best blend +0.00000 w=0.05
15
+ dwmlp_c25_s0[3] AUC 0.81637 corr(z) 0.996 best blend +0.00000 w=0
16
+ dwmlp_c25_s1[0] AUC 0.81144 corr(z) 0.978 best blend +0.00000 w=0
17
+ dwmlp_c25_s1[1] AUC 0.81440 corr(z) 0.987 best blend +0.00000 w=0
18
+ dwmlp_c25_s1[2] AUC 0.81592 corr(z) 0.994 best blend +0.00000 w=0
19
+ dwmlp_c25_s1[3] AUC 0.81628 corr(z) 0.995 best blend +0.00000 w=0
20
+ dwmlp_c25_s2[0] AUC 0.81295 corr(z) 0.984 best blend +0.00000 w=0
21
+ dwmlp_c25_s2[1] AUC 0.81485 corr(z) 0.990 best blend +0.00000 w=0
22
+ dwmlp_c25_s2[2] AUC 0.81584 corr(z) 0.992 best blend +0.00000 w=0.05
23
+ dwmlp_c25_s2[3] AUC 0.81632 corr(z) 0.995 best blend +0.00000 w=0
24
+ mlp2_c25_s0[0] AUC 0.81056 corr(z) 0.975 best blend +0.00000 w=0
25
+ mlp2_c25_s0[1] AUC 0.81289 corr(z) 0.983 best blend +0.00000 w=0
26
+ mlp2_c25_s0[2] AUC 0.81420 corr(z) 0.989 best blend +0.00000 w=0
27
+ mlp2_c25_s0[3] AUC 0.81456 corr(z) 0.990 best blend +0.00000 w=0
28
+ mlp2_c25_s1[0] AUC 0.81214 corr(z) 0.976 best blend +0.00000 w=0
29
+ mlp2_c25_s1[1] AUC 0.81286 corr(z) 0.982 best blend +0.00000 w=0
30
+ mlp2_c25_s1[2] AUC 0.81365 corr(z) 0.988 best blend +0.00000 w=0
31
+ mlp2_c25_s1[3] AUC 0.81447 corr(z) 0.990 best blend +0.00000 w=0
32
+ mlp2_c25_s2[0] AUC 0.80838 corr(z) 0.969 best blend +0.00000 w=0
33
+ mlp2_c25_s2[1] AUC 0.81322 corr(z) 0.984 best blend +0.00000 w=0
34
+ mlp2_c25_s2[2] AUC 0.81430 corr(z) 0.987 best blend +0.00000 w=0.05
35
+ mlp2_c25_s2[3] AUC 0.81456 corr(z) 0.990 best blend +0.00000 w=0
36
+ sC_s_c25_s0[0] AUC 0.81408 corr(z) 0.988 best blend +0.00000 w=0
37
+ sC_s_c25_s0[1] AUC 0.81402 corr(z) 0.988 best blend +0.00000 w=0
38
+ sC_s_c25_s1[0] AUC 0.81425 corr(z) 0.988 best blend +0.00000 w=0
39
+ sC_s_c25_s1[1] AUC 0.81425 corr(z) 0.989 best blend +0.00000 w=0
40
+ sCbig_c25_s0[0] AUC 0.81467 corr(z) 0.989 best blend +0.00000 w=0
41
+ sCbig_c25_s0[1] AUC 0.81460 corr(z) 0.989 best blend +0.00000 w=0
42
+ sCbig_c25_s0[2] AUC 0.81456 corr(z) 0.989 best blend +0.00000 w=0.05
43
+ sCbig_c25_s1[0] AUC 0.81461 corr(z) 0.989 best blend +0.00000 w=0
44
+ sCbig_c25_s1[1] AUC 0.81464 corr(z) 0.989 best blend +0.00000 w=0.05
45
+ sCbig_c25_s1[2] AUC 0.81466 corr(z) 0.989 best blend +0.00001 w=0.05
46
+ == C23 z12 0.79566
47
+ dw_s_c23_s0[0] AUC 0.79430 corr(z) 0.992 best blend +0.00000 w=0
48
+ dw_s_c23_s0[1] AUC 0.79415 corr(z) 0.992 best blend +0.00000 w=0
49
+ dw_s_c23_s1[0] AUC 0.79413 corr(z) 0.990 best blend +0.00001 w=0.05
50
+ dw_s_c23_s1[1] AUC 0.79399 corr(z) 0.990 best blend +0.00001 w=0.05
51
+ dwbig_c23_s0[0] AUC 0.79466 corr(z) 0.992 best blend +0.00001 w=0.1
52
+ dwbig_c23_s0[1] AUC 0.79460 corr(z) 0.992 best blend +0.00002 w=0.1
53
+ dwbig_c23_s0[2] AUC 0.79446 corr(z) 0.992 best blend +0.00002 w=0.1
54
+ dwbig_c23_s1[0] AUC 0.79470 corr(z) 0.991 best blend +0.00005 w=0.2
55
+ dwbig_c23_s1[1] AUC 0.79458 corr(z) 0.991 best blend +0.00005 w=0.2
56
+ dwbig_c23_s1[2] AUC 0.79450 corr(z) 0.991 best blend +0.00007 w=0.2
57
+ dwmlp_c23_s0[0] AUC 0.78745 corr(z) 0.968 best blend +0.00000 w=0
58
+ dwmlp_c23_s0[1] AUC 0.79239 corr(z) 0.983 best blend +0.00000 w=0
59
+ dwmlp_c23_s0[2] AUC 0.79391 corr(z) 0.992 best blend +0.00000 w=0
60
+ dwmlp_c23_s0[3] AUC 0.79421 corr(z) 0.993 best blend +0.00000 w=0
61
+ dwmlp_c23_s1[0] AUC 0.78901 corr(z) 0.971 best blend +0.00000 w=0
62
+ dwmlp_c23_s1[1] AUC 0.79302 corr(z) 0.989 best blend +0.00000 w=0
63
+ dwmlp_c23_s1[2] AUC 0.79371 corr(z) 0.991 best blend +0.00000 w=0
64
+ dwmlp_c23_s1[3] AUC 0.79434 corr(z) 0.994 best blend +0.00000 w=0
65
+ dwmlp_c23_s2[0] AUC 0.78762 corr(z) 0.967 best blend +0.00000 w=0
66
+ dwmlp_c23_s2[1] AUC 0.79245 corr(z) 0.983 best blend +0.00000 w=0
67
+ dwmlp_c23_s2[2] AUC 0.79413 corr(z) 0.992 best blend +0.00000 w=0
68
+ dwmlp_c23_s2[3] AUC 0.79442 corr(z) 0.994 best blend +0.00000 w=0
69
+ mlp2_c23_s0[0] AUC 0.78854 corr(z) 0.966 best blend +0.00000 w=0
70
+ mlp2_c23_s0[1] AUC 0.79075 corr(z) 0.977 best blend +0.00000 w=0
71
+ mlp2_c23_s0[2] AUC 0.79237 corr(z) 0.986 best blend +0.00000 w=0
72
+ mlp2_c23_s0[3] AUC 0.79302 corr(z) 0.989 best blend +0.00000 w=0
73
+ mlp2_c23_s1[0] AUC 0.78539 corr(z) 0.958 best blend +0.00000 w=0
74
+ mlp2_c23_s1[1] AUC 0.79126 corr(z) 0.978 best blend +0.00000 w=0
75
+ mlp2_c23_s1[2] AUC 0.79281 corr(z) 0.988 best blend +0.00000 w=0
76
+ mlp2_c23_s1[3] AUC 0.79312 corr(z) 0.989 best blend +0.00000 w=0
77
+ mlp2_c23_s2[0] AUC 0.78770 corr(z) 0.969 best blend +0.00000 w=0
78
+ mlp2_c23_s2[1] AUC 0.79032 corr(z) 0.978 best blend +0.00000 w=0
79
+ mlp2_c23_s2[2] AUC 0.79258 corr(z) 0.988 best blend +0.00000 w=0
80
+ mlp2_c23_s2[3] AUC 0.79291 corr(z) 0.988 best blend +0.00000 w=0
81
+ sC_s_c23_s0[0] AUC 0.79290 corr(z) 0.986 best blend +0.00000 w=0
82
+ sC_s_c23_s0[1] AUC 0.79281 corr(z) 0.986 best blend +0.00000 w=0
83
+ sC_s_c23_s1[0] AUC 0.79299 corr(z) 0.987 best blend +0.00000 w=0
84
+ sC_s_c23_s1[1] AUC 0.79283 corr(z) 0.987 best blend +0.00000 w=0
85
+ sCbig_c23_s0[0] AUC 0.79328 corr(z) 0.988 best blend +0.00000 w=0.05
86
+ sCbig_c23_s0[1] AUC 0.79309 corr(z) 0.987 best blend +0.00000 w=0.05
87
+ sCbig_c23_s0[2] AUC 0.79299 corr(z) 0.987 best blend +0.00001 w=0.05
88
+ sCbig_c23_s1[0] AUC 0.79311 corr(z) 0.987 best blend +0.00000 w=0
89
+ sCbig_c23_s1[1] AUC 0.79309 corr(z) 0.987 best blend +0.00000 w=0.05
90
+ sCbig_c23_s1[2] AUC 0.79290 corr(z) 0.987 best blend +0.00000 w=0.05
dw_levers/logs/choice_base_25.log ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ v12 0.8172259475835104
2
+ [ 7s] svd done
3
+ [ 12s] ep0 train 1.5714 hold 1.5278 8s valAUC 0.77560
4
+ [ 17s] ep1 train 0.9808 hold 1.8055 12s valAUC 0.74639
5
+ [ 22s] ep2 train 0.5487 hold 2.3603 17s valAUC 0.72596
6
+ [ 26s] ep3 train 0.3437 hold 2.9096 22s valAUC 0.71568
7
+ choice AUC 0.7756003662421029 within 0.7756003662421029
8
+ blend z+w*lp 0.1 0.8172855210762608
9
+ blend z+w*lp 0.2 0.8166980845190918
10
+ blend z+w*lp 0.3 0.8157374588477733
11
+ blend z+w*lp 0.5 0.8133236048636625
dw_levers/logs/stack25.log ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ [ 6s] svd done
2
+ [ 12s] ep0 train 1.6461 hold 1.4576 8s valAUC 0.77770
3
+ z not prob? -7.762106418609619 1.4581687450408936
4
+ ctrl AUC 0.8173432554565818 delta 0.00011730787307140389
5
+ stack AUC 0.817422278088598 delta 0.0001963305050876052
6
+ stack-ctrl 8.023554142218892e-05 [2.16149252e-05 1.50093019e-04]
dw_levers/logs/sweep1.log ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CFG {"d": 32, "ep": 3, "lr": 0.001}
2
+ [ 12s] svd done
3
+ [ 18s] ep0 train 1.6461 hold 1.4576 13s valAUC 0.77770
4
+ [ 22s] ep1 train 1.1656 hold 1.5018 18s valAUC 0.77658
5
+ [ 27s] ep2 train 0.8589 hold 1.7046 23s valAUC 0.76555
6
+ RES {"cfg": {"d": 32, "ep": 3, "lr": 0.001}, "cut": 25, "auc": 0.7776973973402646, "blend": {"0.1": -8e-05, "0.2": -0.00076, "0.4": -0.00295}}
7
+ CFG {"d": 32, "ep": 3, "lr": 0.001, "l2": 0.01}
8
+ [ 30s] svd done
9
+ [ 36s] ep0 train 1.6652 hold 1.4589 9s valAUC 0.77774
10
+ [ 42s] ep1 train 1.1864 hold 1.5036 15s valAUC 0.77665
11
+ [ 48s] ep2 train 0.8811 hold 1.7076 21s valAUC 0.76554
12
+ RES {"cfg": {"d": 32, "ep": 3, "lr": 0.001, "l2": 0.01}, "cut": 25, "auc": 0.777737651041082, "blend": {"0.1": -8e-05, "0.2": -0.00075, "0.4": -0.00294}}
13
+ CFG {"d": 32, "ep": 3, "lr": 0.001, "l2": 0.1}
14
+ [ 51s] svd done
15
+ [ 57s] ep0 train 1.8282 hold 1.4700 8s valAUC 0.77784
16
+ [ 63s] ep1 train 1.3527 hold 1.5188 14s valAUC 0.77686
17
+ [ 69s] ep2 train 1.0524 hold 1.7287 20s valAUC 0.76530
18
+ RES {"cfg": {"d": 32, "ep": 3, "lr": 0.001, "l2": 0.1}, "cut": 25, "auc": 0.7778433663501874, "blend": {"0.1": -7e-05, "0.2": -0.00071, "0.4": -0.00281}}
19
+ CFG {"d": 32, "ep": 3, "lr": 0.001, "hist_drop": 0.3, "l2": 0.01}
20
+ [ 72s] svd done
21
+ [ 78s] ep0 train 1.6956 hold 1.4836 9s valAUC 0.77525
22
+ [ 84s] ep1 train 1.2712 hold 1.6013 15s valAUC 0.77353
23
+ [ 90s] ep2 train 1.0243 hold 1.8377 21s valAUC 0.76473
24
+ RES {"cfg": {"d": 32, "ep": 3, "lr": 0.001, "hist_drop": 0.3, "l2": 0.01}, "cut": 25, "auc": 0.775251609736144, "blend": {"0.1": -0.00018, "0.2": -0.00114, "0.4": -0.004}}
25
+ CFG {"d": 32, "ep": 3, "lr": 0.001, "att": true, "l2": 0.01}
26
+ [ 92s] svd done
27
+ [ 100s] ep0 train 1.8460 hold 1.7163 9s valAUC 0.76406
28
+ [ 107s] ep1 train 1.5098 hold 1.5874 16s valAUC 0.76832
29
+ [ 113s] ep2 train 1.2045 hold 1.5901 23s valAUC 0.76180
30
+ RES {"cfg": {"d": 32, "ep": 3, "lr": 0.001, "att": true, "l2": 0.01}, "cut": 25, "auc": 0.768316048958352, "blend": {"0.1": -8e-05, "0.2": -0.00059, "0.4": -0.00232}}
31
+ CFG {"d": 64, "ep": 3, "lr": 0.001, "l2": 0.03}
32
+ [ 116s] svd done
33
+ [ 125s] ep0 train 1.6851 hold 1.4572 11s valAUC 0.77724
34
+ [ 134s] ep1 train 1.1671 hold 1.5469 20s valAUC 0.77368
35
+ [ 142s] ep2 train 0.6993 hold 1.9402 28s valAUC 0.75787
36
+ RES {"cfg": {"d": 64, "ep": 3, "lr": 0.001, "l2": 0.03}, "cut": 25, "auc": 0.7772370992714306, "blend": {"0.1": -7e-05, "0.2": -0.00076, "0.4": -0.00298}}
dw_levers/logs/sweep2.log ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CFG {"d": 32, "ep": 6, "lr": 0.003, "elr": 0.0}
2
+ [ 9s] svd done
3
+ [ 15s] ep0 train 1.6042 hold 1.5460 9s valAUC 0.75228
4
+ [ 19s] ep1 train 1.5421 hold 1.5458 14s valAUC 0.75218
5
+ [ 24s] ep2 train 1.5410 hold 1.5446 19s valAUC 0.75248
6
+ [ 28s] ep3 train 1.5401 hold 1.5441 23s valAUC 0.75263
7
+ [ 33s] ep4 train 1.5393 hold 1.5436 28s valAUC 0.75278
8
+ [ 37s] ep5 train 1.5387 hold 1.5473 32s valAUC 0.75320
9
+ RES {"cfg": {"d": 32, "ep": 6, "lr": 0.003, "elr": 0.0}, "cut": 25, "auc": 0.7527770901981062, "blend": {"0.1": -0.00053, "0.2": -0.00182, "0.4": -0.00551}}
10
+ CFG {"d": 32, "ep": 6, "lr": 0.003, "elr": 0.05}
11
+ [ 40s] svd done
12
+ [ 45s] ep0 train 1.5878 hold 1.5150 7s valAUC 0.75848
13
+ [ 49s] ep1 train 1.4516 hold 1.4935 11s valAUC 0.76314
14
+ [ 54s] ep2 train 1.3794 hold 1.4803 16s valAUC 0.76700
15
+ [ 58s] ep3 train 1.3101 hold 1.4729 20s valAUC 0.76961
16
+ [ 62s] ep4 train 1.2438 hold 1.4816 25s valAUC 0.77129
17
+ [ 67s] ep5 train 1.1798 hold 1.4903 29s valAUC 0.77254
18
+ RES {"cfg": {"d": 32, "ep": 6, "lr": 0.003, "elr": 0.05}, "cut": 25, "auc": 0.7696136210745811, "blend": {"0.1": -0.00039, "0.2": -0.00168, "0.4": -0.00529}}
19
+ CFG {"d": 32, "ep": 6, "lr": 0.003, "elr": 0.15, "hist_drop": 0.2}
20
+ [ 70s] svd done
21
+ [ 74s] ep0 train 1.5853 hold 1.4910 7s valAUC 0.76688
22
+ [ 79s] ep1 train 1.3515 hold 1.4941 11s valAUC 0.77235
23
+ [ 83s] ep2 train 1.1926 hold 1.5369 16s valAUC 0.77374
24
+ [ 87s] ep3 train 1.0468 hold 1.6133 20s valAUC 0.77222
25
+ [ 92s] ep4 train 0.9117 hold 1.7607 25s valAUC 0.76832
26
+ [ 97s] ep5 train 0.7875 hold 1.9241 29s valAUC 0.76389
27
+ RES {"cfg": {"d": 32, "ep": 6, "lr": 0.003, "elr": 0.15, "hist_drop": 0.2}, "cut": 25, "auc": 0.766880051741821, "blend": {"0.1": -0.00038, "0.2": -0.00157, "0.4": -0.00497}}
dw_levers/prep_data.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import sys; sys.path.insert(0,'/workspace/huawei/dw_levers')
2
+ import numpy as np, time
3
+ from dwcommon import *
4
+ t=time.time(); D=Data(); print('load',time.time()-t, D.NE, D.NU, D.NI, D.Hlen.max(), D.Hlen.mean(), D.ETS.min()-J20, D.ETS.max()-J20, flush=True)
5
+ print(np.searchsorted(D.ETS,Jd(25)), np.searchsorted(D.ETS,Jd(23)))
6
+ v=D.val(25); print(len(v['y']), v['ts'].min()-Jd(25), v['ts'].max()-Jd(25))
7
+ # is history ordered oldest first?
8
+ e=100000; print(D.HT[D.OFF[e]:D.OFF[e+1]]-D.ETS[e])
9
+ import resource; print(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1e6,'GB')
dw_levers/recal.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys, numpy as np, polars as pl, pandas as pd
2
+ sys.path.insert(0,'/workspace/huawei/dw_levers')
3
+ from common import z12, A
4
+ from sklearn.linear_model import LogisticRegression
5
+ from sklearn.model_selection import GroupKFold
6
+ H='/workspace/huawei'
7
+ for c in (25,23):
8
+ m=pl.read_parquet(f'{H}/v10/feat_v3/val{c}.parquet',columns=['clicked','u','us_hlen','it_imp','us_nev','us_cold']).to_pandas()
9
+ z=z12(c); y=m.clicked.values.astype(int); base=A(y,z)
10
+ for name,keys in (('hlen',['us_hlen']),('imp',['it_imp']),('hlen x imp',['us_hlen','it_imp']),('nev x imp',['us_nev','it_imp'])):
11
+ cell=np.zeros(len(y),int)
12
+ for k in keys: cell=cell*8+pd.qcut(m[k],6,duplicates='drop',labels=False).values.astype(int)
13
+ out=np.zeros(len(y))
14
+ for tr,te in GroupKFold(5).split(z,y,m.u.values): # honest CV by user
15
+ for cl in np.unique(cell):
16
+ a=tr[cell[tr]==cl]; b=te[cell[te]==cl]
17
+ if len(b)==0: continue
18
+ lr=LogisticRegression(C=10).fit(z[a,None],y[a]); out[b]=lr.decision_function(z[b,None])
19
+ print(f'C{c} {name:12s} Δ={A(y,out)-base:+.5f}',flush=True)
dw_levers/run_choice.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys, json, numpy as np
2
+ sys.path.insert(0,'/workspace/huawei/dw_levers')
3
+ from choice import *
4
+ from common import meta, z12, A
5
+ cut=int(sys.argv[1]); cfg=json.loads(sys.argv[2]); tag=sys.argv[3]
6
+ D=Data(); v=D.val(cut); m_=meta(cut); assert (m_['clicked'].to_numpy()==v['y']).all()
7
+ v['col']=align(D,v); z=z12(cut); print('v12',A(v['y'],z),flush=True)
8
+ mdl=fit_choice(D,Jd(cut),cfg,val=v)
9
+ lp,on=score(mdl,D,v['e'][::10]); lp=to_val(lp,v['col']); y=v['y']
10
+ print('choice AUC',A(y,lp.ravel()),'within',A(y,lp.ravel()-np.repeat(0,len(y))),flush=True)
11
+ np.save(f'/workspace/huawei/dw_levers/cache/choice_{tag}_c{cut}.npy',np.column_stack([lp.ravel(),np.repeat(on,10)]).astype(np.float32))
12
+ for w in (0.1,0.2,0.3,0.5): print('blend z+w*lp',w,A(y,z+w*lp.ravel()),flush=True)
dw_levers/seg.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys, numpy as np, polars as pl, json
2
+ sys.path.insert(0,'/workspace/huawei/dw_levers')
3
+ from common import z12, A
4
+ H='/workspace/huawei'
5
+ out={}
6
+ for c in (25,23):
7
+ m=pl.read_parquet(f'{H}/v10/feat_v3/val{c}.parquet',columns=['rowid','eid','clicked','u','tm_stale','us_hlen','hist_n_win','it_imp','us_nev','tm_hour','it_ctr','hist_in','us_cold','us_nohist']).to_pandas()
8
+ z=z12(c); y=m.clicked.values.astype(int); base=A(y,z); print(f'== C{c} base {base:.5f} n={len(y)} pos={y.mean():.4f}')
9
+ # global AUC when segment scores replaced by oracle-shifted: seg pos get +big? use: pos in seg -> z+3 , neg in seg -> z-3
10
+ def segs(col,bins):
11
+ q=pd_cut(m[col].values,bins); return q
12
+ import pandas as pd
13
+ pd_cut=lambda x,b: pd.cut(x,b,include_lowest=True).astype(str)
14
+ S={'tm_stale':pd_cut(m.tm_stale.values,[-1e9,0,6,12,24,48,1e9]) ,
15
+ 'us_hlen':pd.qcut(m.us_hlen,6,duplicates='drop').astype(str),
16
+ 'hist_n_win':pd.qcut(m.hist_n_win,6,duplicates='drop').astype(str),
17
+ 'it_imp':pd.qcut(m.it_imp,6,duplicates='drop').astype(str),
18
+ 'us_nev':pd.qcut(m.us_nev,6,duplicates='drop').astype(str),
19
+ 'hour':pd_cut(m.tm_hour.values,[-1,5,11,17,24])}
20
+ for k,sg in S.items():
21
+ print('--',k)
22
+ for s in sorted(set(sg)):
23
+ i=sg==s
24
+ if i.sum()<500 or y[i].min()==y[i].max(): continue
25
+ wi=A(y[i],z[i]); zz=z.copy(); zz[i&(y==1)]+=2; zz[i&(y==0)]-=2 # soft oracle
26
+ # recalibration headroom: shift segment so mean logit gap matches
27
+ hs=A(y,zz)-base
28
+ # mean score (pos rate) vs mean pred
29
+ print(f' {s:>28} share {i.mean():.3f} pos {y[i].mean():.3f} AUCin {wi:.4f} meanZ {z[i].mean():+.2f} oracleΔ {hs:+.4f} oracleΔ/share {hs/i.mean():+.4f}')
dw_levers/stack_choice.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys, json, numpy as np, lightgbm as lgb
2
+ sys.path.insert(0,'/workspace/huawei/dw_levers')
3
+ from choice import *
4
+ from common import meta, z12, A
5
+ from sklearn.model_selection import GroupKFold
6
+ cut=int(sys.argv[1]); cfg=json.loads(sys.argv[2]); tag=sys.argv[3]
7
+ D=Data(); v=D.val(cut); v['col']=align(D,v); z=z12(cut); y=v['y']
8
+ import os; f=f'cache/choice_{tag}_c{cut}.npz'
9
+ if os.path.exists(f): d=np.load(f); lp,on=d['lp'],d['on']
10
+ else:
11
+ mdl=fit_choice(D,Jd(cut),cfg,val=v); lp,on=score(mdl,D,v['e'][::10]); lp=to_val(lp,v['col']).ravel(); on=on; np.savez(f,lp=lp,on=on)
12
+ n=len(y)//10; ev=np.repeat(np.arange(n),10)
13
+ lz=np.log(z/(1-z)) if z.max()<=1 else z
14
+ if z.max()>1: print('z not prob?',z.min(),z.max())
15
+ def slate(a): m=a.reshape(n,10); return (m-m.mean(1,keepdims=True)).ravel(), (np.argsort(np.argsort(-m,1),1)).ravel()
16
+ Z=np.c_[lz,*slate(lz),np.repeat(np.log(np.exp(lz.reshape(n,10)).sum(1)),10)]
17
+ X1=np.c_[Z,lp,*slate(lp),np.repeat(on,10)]
18
+ users=v['user']; res={}
19
+ def cv(X,name):
20
+ out=np.zeros(len(y))
21
+ for seed in (0,1):
22
+ for tr,te in GroupKFold(5).split(X,y,users):
23
+ p=dict(objective='binary',learning_rate=0.02,num_leaves=8,min_data_in_leaf=300,feature_fraction=0.8,bagging_fraction=0.8,bagging_freq=1,lambda_l2=10,seed=seed,verbose=-1,num_threads=4)
24
+ m=lgb.train(p,lgb.Dataset(X[tr],y[tr],init_score=lz[tr]),150)
25
+ out[te]+=m.predict(X[te],raw_score=True)+lz[te]
26
+ out/=2; res[name]=out; return out
27
+ base=A(y,lz)
28
+ for name,X in (('ctrl',Z),('stack',X1)):
29
+ o=cv(X,name); print(name,'AUC',A(y,o),'delta',A(y,o)-base,flush=True)
30
+ # paired event bootstrap of stack-ctrl
31
+ rng=np.random.default_rng(0); yy=y.reshape(n,10); a=res['stack'].reshape(n,10); b=res['ctrl'].reshape(n,10); ds=[]
32
+ for _ in range(100):
33
+ i=rng.integers(0,n,n); ds.append(A(yy[i].ravel(),a[i].ravel())-A(yy[i].ravel(),b[i].ravel()))
34
+ print('stack-ctrl',np.mean(ds),np.percentile(ds,[2.5,97.5]))
dw_levers/sweep_choice.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys, json, numpy as np
2
+ sys.path.insert(0,'/workspace/huawei/dw_levers')
3
+ from choice import *
4
+ from common import meta, z12, A
5
+ cut=int(sys.argv[1]); cfgs=[json.loads(l) for l in open(sys.argv[2]) if l.strip()]
6
+ D=Data(); v=D.val(cut); v['col']=align(D,v); z=z12(cut)
7
+ for cfg in cfgs:
8
+ print('CFG',json.dumps(cfg),flush=True)
9
+ mdl=fit_choice(D,Jd(cut),cfg,val=v); lp,on=score(mdl,D,v['e'][::10]); lp=to_val(lp,v['col']).ravel(); y=v['y']
10
+ r=dict(cfg=cfg,cut=cut,auc=A(y,lp),blend={w:round(A(y,z+w*lp)-A(y,z),5) for w in (0.1,0.2,0.4)}); print('RES',json.dumps(r),flush=True)
11
+ open('choice_sweep.jsonl','a').write(json.dumps(r)+'\n')
dw_v12sig/findings.md ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # v12 new-signal search (dw_v12sig) — findings
2
+
3
+ Harness: dw_lb/lib.py residual LightGBM on v12 logits (init_score=z), user-grouped 5-fold, event-bootstrap 95% CI of AUC(test)-AUC(control). C25 primary, C23 confirm. v12 val AUC: C25 0.81723, C23 0.79566.
4
+ Noise control (null event-noise feature): C25 -0.00006 [-0.00012,-0.000005]; C23 -0.00002 [-0.00008,+0.00005]. Floor about ±0.0001.
5
+
6
+ ## Ranked results (delta AUC vs control, 95% CI)
7
+ | Group | C25 | C23 |
8
+ |---|---|---|
9
+ | tmp: per-dim taste products (13) | +0.00019 [+0.00002,+0.00033] | +0.00028 [+0.00012,+0.00044] |
10
+ | tmprod: products + item coords (25) | +0.00017 [0,+0.00034] | +0.00035 [+0.00014,+0.00051] |
11
+ | tm: all taste-metric (30) | +0.00016 [-0.00002,+0.00032] | +0.00036 [+0.00017,+0.00053] |
12
+ | all (68) | +0.00015 [-0.00004,+0.00030] | +0.00044 [+0.00020,+0.00064] |
13
+ | tmi: item coords only (12) | +0.00002 [-0.00015,+0.00016] | +0.00014 [-0.00003,+0.00030] |
14
+ | tmbil: learned bilinear (5) | +0.00004 [-0.00008,+0.00016] | not run |
15
+ | cl: conditional-logit item strength (15) | +0.00002 [-0.00013,+0.00016] | -0.00001 [-0.00014,+0.00012] |
16
+ | sq: transitions/Markov (12) | +0.00002 [-0.00012,+0.00017] | not run |
17
+ | sigs all (38) | +0.00001 [-0.00015,+0.00015] | not run |
18
+ | rp: repeat propensity (4) | -0.00002 [-0.00011,+0.00007] | not run |
19
+ | lc: item lifecycle (7) | -0.00009 [-0.00020,+0.00001] | not run |
20
+
21
+ ## Disagreement profile v12 vs p33 (no labels; t1_disagree.py, t1.log)
22
+ - Spearman 0.929, normal-score Pearson 0.935, residual sd 0.354; residual 15% event-level, 85% within-event.
23
+ - Spread across segments. Lowest agreement for no-history users (corr 0.47, tiny share). p33 ranks candidates already in the user's own history about +0.22 sd higher.
24
+ - Persistent ITEM-LEVEL residual: split-half reliability 0.36 (true item effect sd about 0.086), nearly uncorrelated (~0.07) with item CTR, popularity, lifecycle and CL strength. Hypothesis: p33 uses item identity / embedding (taste-region) information that v12 lacks. Matches the only winner: taste-dimension products from impression-space SVD.
25
+ - Event-level residual is 24% explainable from existing features (mostly SVD-family); within-event 7%.
26
+
27
+ ## Task 4 (no/short history)
28
+ Not run as an experiment: no-history rows are 1.3% of eval (6,650), so even a big lift there caps at about +0.0005 global AUC.
29
+ ## Task 5 (slate/position)
30
+ No signal. Click rate by file position is flat (chi2 p=0.84), rows inside an event are not sorted, rowid is a hash. Nothing to exploit, nothing leaky to worry about.
31
+
32
+ ## Verdict
33
+ Nothing reaches +0.001. The only signal above noise is per-dimension user×item taste products (tm_prod0-11 + tm_prod_tail): about +0.0002 (C25, CI touches 0) and +0.0003 (C23, CI clear of 0), confirmed on both cuts, in the same direction. Item strength, lifecycle, transitions, repeat propensity, the learned bilinear metric and item-only coordinates are at the noise floor. Expect a small gain (~+0.0002–0.0004) if tm_prod is added as extra stacker features; probably worth it only if cheap. Likely v12 and p33 already capture the same sequence/item-strength information.
34
+
35
+ ## Leak safety / tests
36
+ Features use only train events before the cutoff plus each row's own history and slate; no eval aggregates (c27 files are built from train events only). test_sigs.py (run, passes): taste_metric recomputed for val25 matches cache within 1e-3; item_strength is unchanged when post-cutoff labels are flipped.
37
+
38
+ ## Files and reuse
39
+ - Code: sigs.py (extend_eval, item_strength, item_lifecycle, sequence, all_new), sigs2.py (imp_svd, learn_bilinear, taste_metric — `from sigs2 import taste_metric`; keep columns tm_prod*), run_groups.py (`run_groups.py <cuts> <groups>`), test_sigs.py, t1_disagree.py, t1b_item.py, t1c.py, t5_slate.py.
40
+ - Features: cache/sig_c{23,25,27}.parquet, cache/tm_c{23,25,27}.parquet (c27 = eval-time).
41
+ - Results: results.jsonl, run*.log, t1.log, t1_resid.parquet.
dw_v12sig/results.jsonl ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"name": "v12sig_noise", "cut": 25, "nfeat": 1, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8171585501683595, "d_vs_z": -6.739741515093822e-05, "d_vs_ctrl": -6.094809697987369e-05, "ci_vs_ctrl": [-0.00012172757771286569, -5.225814527426415e-06], "sd": 3.1405712970425335e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6659201019047909}
2
+ {"name": "v12sig_cl", "cut": 25, "nfeat": 15, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8172431409698145, "d_vs_z": 1.7193386304126257e-05, "d_vs_ctrl": 2.364270447519079e-05, "ci_vs_ctrl": [-0.0001276006095983051, 0.00015528683873076987], "sd": 7.111215168176308e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.666382687623516}
3
+ {"name": "v12sig_lc", "cut": 25, "nfeat": 7, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8171258842776561, "d_vs_z": -0.00010006330585432544, "d_vs_ctrl": -9.36139876832609e-05, "ci_vs_ctrl": [-0.00019997879057406519, 1.3580106612468018e-05], "sd": 5.731122009925467e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6658895215004376}
4
+ {"name": "v12sig_sq", "cut": 25, "nfeat": 12, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8172391254915123, "d_vs_z": 1.3177908001926752e-05, "d_vs_ctrl": 1.9627226172991286e-05, "ci_vs_ctrl": [-0.00011759695631434197, 0.00016744051936322672], "sd": 7.023741015122335e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6665369601144708}
5
+ {"name": "v12sig_rp", "cut": 25, "nfeat": 4, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8171958254800887, "d_vs_z": -3.0122103421681423e-05, "d_vs_ctrl": -2.367278525061689e-05, "ci_vs_ctrl": [-0.00011231654110588352, 6.724128526499896e-05], "sd": 4.797619615335261e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6659012941650297}
6
+ {"name": "v12sig_all", "cut": 25, "nfeat": 38, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8172252933920461, "d_vs_z": -6.541914643332092e-07, "d_vs_ctrl": 5.795126706731324e-06, "ci_vs_ctrl": [-0.00014515511066469922, 0.00015161341756678718], "sd": 8.016159318248819e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6662606668408032}
7
+ {"name": "v12sig_tmbil", "cut": 25, "nfeat": 5, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8172640377790762, "d_vs_z": 3.809019556577642e-05, "d_vs_ctrl": 4.453951373684095e-05, "ci_vs_ctrl": [-7.667979150120518e-05, 0.00016468177852301818], "sd": 6.477103521899297e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6665646547341095}
8
+ {"name": "v12sig_tmprod", "cut": 25, "nfeat": 25, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8173926891560154, "d_vs_z": 0.00016674157250495814, "d_vs_ctrl": 0.00017319089067602267, "ci_vs_ctrl": [1.6364068469722884e-08, 0.00034153239137667545], "sd": 8.146970827146051e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6658928329105425}
9
+ {"name": "v12sig_tm", "cut": 25, "nfeat": 30, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8173788290683497, "d_vs_z": 0.00015288148483927344, "d_vs_ctrl": 0.00015933080301033797, "ci_vs_ctrl": [-1.6180528216988562e-05, 0.00031689746401823157], "sd": 8.419880596862764e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6659289553585908}
10
+ {"name": "v12sig_noise", "cut": 23, "nfeat": 1, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7955304044107099, "d_vs_z": -0.00012537297675574433, "d_vs_ctrl": -1.5034052699869349e-05, "ci_vs_ctrl": [-7.943090645900763e-05, 5.394747265244915e-05], "sd": 3.201110798736299e-05, "evAUC_base": 0.644454956712242, "evAUC_test": 0.6442237185499589}
11
+ {"name": "v12sig_tmprod", "cut": 23, "nfeat": 25, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7958909109102567, "d_vs_z": 0.00023513352279103117, "d_vs_ctrl": 0.00034547244684690614, "ci_vs_ctrl": [0.00014232738845744997, 0.0005114640319105219], "sd": 9.420359906713397e-05, "evAUC_base": 0.644454956712242, "evAUC_test": 0.6454062268527134}
12
+ {"name": "v12sig_tm", "cut": 23, "nfeat": 30, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7959079036807816, "d_vs_z": 0.00025212629331594627, "d_vs_ctrl": 0.00036246521737182125, "ci_vs_ctrl": [0.0001694616255996123, 0.0005299075006823445], "sd": 9.685927937433816e-05, "evAUC_base": 0.644454956712242, "evAUC_test": 0.6456233333774741}
13
+ {"name": "v12sig_cl", "cut": 23, "nfeat": 15, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7955343542107168, "d_vs_z": -0.00012142317674879166, "d_vs_ctrl": -1.1084252692916685e-05, "ci_vs_ctrl": [-0.00014228909437703495, 0.00012075060785508584], "sd": 7.365958161425481e-05, "evAUC_base": 0.644454956712242, "evAUC_test": 0.6443536362448076}
14
+ {"name": "v12sig_all", "cut": 23, "nfeat": 68, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7959834800495287, "d_vs_z": 0.0003277026620630563, "d_vs_ctrl": 0.0004380415861189313, "ci_vs_ctrl": [0.00020191954181220106, 0.0006377027300764782], "sd": 0.00010542090322451897, "evAUC_base": 0.644454956712242, "evAUC_test": 0.6459186103143261}
15
+ {"name": "v12sig_tmp", "cut": 25, "nfeat": 13, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8174051491361859, "d_vs_z": 0.00017920155267547866, "d_vs_ctrl": 0.0001856508708465432, "ci_vs_ctrl": [2.3133276748360526e-05, 0.00033354929847700953], "sd": 7.819032854526502e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6658932830483899}
16
+ {"name": "v12sig_tmi", "cut": 25, "nfeat": 12, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8172367796270116, "d_vs_z": 1.0832043501163291e-05, "d_vs_ctrl": 1.7281361672227824e-05, "ci_vs_ctrl": [-0.0001509946153145647, 0.00016059998032812444], "sd": 8.126794229520459e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6655751715230213}
17
+ {"name": "v12sig_all", "cut": 25, "nfeat": 68, "base": 0.8172259475835104, "control": 0.8172194982653394, "test": 0.8173653104192783, "d_vs_z": 0.00013936283576787556, "d_vs_ctrl": 0.0001458121539389401, "ci_vs_ctrl": [-4.121430504122336e-05, 0.00030456759421955973], "sd": 8.878763031890897e-05, "evAUC_base": 0.6680507246702352, "evAUC_test": 0.6660854161434371}
18
+ {"name": "v12sig_tmp", "cut": 23, "nfeat": 13, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7958279435599476, "d_vs_z": 0.00017216617248194677, "d_vs_ctrl": 0.00028250509653782174, "ci_vs_ctrl": [0.00012370744361178964, 0.00043968947250715433], "sd": 8.595574449986403e-05, "evAUC_base": 0.644454956712242, "evAUC_test": 0.6450338154376516}
19
+ {"name": "v12sig_tmi", "cut": 23, "nfeat": 12, "base": 0.7956557773874656, "control": 0.7955454384634097, "test": 0.7956900671534669, "d_vs_z": 3.4289766001283084e-05, "d_vs_ctrl": 0.00014462869005715806, "ci_vs_ctrl": [-3.351939774114408e-05, 0.00030396100199877875], "sd": 8.505831299199525e-05, "evAUC_base": 0.644454956712242, "evAUC_test": 0.6449723392363685}