training¶
news_recommendation.training
Train PLM-NR on one article representation of the MIND-large day split, and evaluate it.
torchrun --nproc_per_node 4 -m news_recommendation.training train title_section_summary_512 --output-dir runs/x
python -m news_recommendation.training evaluate --output-dir runs/x
configs/plm_nr.json holds the settings shared by every representation.
evaluate scores the epoch with the best validation AUC on the test split.
run_config(variant, data=None)
¶
Source code in src/news_recommendation/training.py
26 27 28 29 30 31 | |
read_impressions(path)
¶
(impression id, history, candidate news ids, click labels) per line of a behaviors file.
Source code in src/news_recommendation/training.py
34 35 36 37 38 39 40 41 42 | |
news_inputs(config, rows)
¶
Row index of every news id the rows use (0 is the all-zero padding row) and the packed token rows.
Source code in src/news_recommendation/training.py
45 46 47 48 49 50 51 | |
padded_history(history, index, length)
¶
The last length clicks, left-padded with row 0, and their mask.
Source code in src/news_recommendation/training.py
54 55 56 57 | |
build_model(config, pretrained=True)
¶
PLM-NR on the first bert_layers BERT layers, of which only trainable_bert_layers are trained.
Source code in src/news_recommendation/training.py
60 61 62 63 64 65 66 | |
train_epoch(model, rows, index, packed, config, optimizer, device)
¶
One epoch over every clicked candidate with npratio sampled negatives.
Source code in src/news_recommendation/training.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
ndcg(labels, scores, k)
¶
Source code in src/news_recommendation/training.py
111 112 113 114 115 | |
mrr(labels, scores)
¶
Source code in src/news_recommendation/training.py
118 119 120 | |
evaluate(model, rows, index, packed, config, device)
¶
Mean AUC, MRR, and nDCG@5/10 over the prepared impressions, each with both click labels.
Source code in src/news_recommendation/training.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
train(config, run, device)
¶
Source code in src/news_recommendation/training.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
test(run, device)
¶
Score the epoch with the best validation AUC on the test split into test.json.
Source code in src/news_recommendation/training.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
main()
¶
Source code in src/news_recommendation/training.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |