Language Model¤
The language_model module is a wrapper around spaCy's training workflow for fine-tuning language models on custom corpora. It handles directory setup, config generation (including fine-tuning via component sourcing and transformer-based training via recipes), data conversion, training, evaluation, and packaging without requiring the user to edit config files or use the command line.
For a user-friendly overview, see Training Language Models in the User Guide. For hands-on walkthroughs, see the tutorial notebooks listed in Tutorials.
Constants¤
FULL_UD_PIPELINE: list[str] = ['tok2vec', 'tagger', 'morphologizer', 'trainable_lemmatizer', 'parser']
module-attribute
¤
rendering:
show_root_heading: true
heading_level: 3
CONLL-U Utilities¤
Standalone functions for preparing and managing CONLL-U training data.
split_conllu(input_path: str | Path, output_dir: str | Path, *, train_ratio: float = 0.8, dev_ratio: float = 0.1, seed: int = 42, shuffle: bool = True, include_test: bool = True) -> dict[str, Path]
¤
Split a single CONLL-U file into train / dev / (optionally) test files.
Sentences are the unit of splitting — sentence boundaries are blank lines in the CONLL-U format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
str | Path
|
Path to the source CONLL-U file. |
required |
output_dir
|
str | Path
|
Directory where split files will be written. |
required |
train_ratio
|
float
|
Fraction of sentences for the training split (default 0.8). |
0.8
|
dev_ratio
|
float
|
Fraction for the dev split (default 0.1). The test split receives whatever remains (1 - train_ratio - dev_ratio). |
0.1
|
seed
|
int
|
Random seed for reproducible shuffling (default 42). |
42
|
shuffle
|
bool
|
Whether to shuffle sentences before splitting. Set to False to preserve document order (e.g. split by act / chapter). |
True
|
include_test
|
bool
|
Whether to write a test file. Set to False for workflows that evaluate manually or with an external test set. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Path]
|
Dict with keys |
dict[str, Path]
|
mapping to the Path of each written file. The return value is designed |
dict[str, Path]
|
to be unpacked directly into :meth: splits = split_conllu("corpus.conllu", "model/assets/en/") model.copy_assets(**splits) |
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
export_to_conllu(model_path: str | Path, texts: list[str], output_path: str | Path) -> Path
¤
Run a trained model on texts and write predictions to a CONLL-U file.
Each element of texts can be a single sentence or a longer passage;
the model's sentence segmenter splits passages into individual sentences
automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str | Path
|
Path to a trained spaCy model directory, or an installed
model name (e.g. |
required |
texts
|
list[str]
|
List of strings to annotate. Each element may contain multiple sentences — the model's sentence segmenter handles splitting. |
required |
output_path
|
str | Path
|
Path where the CONLL-U output file will be written. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written output file. |
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
combine_conllu(round_files: list[str | Path], output_path: str | Path) -> Path
¤
Concatenate multiple CONLL-U files into a single training file.
Training on the full accumulated corpus each round (not just the latest batch) produces more stable models. Use this before each fine-tuning round to merge all corrected annotation batches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
round_files
|
list[str | Path]
|
List of paths to corrected CONLL-U files, in the order they should be concatenated. |
required |
output_path
|
str | Path
|
Path where the combined output file will be written. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written output file. |
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
The LanguageModel Class¤
The main entry point for the module. Manages the model directory, generates or loads the spaCy training config, and exposes the training lifecycle as method calls.
LanguageModel
¤
Manage the full lifecycle of a spaCy fine-tuning workflow.
Creates and maintains a self-contained model directory with the following structure::
model_dir/
├── config.cfg spaCy training configuration
├── assets/{lang}/ raw input data (CONLL-U files)
├── corpus/{lang}/ converted spaCy binary (.spacy) files
├── training/{lang}/ trained model checkpoints
└── metrics/{lang}/ evaluation output (JSON)
The config is generated automatically unless a recipe path is supplied.
When base_model is provided the config uses spaCy's component-sourcing
mechanism to warm-start from existing model weights instead of training from
random initialisation.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialise the LanguageModel and create its directory structure. |
convert_assets |
Convert CONLL-U files in assets/ to spaCy's binary format in corpus/. |
copy_assets |
Copy CONLL-U data files into the model's assets folder. |
evaluate |
Evaluate a trained model against a test set. |
load_config |
Replace the current config by loading from a file. |
package |
Package a trained model as a pip-installable distribution. |
save_config |
Write the in-memory config to disk. |
train |
Train the model using the current config. |
validate |
Run pre-training preflight checks and print a summary. |
Attributes:
| Name | Type | Description |
|---|---|---|
config_path |
Path
|
Path to the config.cfg file on disk. |
Source code in lexos/language_model/__init__.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 | |
config_path: Path
property
¤
Path to the config.cfg file on disk.
__init__(model_dir: str, *, lang: str = 'en', gpu: bool = False, components: list[str] | None = None, base_model: str | dict | None = None, recipe: str | None = None, force: bool = False) -> None
¤
Initialise the LanguageModel and create its directory structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir
|
str
|
Root folder for all model artefacts. |
required |
lang
|
str
|
BCP-47 language code (default |
'en'
|
gpu
|
bool
|
Use GPU for training (default |
False
|
components
|
list[str] | None
|
spaCy pipeline components to train. Defaults to the
full Universal Dependencies pipeline
|
None
|
base_model
|
str | dict | None
|
Starting point for fine-tuning. Three forms are accepted:
|
None
|
recipe
|
str | None
|
Path to a |
None
|
force
|
bool
|
Overwrite an existing |
False
|
Source code in lexos/language_model/__init__.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | |
convert_assets(*, n_sents: int = 10, merge_subtokens: bool = True) -> None
¤
Convert CONLL-U files in assets/ to spaCy's binary format in corpus/.
Groups every n_sents sentences into a single spaCy Doc. Larger
groups give the model more context during training but use more memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_sents
|
int
|
Sentences per Doc (0 to keep each sentence as its own Doc). |
10
|
merge_subtokens
|
bool
|
Merge CONLL-U multi-word tokens into single tokens. |
True
|
Source code in lexos/language_model/__init__.py
copy_assets(*, train: str | Path | None = None, dev: str | Path | None = None, test: str | Path | None = None) -> None
¤
Copy CONLL-U data files into the model's assets folder.
Accepts local paths or URLs (via smart_open). Also updates
config["paths"]["train"] and config["paths"]["dev"] to point
at the expected post-conversion .spacy files so that train()
can find them automatically.
The return value of :func:split_conllu can be unpacked directly::
splits = split_conllu("corpus.conllu", "model/assets/en/")
model.copy_assets(**splits)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train
|
str | Path | None
|
Path or URL to the training CONLL-U file. |
None
|
dev
|
str | Path | None
|
Path or URL to the development CONLL-U file. |
None
|
test
|
str | Path | None
|
Path or URL to the test CONLL-U file. |
None
|
Source code in lexos/language_model/__init__.py
evaluate(*, model: str | None = None, test_file: str | Path | None = None, gpu: bool = False, silent: bool = False) -> None
¤
Evaluate a trained model against a test set.
Defaults to CPU (gpu=False). Pass gpu=True to use GPU if
available — evaluation is fast and rarely needs it, but the option
is there.
Results are printed to stdout and saved as JSON to
metrics/{lang}/{lang}.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str | None
|
Path to a trained model directory. Defaults to
|
None
|
test_file
|
str | Path | None
|
Path to the test |
None
|
gpu
|
bool
|
Use GPU for evaluation (default |
False
|
silent
|
bool
|
Suppress console output (results are still saved to disk). |
False
|
Source code in lexos/language_model/__init__.py
load_config(*, filepath: str | Path | None = None) -> None
¤
Replace the current config by loading from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str | Path | None
|
Source path. Defaults to the model's config.cfg. |
None
|
Source code in lexos/language_model/__init__.py
package(input_dir: str | Path, output_dir: str | Path, name: str, version: str, *, force: bool = False, silent: bool = False) -> None
¤
Package a trained model as a pip-installable distribution.
Creates a source distribution (.tar.gz) that can be installed with
pip install and then loaded by package name with spacy.load().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dir
|
str | Path
|
Path to a trained model directory (e.g.
|
required |
output_dir
|
str | Path
|
Directory where the package will be written. |
required |
name
|
str
|
Short name for the package (e.g. |
required |
version
|
str
|
Semantic version string (e.g. |
required |
force
|
bool
|
Overwrite an existing package with the same name/version. |
False
|
silent
|
bool
|
Suppress console output. |
False
|
Source code in lexos/language_model/__init__.py
save_config(*, filepath: str | Path | None = None) -> None
¤
Write the in-memory config to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str | Path | None
|
Destination path. Defaults to the model's config.cfg. |
None
|
Source code in lexos/language_model/__init__.py
train(*, skip_validation: bool = False) -> None
¤
Train the model using the current config.
Reads config.cfg from disk (so any manual edits to that file are
respected), runs a preflight check via :meth:validate (unless
skip_validation=True), then initialises the spaCy pipeline and
runs the training loop. Progress is logged to stdout.
The trained model is saved to training/{lang}/model-best (best dev
score) and training/{lang}/model-last (final step).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip_validation
|
bool
|
Skip the pre-training preflight check (default
|
False
|
Source code in lexos/language_model/__init__.py
validate() -> None
¤
Run pre-training preflight checks and print a summary.
Verifies that:
- Assets exist in
assets/{lang}/and are non-empty. - Converted
.spacycorpus files are present (warns if missing, sinceconvert_assets()may not have been called yet). - The config file exists and passes spaCy's
debug_configcheck. - Training data passes spaCy's
debug_datacheck (if corpus exists).
Raises:
| Type | Description |
|---|---|
LexosException
|
If any check fails. All failures are reported before raising so the user can fix them in one round. |
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
__init__(model_dir: str, *, lang: str = 'en', gpu: bool = False, components: list[str] | None = None, base_model: str | dict | None = None, recipe: str | None = None, force: bool = False) -> None
¤
Initialise the LanguageModel and create its directory structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir
|
str
|
Root folder for all model artefacts. |
required |
lang
|
str
|
BCP-47 language code (default |
'en'
|
gpu
|
bool
|
Use GPU for training (default |
False
|
components
|
list[str] | None
|
spaCy pipeline components to train. Defaults to the
full Universal Dependencies pipeline
|
None
|
base_model
|
str | dict | None
|
Starting point for fine-tuning. Three forms are accepted:
|
None
|
recipe
|
str | None
|
Path to a |
None
|
force
|
bool
|
Overwrite an existing |
False
|
Source code in lexos/language_model/__init__.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | |
rendering:
show_root_heading: true
heading_level: 3
config_path: Path
property
¤
Path to the config.cfg file on disk.
rendering:
show_root_heading: true
heading_level: 3
save_config(*, filepath: str | Path | None = None) -> None
¤
Write the in-memory config to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str | Path | None
|
Destination path. Defaults to the model's config.cfg. |
None
|
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
load_config(*, filepath: str | Path | None = None) -> None
¤
Replace the current config by loading from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str | Path | None
|
Source path. Defaults to the model's config.cfg. |
None
|
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
copy_assets(*, train: str | Path | None = None, dev: str | Path | None = None, test: str | Path | None = None) -> None
¤
Copy CONLL-U data files into the model's assets folder.
Accepts local paths or URLs (via smart_open). Also updates
config["paths"]["train"] and config["paths"]["dev"] to point
at the expected post-conversion .spacy files so that train()
can find them automatically.
The return value of :func:split_conllu can be unpacked directly::
splits = split_conllu("corpus.conllu", "model/assets/en/")
model.copy_assets(**splits)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train
|
str | Path | None
|
Path or URL to the training CONLL-U file. |
None
|
dev
|
str | Path | None
|
Path or URL to the development CONLL-U file. |
None
|
test
|
str | Path | None
|
Path or URL to the test CONLL-U file. |
None
|
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
convert_assets(*, n_sents: int = 10, merge_subtokens: bool = True) -> None
¤
Convert CONLL-U files in assets/ to spaCy's binary format in corpus/.
Groups every n_sents sentences into a single spaCy Doc. Larger
groups give the model more context during training but use more memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_sents
|
int
|
Sentences per Doc (0 to keep each sentence as its own Doc). |
10
|
merge_subtokens
|
bool
|
Merge CONLL-U multi-word tokens into single tokens. |
True
|
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
validate() -> None
¤
Run pre-training preflight checks and print a summary.
Verifies that:
- Assets exist in
assets/{lang}/and are non-empty. - Converted
.spacycorpus files are present (warns if missing, sinceconvert_assets()may not have been called yet). - The config file exists and passes spaCy's
debug_configcheck. - Training data passes spaCy's
debug_datacheck (if corpus exists).
Raises:
| Type | Description |
|---|---|
LexosException
|
If any check fails. All failures are reported before raising so the user can fix them in one round. |
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
train(*, skip_validation: bool = False) -> None
¤
Train the model using the current config.
Reads config.cfg from disk (so any manual edits to that file are
respected), runs a preflight check via :meth:validate (unless
skip_validation=True), then initialises the spaCy pipeline and
runs the training loop. Progress is logged to stdout.
The trained model is saved to training/{lang}/model-best (best dev
score) and training/{lang}/model-last (final step).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip_validation
|
bool
|
Skip the pre-training preflight check (default
|
False
|
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
evaluate(*, model: str | None = None, test_file: str | Path | None = None, gpu: bool = False, silent: bool = False) -> None
¤
Evaluate a trained model against a test set.
Defaults to CPU (gpu=False). Pass gpu=True to use GPU if
available — evaluation is fast and rarely needs it, but the option
is there.
Results are printed to stdout and saved as JSON to
metrics/{lang}/{lang}.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str | None
|
Path to a trained model directory. Defaults to
|
None
|
test_file
|
str | Path | None
|
Path to the test |
None
|
gpu
|
bool
|
Use GPU for evaluation (default |
False
|
silent
|
bool
|
Suppress console output (results are still saved to disk). |
False
|
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
package(input_dir: str | Path, output_dir: str | Path, name: str, version: str, *, force: bool = False, silent: bool = False) -> None
¤
Package a trained model as a pip-installable distribution.
Creates a source distribution (.tar.gz) that can be installed with
pip install and then loaded by package name with spacy.load().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dir
|
str | Path
|
Path to a trained model directory (e.g.
|
required |
output_dir
|
str | Path
|
Directory where the package will be written. |
required |
name
|
str
|
Short name for the package (e.g. |
required |
version
|
str
|
Semantic version string (e.g. |
required |
force
|
bool
|
Overwrite an existing package with the same name/version. |
False
|
silent
|
bool
|
Suppress console output. |
False
|
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
_load_recipe(recipe: str, msg: Printer) -> None
¤
Load a config from a recipe file path.
The recipe's [nlp] pipeline becomes self.components so that
validation output and the score-weight calculation reflect the actual
pipeline being trained, not the constructor default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe
|
str
|
Path to a |
required |
msg
|
Printer
|
Printer used for status output. |
required |
Raises:
| Type | Description |
|---|---|
LexosException
|
If the recipe file cannot be found, or if the
recipe uses a transformer component and |
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
_resolve_sources(base_model: str | dict) -> dict[str, str]
¤
Normalise base_model to a component→source mapping.
rendering:
show_root_heading: true
heading_level: 3
_generate_finetune_config(sources: dict[str, str]) -> Config
¤
Build a Thinc Config that sources each component from an existing model.
Loads default_ud.cfg as the structural base (providing corpora,
training, and initialize sections), then replaces each component block
with a source = "..." entry. For factory-defined components
alongside a sourced tok2vec, the broken
${components.tok2vec.model.encode.width} variable reference is
replaced with the actual integer read from the source model's config.
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
_apply_config_defaults() -> None
¤
Set values that spaCy's config generator leaves unset or unusable.
Specifically:
- corpora.train.max_length = 2000 prevents runaway memory use on
very long documents during training.
- training.before_update = null silences spaCy's debug warning
about the missing key.
- training.score_weights assigns equal weight to each active
component's accuracy metric so the best-model checkpoint reflects
overall pipeline quality.
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
Debugging Utilities¤
Wrappers around spaCy's debugging commands for inspecting a model's config and data before training.
debug_config(config_path: str | Path, *, overrides: dict[str, Any] | None = None, code_path: str | Path | None = None, show_funcs: bool = False, show_vars: bool = False) -> None
¤
Validate a spaCy config file and report any errors.
Creates all registered objects described by the config and checks that every function reference is resolvable. Note: some validation errors are blocking — you may need to fix errors one round at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str | Path
|
Path to the |
required |
overrides
|
dict[str, Any] | None
|
Dict of config key overrides to test (e.g.
|
None
|
code_path
|
str | Path | None
|
Path to a Python file containing custom registered functions. |
None
|
show_funcs
|
bool
|
Print all registered functions used by the config. |
False
|
show_vars
|
bool
|
Print all config variables and their resolved values. |
False
|
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
debug_data(config_path: str | Path, *, overrides: dict[str, Any] | None = None, code_path: str | Path | None = None, ignore_warnings: bool = False, verbose: bool = False, no_format: bool = False) -> None
¤
Analyse and validate training and dev data, reporting stats and issues.
Useful for catching problems like missing labels, data imbalance, or
invalid annotations before a long training run. Raises LexosException
if spaCy's data checker finds errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str | Path
|
Path to the |
required |
overrides
|
dict[str, Any] | None
|
Dict of config key overrides. |
None
|
code_path
|
str | Path | None
|
Path to a Python file with custom registered functions. |
None
|
ignore_warnings
|
bool
|
Show only errors, not warnings. |
False
|
verbose
|
bool
|
Print additional explanations alongside stats. |
False
|
no_format
|
bool
|
Plain-text output without colour formatting. |
False
|
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
debug_model(config_path: str | Path, *, config_overrides: dict[str, Any] | None = None, component: str = 'tagger', layers: list[int] | None = None, dimensions: bool = False, parameters: bool = False, gradients: bool = False, attributes: bool = False, P0: bool = False, P1: bool = False, P2: bool = False, P3: bool = False, use_gpu: int = -1) -> None
¤
Inspect a trained model's internal layer structure and weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str | Path
|
Path to the |
required |
config_overrides
|
dict[str, Any] | None
|
Dict of config key overrides. |
None
|
component
|
str
|
Pipeline component to inspect (default |
'tagger'
|
layers
|
list[int] | None
|
Layer IDs to examine in detail. |
None
|
dimensions
|
bool
|
Print layer dimensions. |
False
|
parameters
|
bool
|
Print parameter counts. |
False
|
gradients
|
bool
|
Print gradient information. |
False
|
attributes
|
bool
|
Print component attributes. |
False
|
P0
|
bool
|
Print model state before training. |
False
|
P1
|
bool
|
Print model state after initialisation. |
False
|
P2
|
bool
|
Print model state after training. |
False
|
P3
|
bool
|
Print final predictions. |
False
|
use_gpu
|
int
|
GPU device ID or |
-1
|
Source code in lexos/language_model/__init__.py
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
rendering:
show_root_heading: true
heading_level: 3
fill_config(config_path: str | Path, output_file: str | Path, *, pretraining: bool = False, diff: bool = False, code_path: str | Path | None = None) -> None
¤
Fill a partial config file with spaCy defaults and save it.
Useful for debugging or understanding what a minimal config expands to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str | Path
|
Path to the partial |
required |
output_file
|
str | Path
|
Path where the filled config will be written. |
required |
pretraining
|
bool
|
Include pretraining config section. |
False
|
diff
|
bool
|
Print a visual diff of changes made. |
False
|
code_path
|
str | Path | None
|
Path to a Python file with custom registered functions. |
None
|
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
Internal Helpers¤
_has_nvidia_gpu() -> bool
¤
Return True if an NVIDIA GPU driver and nvidia-smi are accessible.
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
_get_tok2vec_width(source: str) -> int
¤
Read tok2vec output width from a model's config.cfg without loading weights.
Supports both local directory paths and installed spaCy package names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
An installed spaCy model name (e.g. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The integer width of the tok2vec encoder's output. |
Raises:
| Type | Description |
|---|---|
LexosException
|
If the config.cfg cannot be located or the width key is missing. |
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3
_patch_tok2vec_width(component_cfg: dict[str, Any], width: int) -> None
¤
Replace the tok2vec width variable reference with a concrete integer.
Thinc stores ${components.tok2vec.model.encode.width} as a literal
string until interpolation. When tok2vec is sourced that config path
disappears, so we walk the component dict and substitute the integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component_cfg
|
dict[str, Any]
|
A single component's config sub-dict (mutated in place). |
required |
width
|
int
|
The integer width to substitute for the variable reference. |
required |
Source code in lexos/language_model/__init__.py
rendering:
show_root_heading: true
heading_level: 3