Commit 1637cfc
authored
fix(c#): retain SimpleLabel importance weight when building examples (#4949)
SimpleLabelUpdateExample wrote the importance weight to example::weight, but
that field is not where a simple label's weight lives. VW::setup_example --
which VowpalWabbitExampleBuilder.CreateExample runs to finalize the example --
reassigns it:
ae->weight = lbl_parser.get_weight(ae->l, ae->ex_reduction_features);
and for simple labels get_weight returns simple_label_reduction_features::weight,
which ApplyLabel never set. So the weight was overwritten with its default of 1
between ApplyLabel and CreateExample, and SimpleLabelReadFromExample -- which
reads the reduction feature, and was correct all along -- reported 1.
Reported in #4945: a label built as { Label = 7, Weight = 4, Initial = 3 } reads
back as 7 1 3. StringLabel is unaffected because the text parser writes
simple_red_features.weight directly, which is why it round-trips correctly and
made the two paths disagree.
The consequence is worse than a bad round-trip: because ex->weight is what the
learner consumes, an importance weight supplied through SimpleLabel never
reached training at all -- every such example trained as though weighted 1.0.
Set the reduction feature, which is the source of truth and survives
setup_example, and keep assigning ex->weight so the value is also correct for
callers that never run setup_example.
Verified by driving the same native entry points the builder uses
(SimpleLabelUpdateExample -> VW::setup_example -> SimpleLabelReadFromExample):
before the change the harness reports "label=7 weight=1 initial=3", matching the
report exactly; after it reports "label=7 weight=4 initial=3" with ex->weight=4.
Adds two regression tests mirroring the reporter's: one that the weight
round-trips, and one that it actually affects training.
Closes #4945
Claude-Session: https://claude.ai/code/session_01EVprwZHP4KXAhsF6JGXK9k1 parent 01fa96a commit 1637cfc
2 files changed
Lines changed: 88 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 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 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
84 | 159 | | |
85 | 160 | | |
86 | 161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
29 | 38 | | |
30 | 39 | | |
31 | 40 | | |
| |||
0 commit comments