Choosing training splits for DaCy#
DaCy is trained on the Danish Dependency Treebank (DDT) and the annotations built on top of it: named entities (DaNE) and coreference (DaCoref). The texts come from the Copenhagen Dependency Treebank (CDT), where they are documents. When CDT was converted to DDT, the sentences were shuffled across the train, dev and test splits, so the sentences of one document can end up in different splits. For example, a document with six sentences could be split like this:
Document: s1 s2 s3 s4 s5 s6
DDT split: train test train dev train train
This is common: a typical document has 10 sentences, and 394 of the 536 documents have sentences in more than one split.
This also means that the standard DDT split leaks a little information from training into testing. Sentences from the same document share names, topics and words, so a model trained on DDT train has often seen the entities of a test sentence in the same document: 56 of the 558 named entities in the DDT test sentences (10%) also occur in a DDT train sentence from the same document, and for 36 of them (6%, e.g. Rushdie and Palle Kreiberg), that is the only place they occur in the training data. This applies to every model trained and tested on the DDT split.
Since DaCy 0.2.0, we have trained on whole documents as this is required for training models for coreference resolution and similarly we saw quite an improvement especially in sentence segmentation, named entity recognition and downstream generalization. However, this has also made the test split of the DaCy models incomparable with the existing test split, and DaCy models cannot simply be scored on the DDT or DaNE test sets either, since they have seen some of those test sentences during training. This blog post goes through our examination of the different options.
The options#
Each way of handling the shuffled documents gives up something. For the document above, the main options are:
Whole documents, new split. Keep each document whole and assign it to a single split, as the current data does. The documents stay intact, but the test set is no longer the DDT test set.
Fragments. Cut each document into one piece per DDT split, keeping the sentences of each piece in their original order. This keeps the DDT splits exactly, but the pieces have gaps where the sentences of the other splits were:
Train fragment: s1 s3 s5 s6 (s2 and s4 are missing) Dev fragment: s4 Test fragment: s2
This rules out coreference: a mention in s2 can refer to an entity introduced in s1, and the fragments separate the two, so coreference clusters that cross the splits are cut apart.
Whole documents, unlabelled test sentences. Train on the whole document, but remove the labels of s2 and s4, so the model sees their text but not their annotation. This keeps both the documents and the DDT splits, but the model sees the text of the test sentences during training.
Single sentences. Ignore the documents and train on each DDT sentence on its own.
We compared these four options. As a control for the amount of data, we also trained on whole documents cut to the same size as the fragments (D_sm). The last column shows whether an option can be used for annotations that span whole documents, such as coreference, which links mentions across sentences:
Training data |
Documents |
Standard test set |
Test text unseen |
Supports whole-document annotations |
|
|---|---|---|---|---|---|
A |
Documents cut into fragments, one per DDT split |
Fragments |
Yes |
Yes |
No |
B |
Single sentences |
None |
Yes |
Yes |
No |
C |
Whole documents, with the dev and test sentences unlabelled |
Whole |
Yes |
No |
Yes |
D |
Whole documents, fully labelled: all CDT documents except the held-out ones (so it includes DDT dev and test sentences from other documents) |
Whole, for all 536 documents |
No |
Yes |
Yes |
D_sm |
As D, but cut to the same size as A (control) |
Whole |
No |
Yes |
Yes |
To compare them fairly, all models are tested on the same 300 DDT test sentences (5,377 tokens, from 35 documents). These are held out from every training set: no model has seen their labels, and only C has seen their text. We also exclude the 163 DDT test sentences that are in the current training data.
We trained the smallest DaCy model (dacy_edge) on each training set for 5,000 steps with a fixed batch size of 1,000 words, with 3 seeds, and scored the final model. The fixed batch size makes the runs compute matched: every model sees about the same amount of text. The configs we used are in configs/. To test the models as they are used, on running text, each model processes the full held-out documents, and only the held-out sentences are scored. This includes finding the sentence boundaries. We report the mean over seeds. The 95% confidence intervals come from resampling the 35 held-out documents (a bootstrap over documents), since sentences from the same document are not independent.
How much does the split matter?#
Scores on the held-out sentences:
POS |
Lemma |
LAS |
NER F |
Sentence F |
|
|---|---|---|---|---|---|
A: fragments |
94.3 |
93.8 |
73.7 |
63.5 |
95.1 |
B: single sentences |
94.2 |
93.6 |
67.6 |
60.1 |
20.8 |
C: whole, test unlabelled |
94.3 |
93.7 |
72.9 |
61.6 |
94.2 |
D: whole, fully labelled |
94.7 |
94.3 |
74.5 |
62.9 |
94.6 |
D_sm: as D, same size as A |
94.3 |
94.0 |
73.6 |
63.1 |
95.5 |
In each column, the best score and the scores that are not significantly below it (95% confidence interval of the difference includes zero) are in bold (see Full results for the differences with their intervals).
1. Context matters for running text. The model trained on single sentences (B) tags words as well as the others, but it cannot find the sentence boundaries in running text (sentence F 20.8), and its LAS drops by 6.1 points.
2. Fragments are as good as whole documents. Cutting the documents into fragments (A) costs nothing we can measure: on the full documents, A and whole documents of the same size (D_sm) are within 0.4 points on every metric, and none of the differences are significant. Whole documents with unlabelled test sentences (C) are within 0.9 points of A, except on NER, where C is 2.0 points lower (95% CI −4.0 to −0.2).
3. More data helps a little. Fully labelled whole documents (D) score highest, slightly above A on POS (+0.4) and lemmas (+0.5), but the advantage disappears when D is cut to the same size (D_sm). D simply has more labelled text (95k vs 80k tokens).
Do the results hold for a transformer model?#
The smallest model has no transformer, while the larger DaCy models do. So we repeated the experiment with the DaCy medium model, using the configuration of DaCy medium 1.0.0 (with the transformer vesteinn/ScandiBERT-no-faroese). Each model was trained for 10,000 steps with the same fixed batch size, with 3 seeds, and tested on the same held-out sentences:
POS |
Morph |
Lemma |
LAS |
NER F |
Sentence F |
|
|---|---|---|---|---|---|---|
A: fragments |
98.5 |
98.3 |
96.0 |
86.3 |
79.8 |
96.5 |
B: single sentences |
98.4 |
98.2 |
95.5 |
80.0 |
78.4 |
25.6 |
C: whole, test unlabelled |
98.3 |
98.0 |
95.7 |
85.0 |
80.3 |
94.3 |
D: whole, fully labelled |
98.6 |
98.2 |
96.2 |
86.8 |
83.0 |
96.9 |
D_sm: as D, same size as A |
98.6 |
98.3 |
96.3 |
86.4 |
82.4 |
96.6 |
Bold marks the best score in each column and the scores that are not significantly below it (see Full results for the differences between the training sets).
The conclusions from the smallest model hold: without document context (B), the model again cannot find the sentence boundaries (sentence F 25.6) and loses 6.3 points LAS, and fragments and whole documents of the same size (D_sm) are on par on POS, morphology, LAS and sentence boundaries.
The transformer model does gain from whole documents on NER: D is 3.3 points above A (95% CI 1.4 to 5.2), and D_sm is 2.6 points above A (0.5 to 4.7), so the gain comes from the document context and not only from the extra data. Whole documents are also slightly better at lemmatization (+0.3 for both). Whole documents with unlabelled test sentences (C) are slightly behind A on LAS (−1.3) and lemmatization (−0.3).
The confidence intervals cover the choice of test documents, but not the randomness of training; the standard deviations over seeds are in Full results.
Does seeing the unlabelled test text inflate scores?#
Option C keeps both the documents and the DDT test set, but the model sees the text of the test sentences during training, without their labels. Could that inflate the test scores? To find out, we trained a second version of C in which the 300 held-out sentences are removed from the text (C−H). The other dev and test sentences stay in, unlabelled. For a document where s2 is one of the held-out sentences:
Document: s1 s2 s3 s4 s5 s6 s7
DDT split: train test (H) train dev train train test
C: s1 s2 s3 s4 s5 s6 s7 s2, s4 and s7 unlabelled
C−H: s1 s3 s4 s5 s6 s7 s2 removed; s4 and s7 unlabelled
Both are trained on the same labels, so the only difference is whether the model has seen the text of the held-out sentences:
POS |
Lemma |
LAS |
NER F |
Sentence F |
|
|---|---|---|---|---|---|
C: has seen the held-out text |
94.3 (93.8–94.8) |
93.7 (92.9–94.5) |
72.9 (70.8–74.9) |
61.6 (54.8–68.9) |
94.2 (91.7–96.2) |
C−H: has not |
94.3 (93.7–94.8) |
93.9 (93.1–94.6) |
72.8 (70.7–74.9) |
62.4 (55.9–69.0) |
94.4 (92.2–96.2) |
Difference |
0.0 (−0.3 to +0.3) |
−0.2 (−0.4 to +0.1) |
+0.1 (−0.8 to +1.0) |
−0.8 (−3.6 to +2.0) |
−0.2 (−1.4 to +1.0) |
The confidence intervals of all differences include 0, and NER is even lower for C. The medium model gives the same result: C and C−H are within 0.7 points of each other on every metric, and all confidence intervals include 0 (see Full results). Seeing the test text without labels does not inflate the scores.
Comparison with spaCy#
How do these models compare with spaCy’s transformer model (da_core_news_trf 3.8)? spaCy’s Danish models are trained on the DDT train split and tested on the DDT test set, so we score the DaCy medium models on the same test set: all 565 DDT test sentences, processed in their full documents, with the surrounding train and dev sentences as context. We use the models trained on fragments (A), which keep the DDT test set. D contains labelled DDT test sentences, so it cannot be compared.
POS |
Lemma |
LAS |
NER F |
Sentence F |
|
|---|---|---|---|---|---|
spaCy |
98.4 (98.1–98.6) |
95.6 (95.1–96.0) |
86.6 (85.4–87.8) |
83.4 (78.7–87.4) |
97.8 (96.6–98.9) |
DaCy medium, A: fragments |
98.4 (98.1–98.7) |
95.9 (95.5–96.4) |
85.9 (84.6–87.1) |
82.9 (78.3–86.9) |
97.6 (95.9–98.9) |
Bold marks the best score in each column and the scores that are not significantly below it.
Trained on fragments, the DaCy medium recipe is on par with spaCy: it is slightly better at lemmatization (+0.3, 95% CI +0.1 to +0.6) and slightly behind on LAS (−0.8, CI −1.5 to −0.0), and the other differences are not significant. spaCy’s model is trained on an older release of DDT, whose part-of-speech tags and dependencies differ slightly from the version we test on, which may cost it a little on POS and LAS.
Conclusion#
Overall there is no option without any issues. Keeping the current DDT split (option A, B, C) inherits the leakage in the DDT split, but remains comparable, while options that define a new split (D) lose that. However, after our examination we can at least filter out a few cases. The current default for DDT, single sentence (B), leads to systematic issues in sentence segmentation with A and C being clear upgrades. Similarly, A would not support whole-document annotations in the future so would block us which leaves C and D. What remains is a question of comparability with existing models and using C or prevent leakage caused by within document samples (e.g. same entities repeating in train and test) and use D instead. Additionally D has the added benefit that the data structure is simpler with all documents being fully annotated instead of partly annotated.
Overall the performance differences between the top solutions are minor and would likely come out slightly differently between runs.
Reproducing#
The scripts are in scripts/, and the held-out sentences are listed in held_out.json. Internally, the scripts name the training sets B (fragments), C (single sentences), D (whole, unlabelled), D-H, E (whole, new split) and E_sm, and A is the DaCy 1.0.0 data, which is not included in this post; analyze.py prints the names used here. The experiment builds on version 2.9.0 of chcaa/dacy-data, the data of DaCy 1.0.0. From training/ in the DaCy repository, with the dacy-data submodule:
POST=../docs/blog/2026-11-25-train-test-split
OUT=../output/train-test-split # outside docs/, which Sphinx builds
CDT_COMMIT=f72eb56a05f0105f4f20e242bde2131685240653
git -C dacy-data checkout v2.9.0
(cd dacy-data && make && uv run python ../$POST/scripts/cdt_full.py --commit $CDT_COMMIT \
&& uv run python ../$POST/scripts/build_training_sets.py . ../$OUT)
$POST/scripts/train_all.sh $OUT
uv run --python 3.12 --with "spacy>=3.8,<3.9" --with spacy-lookups-data python $POST/scripts/evaluate.py $OUT
uv run --with numpy python $POST/scripts/analyze.py $OUT
Full results#
Show the full results
Scores on the 300 held-out sentences, processed in their full documents: the mean over 3 seeds, with 95% confidence intervals from a bootstrap over the 35 held-out documents. Bold marks the best score in each column and the scores that are not significantly below it.
Smallest model (dacy_edge)#
Training data |
POS |
Morph |
Lemma |
LAS |
NER F |
Sentence F |
|---|---|---|---|---|---|---|
A: fragments |
94.3 (93.8–94.8) |
93.3 (92.6–94.0) |
93.8 (93.1–94.5) |
73.7 (71.6–75.9) |
63.5 (56.4–71.2) |
95.1 (92.9–96.7) |
B: single sentences |
94.2 (93.6–94.8) |
93.3 (92.6–94.0) |
93.6 (92.8–94.4) |
67.6 (66.0–69.3) |
60.1 (53.3–67.4) |
20.8 (17.9–24.7) |
C: whole, test unlabelled |
94.3 (93.8–94.8) |
93.3 (92.5–94.0) |
93.7 (92.9–94.5) |
72.9 (70.8–74.9) |
61.6 (54.8–68.9) |
94.2 (91.7–96.2) |
C−H: as C, without the test sentences |
94.3 (93.7–94.8) |
93.2 (92.4–94.0) |
93.9 (93.1–94.6) |
72.8 (70.7–74.9) |
62.4 (55.9–69.0) |
94.4 (92.2–96.2) |
D: whole, fully labelled |
94.7 (94.1–95.3) |
93.5 (92.7–94.2) |
94.3 (93.6–95.0) |
74.5 (72.6–76.4) |
62.9 (55.9–70.9) |
94.6 (92.3–96.4) |
D_sm: as D, same size as A |
94.3 (93.7–94.8) |
93.1 (92.3–93.8) |
94.0 (93.2–94.7) |
73.6 (71.7–75.5) |
63.1 (56.0–70.8) |
95.5 (92.7–97.5) |
Difference to fragments (A). * marks differences whose 95% confidence interval excludes 0.
Difference |
POS |
Morph |
Lemma |
LAS |
NER F |
Sentence F |
|---|---|---|---|---|---|---|
B − A |
-0.1 (-0.4, +0.2) |
+0.0 (-0.3, +0.3) |
-0.2 (-0.4, +0.0) |
-6.1 (-7.3, -4.9)* |
-3.5 (-7.1, -0.3)* |
-74.3 (-77.7, -69.8)* |
C − A |
-0.0 (-0.4, +0.3) |
-0.0 (-0.4, +0.4) |
-0.1 (-0.4, +0.2) |
-0.8 (-1.9, +0.3) |
-2.0 (-4.0, -0.2)* |
-0.9 (-2.0, +0.2) |
C−H − A |
-0.0 (-0.4, +0.3) |
-0.1 (-0.4, +0.2) |
+0.0 (-0.2, +0.3) |
-0.9 (-1.9, +0.0) |
-1.2 (-3.8, +1.2) |
-0.7 (-1.6, +0.2) |
D − A |
+0.4 (+0.1, +0.6)* |
+0.2 (-0.2, +0.5) |
+0.5 (+0.1, +0.8)* |
+0.8 (-0.3, +1.8) |
-0.6 (-2.4, +1.2) |
-0.5 (-1.2, +0.3) |
D_sm − A |
-0.1 (-0.4, +0.2) |
-0.2 (-0.6, +0.2) |
+0.2 (-0.1, +0.5) |
-0.1 (-1.0, +0.8) |
-0.4 (-3.3, +2.3) |
+0.4 (-0.6, +1.4) |
C − C−H (seeing the test text) |
+0.0 (-0.3, +0.3) |
+0.1 (-0.3, +0.4) |
-0.2 (-0.4, +0.1) |
+0.1 (-0.8, +1.0) |
-0.8 (-3.6, +2.0) |
-0.2 (-1.4, +1.0) |
Standard deviation over the 3 seeds:
A: POS 0.17, Morph 0.21, Lemma 0.04, LAS 0.45, NER F 1.45, Sentence F 0.55
B: POS 0.07, Morph 0.10, Lemma 0.08, LAS 0.25, NER F 0.92, Sentence F 0.06
C: POS 0.14, Morph 0.11, Lemma 0.07, LAS 0.49, NER F 3.21, Sentence F 0.12
C−H: POS 0.11, Morph 0.13, Lemma 0.25, LAS 0.31, NER F 1.21, Sentence F 0.60
D: POS 0.13, Morph 0.20, Lemma 0.09, LAS 0.48, NER F 0.64, Sentence F 0.53
D_sm: POS 0.22, Morph 0.14, Lemma 0.08, LAS 0.36, NER F 1.13, Sentence F 0.33
Medium model (dacy_medium)#
Training data |
POS |
Morph |
Lemma |
LAS |
NER F |
Sentence F |
|---|---|---|---|---|---|---|
A: fragments |
98.5 (98.2–98.9) |
98.3 (97.8–98.7) |
96.0 (95.3–96.6) |
86.3 (84.7–88.0) |
79.8 (72.2–86.3) |
96.5 (93.3–98.6) |
B: single sentences |
98.4 (98.0–98.7) |
98.2 (97.7–98.6) |
95.5 (94.8–96.2) |
80.0 (78.5–81.5) |
78.4 (69.6–85.9) |
25.6 (22.2–29.9) |
C: whole, test unlabelled |
98.3 (97.6–98.8) |
98.0 (97.3–98.6) |
95.7 (94.9–96.4) |
85.0 (83.0–86.9) |
80.3 (72.5–87.2) |
94.3 (90.3–97.3) |
C−H: as C, without the test sentences |
98.4 (98.0–98.7) |
98.1 (97.6–98.5) |
95.7 (95.0–96.5) |
85.0 (83.3–86.8) |
80.0 (72.2–86.8) |
95.0 (92.1–97.3) |
D: whole, fully labelled |
98.6 (98.3–98.9) |
98.2 (97.8–98.7) |
96.2 (95.6–96.8) |
86.8 (85.2–88.4) |
83.0 (75.6–89.1) |
96.9 (94.6–98.6) |
D_sm: as D, same size as A |
98.6 (98.3–98.9) |
98.3 (97.8–98.6) |
96.3 (95.6–96.9) |
86.4 (84.6–88.1) |
82.4 (74.1–89.5) |
96.6 (94.2–98.4) |
Difference to fragments (A). * marks differences whose 95% confidence interval excludes 0.
Difference |
POS |
Morph |
Lemma |
LAS |
NER F |
Sentence F |
|---|---|---|---|---|---|---|
B − A |
-0.2 (-0.3, -0.0)* |
-0.1 (-0.3, +0.1) |
-0.5 (-0.7, -0.2)* |
-6.3 (-7.2, -5.4)* |
-1.4 (-4.4, +1.7) |
-70.9 (-75.3, -65.5)* |
C − A |
-0.2 (-0.8, +0.1) |
-0.2 (-0.7, +0.1) |
-0.3 (-0.5, -0.1)* |
-1.3 (-2.6, -0.4)* |
+0.6 (-1.2, +2.5) |
-2.2 (-5.8, +0.2) |
C−H − A |
-0.2 (-0.4, +0.1) |
-0.2 (-0.4, +0.0) |
-0.2 (-0.4, -0.0)* |
-1.3 (-2.1, -0.6)* |
+0.2 (-1.3, +1.8) |
-1.6 (-3.1, -0.2)* |
D − A |
+0.0 (-0.1, +0.2) |
-0.0 (-0.2, +0.2) |
+0.3 (+0.0, +0.5)* |
+0.5 (-0.1, +1.1) |
+3.3 (+1.4, +5.2)* |
+0.4 (-0.4, +1.4) |
D_sm − A |
+0.0 (-0.2, +0.3) |
-0.0 (-0.2, +0.2) |
+0.3 (+0.0, +0.6)* |
+0.0 (-0.6, +0.6) |
+2.6 (+0.5, +4.7)* |
+0.0 (-0.9, +1.1) |
C − C−H (seeing the test text) |
-0.1 (-0.6, +0.3) |
-0.0 (-0.5, +0.3) |
-0.1 (-0.3, +0.2) |
-0.0 (-1.1, +0.8) |
+0.3 (-1.1, +1.8) |
-0.7 (-3.6, +1.3) |
Standard deviation over the 3 seeds:
A: POS 0.05, Morph 0.10, Lemma 0.13, LAS 0.66, NER F 1.02, Sentence F 0.40
B: POS 0.20, Morph 0.17, Lemma 0.05, LAS 0.34, NER F 0.86, Sentence F 5.97
C: POS 0.11, Morph 0.14, Lemma 0.02, LAS 0.31, NER F 0.72, Sentence F 1.50
C−H: POS 0.10, Morph 0.08, Lemma 0.14, LAS 0.32, NER F 0.35, Sentence F 0.29
D: POS 0.09, Morph 0.06, Lemma 0.03, LAS 0.34, NER F 1.17, Sentence F 0.53
D_sm: POS 0.04, Morph 0.07, Lemma 0.04, LAS 0.03, NER F 0.50, Sentence F 0.33