diyclassics commited on
Commit
246aab8
·
verified ·
1 Parent(s): 4465fd3

Release la_senter 3.9.2: add token_fix component (factory-registered, bundled fixers.py)

Browse files

Adds token_fix (paren/dash/quote boundary repair) to pipeline. New 3.9.2 wheel + adjacent fixers.py + updated model files and README. Prior 3.8.0/3.9.0 wheels retained.

Files changed (8) hide show
  1. .gitattributes +2 -0
  2. README.md +25 -4
  3. config.cfg +6 -3
  4. fixers.py +146 -0
  5. la_senter-3.9.2-py3-none-any.whl +3 -0
  6. meta.json +15 -19
  7. senter/model +0 -0
  8. vocab/strings.json +0 -0
.gitattributes CHANGED
@@ -34,3 +34,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  la_senter-3.9.0-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text
 
 
 
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  la_senter-3.9.0-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text
37
+ la_senter-3.9.2-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text
38
+ senter/model filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -31,10 +31,10 @@ Latin sentence segmentation model for [LatinCy](https://huggingface.co/latincy).
31
  | Feature | Description |
32
  | --- | --- |
33
  | **Name** | `la_senter` |
34
- | **Version** | `3.9.0` |
35
  | **spaCy** | `>=3.8.0,<3.9.0` |
36
- | **Default Pipeline** | `senter` |
37
- | **Components** | `senter` |
38
  | **Sources** | UD_Latin-Perseus, UD_Latin-PROIEL, UD_Latin-ITTB, UD_Latin-LLCT, UD_Latin-UDante |
39
  | **License** | `MIT` |
40
  | **Author** | [Patrick J. Burns](https://diyclassics.github.io/) |
@@ -42,7 +42,7 @@ Latin sentence segmentation model for [LatinCy](https://huggingface.co/latincy).
42
  ## Install
43
 
44
  ```bash
45
- pip install https://huggingface.co/latincy/la_senter/resolve/main/la_senter-3.9.0-py3-none-any.whl
46
  ```
47
 
48
  ## Usage
@@ -65,6 +65,27 @@ for sent in doc.sents:
65
  # sed Hercules ipse, fortissimus puer, haudquaquam territus est.
66
  ```
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  ## What's new in 3.9.0
69
 
70
  - Case-insensitive segmentation: correctly handles lowercased and mixed-case input
 
31
  | Feature | Description |
32
  | --- | --- |
33
  | **Name** | `la_senter` |
34
+ | **Version** | `3.9.2` |
35
  | **spaCy** | `>=3.8.0,<3.9.0` |
36
+ | **Default Pipeline** | `senter`, `token_fix` |
37
+ | **Components** | `senter`, `token_fix` |
38
  | **Sources** | UD_Latin-Perseus, UD_Latin-PROIEL, UD_Latin-ITTB, UD_Latin-LLCT, UD_Latin-UDante |
39
  | **License** | `MIT` |
40
  | **Author** | [Patrick J. Burns](https://diyclassics.github.io/) |
 
42
  ## Install
43
 
44
  ```bash
45
+ pip install https://huggingface.co/latincy/la_senter/resolve/main/la_senter-3.9.2-py3-none-any.whl
46
  ```
47
 
48
  ## Usage
 
65
  # sed Hercules ipse, fortissimus puer, haudquaquam territus est.
66
  ```
67
 
68
+ ## What's new in 3.9.2
69
+
70
+ This release adds **`token_fix`**, a rule-based component that runs after
71
+ `senter` to repair sentence boundaries around punctuation that the statistical
72
+ model mis-splits. It is bundled with the model and registered automatically as
73
+ a spaCy factory, so `spacy.load("la_senter")` activates it with no extra imports.
74
+
75
+ - **Parentheticals** — a `!` or `?` inside `(...)` or `[...]` no longer ends the
76
+ sentence: `Verba (mirabile dictu!) sunt.` stays one sentence.
77
+ - **Dash asides** — the same for em/en/hyphen-delimited asides:
78
+ `Nostraque — me miseram! — timui.` stays one sentence.
79
+ - **Orphaned closing quotes** — a sentence-final closing quote is kept with its
80
+ sentence rather than split onto the next: `"Ita est." "Dixit."` breaks after
81
+ the first closing quote, not before it.
82
+
83
+ ## 3.9.1
84
+
85
+ Internal development version — first bundled the fixers but was never published
86
+ to HuggingFace; superseded by 3.9.2 (which corrects the component registration
87
+ and aligns the version with the `latincy-pipelines` releases).
88
+
89
  ## What's new in 3.9.0
90
 
91
  - Case-insensitive segmentation: correctly handles lowercased and mixed-case input
config.cfg CHANGED
@@ -1,6 +1,6 @@
1
  [paths]
2
- train = "corpus/ud-train.spacy"
3
- dev = "corpus/ud-dev.spacy"
4
  vectors = null
5
  init_tok2vec = null
6
 
@@ -10,7 +10,7 @@ seed = 0
10
 
11
  [nlp]
12
  lang = "la"
13
- pipeline = ["senter"]
14
  batch_size = 1000
15
  disabled = []
16
  before_creation = null
@@ -48,6 +48,9 @@ depth = 2
48
  window_size = 1
49
  maxout_pieces = 2
50
 
 
 
 
51
  [corpora]
52
 
53
  [corpora.dev]
 
1
  [paths]
2
+ train = "corpus/train.spacy"
3
+ dev = "corpus/dev.spacy"
4
  vectors = null
5
  init_tok2vec = null
6
 
 
10
 
11
  [nlp]
12
  lang = "la"
13
+ pipeline = ["senter","token_fix"]
14
  batch_size = 1000
15
  disabled = []
16
  before_creation = null
 
48
  window_size = 1
49
  maxout_pieces = 2
50
 
51
+ [components.token_fix]
52
+ factory = "token_fix"
53
+
54
  [corpora]
55
 
56
  [corpora.dev]
fixers.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Rule-based sentence boundary fixers for la_senter."""
2
+
3
+ from typing import Callable
4
+
5
+ from spacy.language import Language
6
+ from spacy.tokens import Doc, Token
7
+
8
+ CLOSING_QUOTES = {
9
+ '"', # straight double (U+0022) — ambiguous
10
+ "”", # right double quotation mark " — definitively closing
11
+ "'", # straight single (U+0027) — ambiguous
12
+ "’", # right single quotation mark ' — definitively closing
13
+ "»", # right-pointing double angle quotation mark » — definitively closing
14
+ "›", # single right-pointing angle quotation mark › — definitively closing
15
+ }
16
+
17
+ # These characters unambiguously encode direction — no whitespace check needed
18
+ DEFINITIVELY_CLOSING = {"”", "’", "»", "›"}
19
+
20
+ # Hard terminals after which a quote is a closer, not an opener.
21
+ # Colon is excluded: in Latin, colon introduces direct speech ("loquitur: 'Rex...'")
22
+ # and a quote after colon is always an opener.
23
+ CLOSING_TERMINALS = {".", "!", "?", ";"}
24
+
25
+
26
+ def _is_likely_closing(token: Token) -> bool:
27
+ """Return True if a sentence-initial quote is closing an open speech.
28
+
29
+ For unambiguous closing characters (curly quotes, guillemets): always True.
30
+ For ambiguous straight/single quotes: True only when the immediately preceding
31
+ token is a hard sentence terminal (. ! ? ;). Colon is excluded because in
32
+ Latin it introduces direct speech and a quote after colon is an opener.
33
+ """
34
+ if token.text in DEFINITIVELY_CLOSING:
35
+ return True
36
+ return token.i > 0 and token.nbor(-1).text in CLOSING_TERMINALS
37
+
38
+
39
+ OPEN_BRACKETS = {"(", "["}
40
+ CLOSE_BRACKETS = {")", "]"}
41
+
42
+ # Unicode dash/hyphen characters used as parenthetical delimiters.
43
+ # Not added to OPEN_BRACKETS because bare - is too common in Latin
44
+ # (enclitic separators, verse markup) to treat as a bracket opener.
45
+ # Instead, _dash_paren_fix uses a stricter paired-with-terminal check.
46
+ DASH_CHARS = {
47
+ "-", # U+002D HYPHEN-MINUS
48
+ "—", # U+2014 EM DASH
49
+ "–", # U+2013 EN DASH
50
+ "‐", # U+2010 HYPHEN
51
+ "‑", # U+2011 NON-BREAKING HYPHEN
52
+ }
53
+ DASH_TERMINALS = {"!", "?"}
54
+
55
+
56
+ def paren_fix(doc: Doc) -> Doc:
57
+ """Suppress sentence boundaries that fall inside unclosed parentheses/brackets.
58
+
59
+ The senter treats '!' and '?' as terminals even inside parentheticals like
60
+ '(mirabile dictu!)'. This rule scans backward from each predicted boundary
61
+ to the previous sentence start, counting open vs. close brackets — if any
62
+ bracket is still open, the boundary is spurious and is suppressed.
63
+ """
64
+ for token in doc[1:]:
65
+ if not token.is_sent_start:
66
+ continue
67
+ depth = 0
68
+ for t in reversed(list(doc[:token.i])):
69
+ if t.text in CLOSE_BRACKETS:
70
+ depth += 1
71
+ elif t.text in OPEN_BRACKETS:
72
+ if depth > 0:
73
+ depth -= 1
74
+ else:
75
+ token.is_sent_start = False
76
+ break
77
+ if t.is_sent_start and t.i > 0:
78
+ break
79
+ return doc
80
+
81
+
82
+ def _dash_paren_fix(doc: Doc) -> Doc:
83
+ """Suppress boundaries where a dash-parenthetical contains a terminal.
84
+
85
+ Handles '- content! -' and '— content? —' asides. Only fires when:
86
+ 1. The sent_start token is itself a dash character (the closing dash), AND
87
+ 2. Scanning backward finds an opening dash of any DASH_CHARS type, AND
88
+ 3. A '!' or '?' appears between the two dashes.
89
+
90
+ This avoids the false-positive problem of bare '-' in Latin enclitic
91
+ separators (e.g. '-que') which must never suppress a sentence boundary.
92
+ """
93
+ for token in doc[1:]:
94
+ if not token.is_sent_start or token.text not in DASH_CHARS:
95
+ continue
96
+ found_terminal = False
97
+ for t in reversed(list(doc[:token.i])):
98
+ if t.is_sent_start and t.i > 0:
99
+ break
100
+ if t.text in DASH_TERMINALS:
101
+ found_terminal = True
102
+ elif t.text in DASH_CHARS and found_terminal:
103
+ token.is_sent_start = False
104
+ break
105
+ return doc
106
+
107
+
108
+ def quote_fix(doc: Doc) -> Doc:
109
+ for token in doc[1:]:
110
+ if (
111
+ token.is_sent_start
112
+ and token.text in CLOSING_QUOTES
113
+ and _is_likely_closing(token)
114
+ ):
115
+ token.is_sent_start = False
116
+ if token.i + 1 < len(doc):
117
+ doc[token.i + 1].is_sent_start = True
118
+ return doc
119
+
120
+
121
+ def token_fix(doc: Doc) -> Doc:
122
+ """Unified rules-based sentence boundary corrector for Latin text.
123
+
124
+ Applies all punctuation-aware corrections in a single pipeline pass:
125
+ - paren_fix: suppress boundaries inside unclosed parentheses/brackets
126
+ - quote_fix: move boundaries past orphaned closing quotes
127
+
128
+ Additional rules (em-dash parentheticals, etc.) should be added here.
129
+ """
130
+ doc = paren_fix(doc)
131
+ doc = _dash_paren_fix(doc)
132
+ doc = quote_fix(doc)
133
+ return doc
134
+
135
+
136
+ @Language.factory("token_fix")
137
+ def create_token_fix(nlp: Language, name: str) -> Callable[[Doc], Doc]:
138
+ """Factory for the token_fix pipeline component.
139
+
140
+ Registered as a factory (not Language.component) so spaCy records this
141
+ module as the factory's source. `spacy package` reads that module to derive
142
+ model requirements; the component form records 'spacy.language' instead,
143
+ which drops latincy-senter from the published model's dependencies.
144
+ token_fix itself stays a plain Doc -> Doc callable.
145
+ """
146
+ return token_fix
la_senter-3.9.2-py3-none-any.whl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef49bde9e9c7f38813b9c03961ca63aab1f434766b60f707475afdcc12f170c9
3
+ size 372482
meta.json CHANGED
@@ -1,14 +1,14 @@
1
  {
2
  "lang":"la",
3
  "name":"senter",
4
- "version":"3.8.0",
5
- "description":"",
6
  "author":"Patrick J. Burns",
7
  "email":"pjb311@nyu.edu",
8
- "url":"https://diyclassics.github.io/",
9
  "license":"MIT",
10
- "spacy_version":">=3.8.3,<3.9.0",
11
- "spacy_git_version":"be0fa81",
12
  "vectors":{
13
  "width":0,
14
  "vectors":0,
@@ -19,28 +19,24 @@
19
 
20
  },
21
  "pipeline":[
22
- "senter"
 
23
  ],
24
  "components":[
25
- "senter"
 
26
  ],
27
  "disabled":[
28
 
29
  ],
30
  "performance":{
31
- "sents_f":0.9961652241,
32
- "sents_p":0.9952928298,
33
- "sents_r":0.997039149,
34
- "senter_loss":32.5332645877
35
  },
36
- "sources":[
37
- "UD_Latin-Perseus",
38
- "UD_Latin-PROIEL",
39
- "UD_Latin-ITTB",
40
- "UD_Latin-LLCT",
41
- "UD_Latin-UDante"
42
- ],
43
  "requirements":[
44
- "spacy>=3.8.3,<3.9.0"
45
  ]
46
  }
 
1
  {
2
  "lang":"la",
3
  "name":"senter",
4
+ "version":"3.9.2",
5
+ "description":"Latin sentence segmentation model for LatinCy. Trained on Universal Dependencies treebanks (Perseus, PROIEL, ITTB, LLCT, UDante) with spaCy 3.8.x.",
6
  "author":"Patrick J. Burns",
7
  "email":"pjb311@nyu.edu",
8
+ "url":"https://github.com/diyclassics/latincy",
9
  "license":"MIT",
10
+ "spacy_version":">=3.8.11,<3.9.0",
11
+ "spacy_git_version":"e7a662a",
12
  "vectors":{
13
  "width":0,
14
  "vectors":0,
 
19
 
20
  },
21
  "pipeline":[
22
+ "senter",
23
+ "token_fix"
24
  ],
25
  "components":[
26
+ "senter",
27
+ "token_fix"
28
  ],
29
  "disabled":[
30
 
31
  ],
32
  "performance":{
33
+ "sents_f":0.9965670436,
34
+ "sents_p":0.9955618318,
35
+ "sents_r":0.9975742874,
36
+ "senter_loss":36.2972924755
37
  },
38
+ "parent_package":"spacy",
 
 
 
 
 
 
39
  "requirements":[
40
+ "spacy>=3.8.11,<3.9.0"
41
  ]
42
  }
senter/model CHANGED
Binary files a/senter/model and b/senter/model differ
 
vocab/strings.json CHANGED
The diff for this file is too large to render. See raw diff