vukrosic commited on
Commit
4b8b927
·
verified ·
1 Parent(s): 0faa578

Upload test_nano_proofread.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. test_nano_proofread.py +61 -0
test_nano_proofread.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests that gate the science: identity examples exist, most inputs carry an error,
2
+ corrected phrases are clean (no doubled words), determinism, the context-free script
3
+ provably fails on a real fraction (the must-beat-a-script filter), and a regression
4
+ test that the PUBLISHED weights still fix the demo phrases.
5
+
6
+ pytest test_nano_proofread.py -q
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import os
12
+
13
+ from data_proofread import naive_fix, proofread_pairs
14
+
15
+
16
+ def test_identity_examples_exist():
17
+ pairs = proofread_pairs(7, 4000)
18
+ ident = sum(1 for i, t in pairs if i[:-4] == t)
19
+ assert 0.08 <= ident / len(pairs) <= 0.25
20
+
21
+
22
+ def test_most_inputs_have_an_error():
23
+ pairs = proofread_pairs(3, 4000)
24
+ changed = sum(1 for i, t in pairs if i[:-4] != t)
25
+ assert changed / len(pairs) > 0.7
26
+
27
+
28
+ def test_targets_are_clean():
29
+ for _, tgt in proofread_pairs(5, 2000):
30
+ toks = tgt.split()
31
+ assert all(toks[i] != toks[i + 1] for i in range(len(toks) - 1)), tgt
32
+
33
+
34
+ def test_deterministic():
35
+ assert proofread_pairs(0, 300) == proofread_pairs(0, 300)
36
+
37
+
38
+ def test_context_free_script_cannot_be_exact():
39
+ """The best context-free script must get a real fraction of examples wrong,
40
+ because the homophone confusions are context-dependent."""
41
+ pairs = proofread_pairs(11, 4000)
42
+ wrong = sum(1 for inp, tgt in pairs if naive_fix(inp[:-4]) != tgt)
43
+ assert wrong > 0.15 * len(pairs)
44
+
45
+
46
+ def test_published_weights_reproduce():
47
+ if not (os.path.exists("model.safetensors") and os.path.exists("config.json")):
48
+ import pytest
49
+ pytest.skip("weights not present in this checkout")
50
+ from modeling_nano_proofread import load, proofread
51
+ m = load()
52
+ for phrase, gold in [
53
+ ("their going to win", "they're going to win"),
54
+ ("its raining again", "it's raining again"),
55
+ ("the the cat sat", "the cat sat"),
56
+ ("we went they're", "we went there"),
57
+ ("this is bigger then that", "this is bigger than that"),
58
+ ("they're house is big", "their house is big"),
59
+ ("she is happy today", "she is happy today"), # already correct -> unchanged
60
+ ]:
61
+ assert proofread(m, phrase) == gold, (phrase, proofread(m, phrase))