Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Turn has_text off: measured against production, it did not earn its place

Daoud Clarkef31374348c99
diff --git a/mwmbl/management/commands/train_domain_moderation_model.py b/mwmbl/management/commands/train_domain_moderation_model.py
index 16f6cee..43cb88f 100644
--- a/mwmbl/management/commands/train_domain_moderation_model.py
+++ b/mwmbl/management/commands/train_domain_moderation_model.py
@@ -47,15 +47,16 @@ class Command(BaseCommand):
"--no-text", action="store_true", dest="no_text",
help="Fit on the domain name alone, ignoring the crawled page text vocabulary")
parser.add_argument(
- "--no-has-text", action="store_true", dest="no_has_text",
- help=("Drop the was-it-crawled indicator. Evidence is crawled newest-first, so it "
- "doubles as a proxy for recency and can move the score distribution through "
- "the serving threshold; --ablate measures whether it is doing that here"))
+ "--has-text", action="store_true", dest="has_text",
+ help=("Add the was-it-crawled indicator, which is off by default because it "
+ "measured worse on every metric: evidence is crawled newest-first, so it "
+ "doubles as a proxy for recency. Worth re-measuring with --ablate once "
+ "backfill_domain_evidence has evened out the coverage"))
parser.add_argument(
"--ablate", action="store_true",
- help=("Also train without the page-text vocabulary and without the has_text "
- "indicator, and report all three on the same split, so each is measured "
- "rather than guessed"))
+ help=("Also train with the has_text indicator and without the page-text "
+ "vocabulary, and report all three on the same split, so each feature is "
+ "measured rather than guessed"))
parser.add_argument(
"--derived", action="store_true",
help=("Add blocklist-derived rows for reason classes short of real data. Off by "
@@ -85,7 +86,7 @@ class Command(BaseCommand):
# no longer featurise - the gate falls back to the stored metrics and says so.
incumbent = load_published_model()
model, metrics = train(rows, version, use_text=not options["no_text"],
- use_has_text=not options["no_has_text"], incumbent=incumbent)
+ use_has_text=options["has_text"], incumbent=incumbent)
self.stdout.write(json.dumps(metrics, indent=2))
if options["ablate"]:
@@ -110,19 +111,23 @@ class Command(BaseCommand):
def _report_ablation(self, rows, version, full: dict) -> None:
"""Hold out each half of the page-text features in turn, on the same split.
- Same rows, same seed, so each line differs from the one above it by one thing. Both
+ Same rows, same seed, so each line differs from what ships by exactly one feature. Both
ranking quality and the *operating point* are reported: a feature can hold the ranking
- while shifting the score distribution through MODERATION_REJECT_THRESHOLD, which is
- what appears to have happened to has_text, and normalised AP alone cannot see it.
+ while shifting the score distribution through MODERATION_REJECT_THRESHOLD, and
+ normalised AP alone cannot see that.
+
+ The intervals are independent, not paired, so they overlap far more than the difference
+ between two lines is uncertain by. Read the direction across all four columns rather
+ than any single interval.
"""
_, no_text = train(rows, f"{version}-no-text", use_text=False, use_has_text=False)
- _, no_has_text = train(rows, f"{version}-no-has-text", use_has_text=False)
+ _, with_has_text = train(rows, f"{version}-has-text", use_has_text=True)
self.stdout.write("\nAblation - are the page-text features earning their place?")
self.stdout.write(f" {'':>22} {'norm AP':>17} {'reject P':>16} "
f"{'reject R':>16} {'unsure':>7}")
- for name, metrics in (("text + has_text", full),
- ("text, no has_text", no_has_text),
+ for name, metrics in (("text (shipped)", full),
+ ("text + has_text", with_has_text),
("domain name only", no_text)):
cold = metrics.get("cold_start")
if cold is None:
@@ -141,8 +146,8 @@ class Command(BaseCommand):
f"{sum(full.get('train_rows_by_source', {}).values())} training rows and "
f"{cold.get('rows_with_text', 0)} of {cold.get('rows', 0)} cold-start test rows "
f"have text.\n A large gap between those two makes has_text a proxy for recency "
- f"rather than for evidence, and the fix is to backfill evidence for the older "
- f"submissions rather than to argue about the feature.\n")
+ f"rather than for evidence, which is why it is off by default. Backfill evidence "
+ f"for the older\n submissions to close the gap, then re-read this table.\n")
@staticmethod
def _with_interval(value, interval) -> str:
diff --git a/mwmbl/moderation/artifacts/README.md b/mwmbl/moderation/artifacts/README.md
index e3740ae..f097f80 100644
--- a/mwmbl/moderation/artifacts/README.md
+++ b/mwmbl/moderation/artifacts/README.md
@@ -29,9 +29,17 @@ Every slice also reports `at_thresholds`: precision, recall and the unsure share
`MODERATION_REJECT_THRESHOLD` and `MODERATION_APPROVE_THRESHOLD`, each with an interval. PR-AUC
summarises every threshold, including ones nothing runs at, so a model can hold its ranking while
its score distribution drifts through the two the server serves — read `reject_precision` and
-`approve_error_rate` before believing a retrain is an improvement. `--ablate` holds out the
-page-text vocabulary and the `has_text` indicator separately and reports all three fits on the
-same split; `--no-text` and `--no-has-text` fit those variants directly.
+`approve_error_rate` before believing a retrain is an improvement. `--ablate` reports the shipped
+model, the same model plus the `has_text` indicator, and the domain-name-only model on the same
+split; `--no-text` and `--has-text` fit those variants directly.
+
+Measured on production data, the page-text vocabulary is worth **+0.143 normalised AP** on the
+cold-start slice (0.535 against 0.392) and halves the share of submissions the tool declines to
+judge (`unsure` 0.118 against 0.249). The `has_text` indicator is **off**, because it made every
+metric worse — normalised AP 0.535 → 0.521, reject precision 0.657 → 0.636, reject recall 0.121
+→ 0.111. Evidence is crawled newest-first, so with 46% of training rows and 92% of cold-start
+test rows carrying text the indicator is a proxy for recency, and recency is when the .ai spam
+wave happened. Re-measure it with `--ablate` once `backfill_domain_evidence` has closed that gap.
To reproduce the numbers without a production database, train from the sanitized judgments export
instead:
diff --git a/mwmbl/moderation/artifacts/metrics.json b/mwmbl/moderation/artifacts/metrics.json
index a98deda..3171957 100644
--- a/mwmbl/moderation/artifacts/metrics.json
+++ b/mwmbl/moderation/artifacts/metrics.json
@@ -115,8 +115,8 @@
"rows": 71,
"f1": {
"LANGUAGE": 0.0,
- "OTHER": 0.2609,
- "SPAM": 0.8547
+ "OTHER": 0.375,
+ "SPAM": 0.8148
},
"support": {
"LANGUAGE": 2,
@@ -130,7 +130,7 @@
},
"train_rows_with_text": 21,
"uses_text": true,
- "uses_has_text": true,
+ "uses_has_text": false,
"suggestion_influence": {
"real_rows": 3796,
"shown_a_suggestion": 0,
diff --git a/mwmbl/moderation/artifacts/model.joblib b/mwmbl/moderation/artifacts/model.joblib
index 69a773f..e2f7b99 100644
Binary files a/mwmbl/moderation/artifacts/model.joblib and b/mwmbl/moderation/artifacts/model.joblib differ
diff --git a/mwmbl/moderation/features.py b/mwmbl/moderation/features.py
index ceb7ba8..13c45c6 100644
--- a/mwmbl/moderation/features.py
+++ b/mwmbl/moderation/features.py
@@ -81,7 +81,7 @@ def shape_features(domain: str) -> list[float]:
]
-def indicator_features(example: "ModerationExample", use_has_text: bool = True) -> list[float]:
+def indicator_features(example: "ModerationExample", use_has_text: bool = False) -> list[float]:
"""The unscaled 0/1 features, in INDICATOR + OPTIONAL_INDICATOR name order."""
indicators = [float(example.domain.lower().startswith("www."))]
if use_has_text:
@@ -96,24 +96,26 @@ class Featuriser:
training saw rather than rebuilding one from different data.
"""
- def __init__(self, use_text: bool = True, use_has_text: bool = True):
+ def __init__(self, use_text: bool = True, use_has_text: bool = False):
"""``use_text`` fits the page-text vocabulary; ``use_has_text`` the "was it crawled at
- all" indicator. Two flags rather than one because the two can fail independently, and
- the August 2026 numbers suggest they did.
-
- ``has_text`` exists because an empty text block and a page whose words are all out of
- vocabulary produce the same all-zero TF-IDF row, and they are not the same thing. But
- evidence is crawled newest-first, so under a chronological split the indicator is also
- a proxy for *recency* - 46% of training rows against 92% of cold-start test rows in the
- first production run - and recency is when the .ai spam wave happened. A model can
- therefore learn ``has_text -> reject`` from the training mix and then apply it to a test
- set where almost everything has text: the ordering barely moves, so PR-AUC does not
- notice, but the whole score distribution shifts through the serving threshold and
- precision at the head collapses. Recall at 75% precision halved between the two
- production runs, which is the shape of exactly that.
-
- So it is ablatable, and the honest fix is to even out the coverage by backfilling
- evidence for older submissions rather than to argue about the feature.
+ all" indicator. Two flags rather than one because the two can fail independently - and
+ measured against production data, they did.
+
+ The vocabulary earns its place easily: holding it out costs 0.143 normalised AP on the
+ cold-start slice (0.535 -> 0.392) and doubles the share of submissions the tool declines
+ to have an opinion about (0.118 -> 0.249).
+
+ ``has_text`` is **off by default, because it was measured and did not help.** The idea
+ was sound - an uncrawled domain and a page whose words are all out of vocabulary produce
+ the same all-zero TF-IDF row, and they are not the same thing - but evidence is crawled
+ newest-first, so under a chronological split the indicator is also a proxy for *recency*
+ (46% of training rows against 92% of cold-start test rows), and recency is when the .ai
+ spam wave happened. Holding it out improved every metric measured: normalised AP 0.521
+ -> 0.535, reject precision 0.636 -> 0.657, reject recall 0.111 -> 0.121. Small against
+ their intervals, individually; consistent across all of them.
+
+ The flag stays so it can be re-measured once ``backfill_domain_evidence`` has evened out
+ the coverage, which is the condition under which it would start meaning what it says.
"""
self.use_text = use_text
self.use_has_text = use_has_text
diff --git a/mwmbl/moderation/train.py b/mwmbl/moderation/train.py
index 0db78f8..81cd0e8 100644
--- a/mwmbl/moderation/train.py
+++ b/mwmbl/moderation/train.py
@@ -120,15 +120,16 @@ def split_by_time(rows: list[TrainingRow]) -> tuple[list[TrainingRow], list[Trai
def train(rows: list[TrainingRow], version: str, use_text: bool = True,
- use_has_text: bool = True,
+ use_has_text: bool = False,
incumbent: Optional[ModerationModel] = None) -> tuple[ModerationModel, dict]:
"""Fit both heads and evaluate on held-out real rows only.
``use_text`` and ``use_has_text`` are the two halves of the page-text ablation - the
vocabulary and the was-it-crawled indicator - held out separately because they can fail
- independently. ``incumbent`` is the model currently being served; when given, the metrics
- carry a paired comparison against it on these exact test rows, which is the only comparison
- that means anything.
+ independently, and did: the vocabulary is worth 0.143 normalised AP and the indicator is
+ worth slightly less than nothing, so it defaults off. ``incumbent`` is the model currently
+ being served; when given, the metrics carry a paired comparison against it on these exact
+ test rows, which is the only comparison that means anything.
"""
train_rows, test_rows = split_by_time(rows)
logger.info("Training on %d rows (%d real), testing on %d real rows",
diff --git a/test/test_domain_moderation.py b/test/test_domain_moderation.py
index 27dbb44..2e1577c 100644
--- a/test/test_domain_moderation.py
+++ b/test/test_domain_moderation.py
@@ -188,7 +188,7 @@ def test_has_text_separates_an_uncrawled_domain_from_one_whose_words_are_unknown
newest-first, so under a chronological split most training rows have no text and most test
rows do; without this indicator the model cannot tell the two cases apart and the
difference is absorbed into an intercept fitted on the training mix."""
- featuriser = Featuriser()
+ featuriser = Featuriser(use_has_text=True)
featuriser.fit_transform([
ModerationExample("aianimegenerator.cloud", ["free ai anime generator tool"]),
ModerationExample("docs.python.org", ["python language reference tool"]),
@@ -213,7 +213,6 @@ def test_the_ablation_fits_the_same_features_minus_the_text_block():
without = Featuriser(use_text=False)
assert without.fit_transform(examples).shape[1] < with_text
assert without.text is None
- assert "has_text" in list(without.feature_names())
def test_a_judges_most_confident_approval_is_not_read_as_a_certain_rejection(tmp_path):
@@ -285,16 +284,16 @@ def test_has_text_can_be_held_out_independently_of_the_text_block():
ModerationExample("docs.python.org", ["python language reference tool"]),
ModerationExample("seobacklinkhub.org", ["best seo backlinks tool"])]
- both = Featuriser()
- no_indicator = Featuriser(use_has_text=False)
+ both = Featuriser(use_has_text=True)
+ shipped = Featuriser()
both.fit_transform(examples)
- no_indicator.fit_transform(examples)
+ shipped.fit_transform(examples)
assert "has_text" in list(both.feature_names())
- assert "has_text" not in list(no_indicator.feature_names())
- assert no_indicator.text is not None # the vocabulary block is still there
- assert (no_indicator.transform(examples).shape[1]
- == both.transform(examples).shape[1] - 1)
+ # Off by default: measured against production data it made every metric worse.
+ assert "has_text" not in list(shipped.feature_names())
+ assert shipped.text is not None # the vocabulary block is still there
+ assert shipped.transform(examples).shape[1] == both.transform(examples).shape[1] - 1
def test_malformed_historic_names_are_excluded_from_training():