dipo 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dipo/__init__.py +22 -0
- dipo/__main__.py +103 -0
- dipo/common/__init__.py +0 -0
- dipo/common/log.py +65 -0
- dipo/common/training.py +613 -0
- dipo/rst/__init__.py +34 -0
- dipo/rst/data/__init__.py +0 -0
- dipo/rst/data/metrics.py +280 -0
- dipo/rst/data/reader.py +280 -0
- dipo/rst/data/seg_metrics.py +157 -0
- dipo/rst/data/tree.py +1106 -0
- dipo/rst/parsers/__init__.py +94 -0
- dipo/rst/parsers/common/__init__.py +0 -0
- dipo/rst/parsers/common/biaffine.py +49 -0
- dipo/rst/parsers/common/config.py +135 -0
- dipo/rst/parsers/common/curriculum.py +144 -0
- dipo/rst/parsers/common/detokenization.py +43 -0
- dipo/rst/parsers/common/encoding.py +474 -0
- dipo/rst/parsers/common/generative_eval.py +232 -0
- dipo/rst/parsers/common/inference.py +107 -0
- dipo/rst/parsers/common/pointer.py +47 -0
- dipo/rst/parsers/common/predict_cli.py +152 -0
- dipo/rst/parsers/common/segmentation.py +300 -0
- dipo/rst/parsers/common/seqgen.py +522 -0
- dipo/rst/parsers/common/sexp_constraints.py +763 -0
- dipo/rst/parsers/common/whitespace.py +110 -0
- dipo/rst/parsers/dmrst/__init__.py +2 -0
- dipo/rst/parsers/dmrst/configuration_dmrst.py +174 -0
- dipo/rst/parsers/dmrst/modeling_dmrst.py +818 -0
- dipo/rst/parsers/dmrst/predict_dmrst.py +9 -0
- dipo/rst/parsers/dmrst/train_dmrst.py +528 -0
- dipo/rst/parsers/gen/__init__.py +4 -0
- dipo/rst/parsers/gen/backbones/__init__.py +10 -0
- dipo/rst/parsers/gen/backbones/base.py +466 -0
- dipo/rst/parsers/gen/backbones/decoder_only.py +415 -0
- dipo/rst/parsers/gen/backbones/seq2seq.py +372 -0
- dipo/rst/parsers/gen/configuration_gen.py +299 -0
- dipo/rst/parsers/gen/decode.py +337 -0
- dipo/rst/parsers/gen/errors.py +31 -0
- dipo/rst/parsers/gen/eval_gen.py +176 -0
- dipo/rst/parsers/gen/modeling_gen.py +393 -0
- dipo/rst/parsers/gen/predict_gen.py +9 -0
- dipo/rst/parsers/gen/serializations/__init__.py +10 -0
- dipo/rst/parsers/gen/serializations/base.py +231 -0
- dipo/rst/parsers/gen/serializations/sexp.py +487 -0
- dipo/rst/parsers/gen/serializations/sr.py +351 -0
- dipo/rst/parsers/gen/train_gen.py +484 -0
- dipo/rst/parsers/hfhub/__init__.py +22 -0
- dipo/rst/parsers/hfhub/datasets.py +188 -0
- dipo/rst/parsers/hfhub/hub.py +502 -0
- dipo/rst/parsers/hfhub/push.py +49 -0
- dipo/rst/parsers/icl/__init__.py +14 -0
- dipo/rst/parsers/icl/_cli_common.py +48 -0
- dipo/rst/parsers/icl/configuration_icl.py +274 -0
- dipo/rst/parsers/icl/eval_icl.py +239 -0
- dipo/rst/parsers/icl/eval_metrics.py +95 -0
- dipo/rst/parsers/icl/modeling_icl.py +293 -0
- dipo/rst/parsers/icl/predict_icl.py +84 -0
- dipo/rst/parsers/icl/provider.py +445 -0
- dipo/rst/parsers/icl/serialize.py +748 -0
- dipo/rst/parsers/sr_biaffine/__init__.py +2 -0
- dipo/rst/parsers/sr_biaffine/configuration_sr_biaffine.py +82 -0
- dipo/rst/parsers/sr_biaffine/modeling_sr_biaffine.py +240 -0
- dipo/rst/parsers/sr_biaffine/predict_sr_biaffine.py +9 -0
- dipo/rst/parsers/sr_biaffine/train_sr_biaffine.py +369 -0
- dipo/rst/parsers/topdown_biaffine/__init__.py +2 -0
- dipo/rst/parsers/topdown_biaffine/configuration_topdown_biaffine.py +76 -0
- dipo/rst/parsers/topdown_biaffine/modeling_topdown_biaffine.py +216 -0
- dipo/rst/parsers/topdown_biaffine/predict_topdown_biaffine.py +9 -0
- dipo/rst/parsers/topdown_biaffine/train_topdown_biaffine.py +369 -0
- dipo/runs.py +745 -0
- dipo-0.2.0.dist-info/METADATA +278 -0
- dipo-0.2.0.dist-info/RECORD +77 -0
- dipo-0.2.0.dist-info/WHEEL +5 -0
- dipo-0.2.0.dist-info/entry_points.txt +3 -0
- dipo-0.2.0.dist-info/licenses/LICENSE +21 -0
- dipo-0.2.0.dist-info/top_level.txt +1 -0
dipo/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""This module declares the project's CLI surface that lives above any one
|
|
2
|
+
framework:
|
|
3
|
+
|
|
4
|
+
- `FRAMEWORKS`: dotted paths of framework modules (e.g. `dipo.rst`).
|
|
5
|
+
Each framework module exposes `PARSERS`, `PARSER_SCOPED_COMMANDS`,
|
|
6
|
+
and `GLOBAL_COMMANDS`. The dispatcher (`dipo/__main__.py`) imports
|
|
7
|
+
each and merges the three.
|
|
8
|
+
- `GLOBAL_COMMANDS`: `{cmd: module_path}` for project-level commands
|
|
9
|
+
that aren't owned by any single framework (e.g. `runs`, which walks
|
|
10
|
+
every framework's parser registry to tag rows by parser kind).
|
|
11
|
+
|
|
12
|
+
To add a sibling framework, append its dotted path to `FRAMEWORKS` and
|
|
13
|
+
give its `__init__.py` the three required attributes.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
__version__ = "0.2.0"
|
|
17
|
+
|
|
18
|
+
FRAMEWORKS: list[str] = ["dipo.rst"]
|
|
19
|
+
|
|
20
|
+
GLOBAL_COMMANDS: dict[str, str] = {
|
|
21
|
+
"runs": "dipo.runs",
|
|
22
|
+
}
|
dipo/__main__.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""dipo CLI dispatcher.
|
|
2
|
+
|
|
3
|
+
`dipo <parser> <cmd>` or `dipo <cmd>` for globals. Routes by merging the
|
|
4
|
+
registries declared by each framework in `dipo.FRAMEWORKS`. See
|
|
5
|
+
`dipo/__init__.py` for the framework contract.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import importlib
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
import dipo
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _merge_frameworks() -> tuple[dict, dict, dict]:
|
|
15
|
+
"""Merge each framework's three registry dicts atop project-level
|
|
16
|
+
`dipo.GLOBAL_COMMANDS`. Aborts on a name collision."""
|
|
17
|
+
parsers: dict = {}
|
|
18
|
+
parser_scoped: dict = {}
|
|
19
|
+
global_cmds: dict = dict(dipo.GLOBAL_COMMANDS)
|
|
20
|
+
for fw_path in dipo.FRAMEWORKS:
|
|
21
|
+
fw = importlib.import_module(fw_path)
|
|
22
|
+
_merge_no_collide(parsers, fw.PARSERS, fw_path, "parser name")
|
|
23
|
+
_merge_no_collide(parser_scoped, fw.PARSER_SCOPED_COMMANDS, fw_path, "parser-scoped command")
|
|
24
|
+
_merge_no_collide(global_cmds, fw.GLOBAL_COMMANDS, fw_path, "global command")
|
|
25
|
+
return parsers, parser_scoped, global_cmds
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _merge_no_collide(dst: dict, src: dict, fw_path: str, kind: str) -> None:
|
|
29
|
+
for k, v in src.items():
|
|
30
|
+
if k in dst and dst[k] is not v:
|
|
31
|
+
sys.stderr.write(
|
|
32
|
+
f"dipo: {kind} {k!r} declared by both an earlier framework and {fw_path!r}. Rename one of them.\n"
|
|
33
|
+
)
|
|
34
|
+
sys.exit(2)
|
|
35
|
+
dst[k] = v
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
PARSERS, PARSER_SCOPED_COMMANDS, GLOBAL_COMMANDS = _merge_frameworks()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def main():
|
|
42
|
+
if len(sys.argv) > 1 and sys.argv[1] in ("-h", "--help"):
|
|
43
|
+
print(__doc__.strip())
|
|
44
|
+
print(f"\nKnown parsers: {', '.join(sorted(PARSERS))}")
|
|
45
|
+
print(f"Global commands: {', '.join(sorted(GLOBAL_COMMANDS))}")
|
|
46
|
+
sys.exit(0)
|
|
47
|
+
|
|
48
|
+
if len(sys.argv) < 2:
|
|
49
|
+
sys.stderr.write(__doc__.strip() + "\n\n")
|
|
50
|
+
sys.stderr.write(f"Known parsers: {', '.join(sorted(PARSERS))}\n")
|
|
51
|
+
sys.stderr.write(f"Global commands: {', '.join(sorted(GLOBAL_COMMANDS))}\n")
|
|
52
|
+
sys.exit(2)
|
|
53
|
+
|
|
54
|
+
head = sys.argv[1]
|
|
55
|
+
|
|
56
|
+
if head in GLOBAL_COMMANDS:
|
|
57
|
+
module = importlib.import_module(GLOBAL_COMMANDS[head])
|
|
58
|
+
sys.argv = [GLOBAL_COMMANDS[head]] + sys.argv[2:]
|
|
59
|
+
module.main()
|
|
60
|
+
return
|
|
61
|
+
|
|
62
|
+
if len(sys.argv) < 3:
|
|
63
|
+
sys.stderr.write(__doc__.strip() + "\n\n")
|
|
64
|
+
sys.stderr.write(f"Known parsers: {', '.join(sorted(PARSERS))}\n")
|
|
65
|
+
sys.exit(2)
|
|
66
|
+
|
|
67
|
+
parser_name = head
|
|
68
|
+
command = sys.argv[2]
|
|
69
|
+
|
|
70
|
+
if parser_name not in PARSERS:
|
|
71
|
+
sys.stderr.write(f"Unknown parser: {parser_name!r}\n")
|
|
72
|
+
sys.stderr.write(f"Known parsers: {', '.join(sorted(PARSERS))}\n")
|
|
73
|
+
sys.stderr.write(f"Global commands: {', '.join(sorted(GLOBAL_COMMANDS))}\n")
|
|
74
|
+
sys.exit(2)
|
|
75
|
+
|
|
76
|
+
if command in PARSER_SCOPED_COMMANDS:
|
|
77
|
+
shared_path = PARSER_SCOPED_COMMANDS[command]
|
|
78
|
+
module = importlib.import_module(shared_path)
|
|
79
|
+
sys.argv = [f"dipo {parser_name} {command}"] + sys.argv[3:]
|
|
80
|
+
module.main(parser_kind=parser_name)
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
module_path = f"{PARSERS[parser_name].package}.{command}_{parser_name}"
|
|
84
|
+
try:
|
|
85
|
+
module = importlib.import_module(module_path)
|
|
86
|
+
except ImportError as e:
|
|
87
|
+
sys.stderr.write(f"No such command {command!r} for parser {parser_name!r}\n")
|
|
88
|
+
sys.stderr.write(f" (tried to import {module_path}: {e})\n")
|
|
89
|
+
sys.exit(2)
|
|
90
|
+
|
|
91
|
+
sys.argv = [module_path] + sys.argv[3:]
|
|
92
|
+
module.main()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def main_iudex():
|
|
96
|
+
"""Entry point of the deprecated `iudex` command, the old name of this project."""
|
|
97
|
+
sys.stderr.write("iudex: this command has been renamed to `dipo` and takes the same arguments. "
|
|
98
|
+
"`iudex` will be removed in a future release.\n")
|
|
99
|
+
main()
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
if __name__ == "__main__":
|
|
103
|
+
main()
|
dipo/common/__init__.py
ADDED
|
File without changes
|
dipo/common/log.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Rich-based logging and console helpers."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.logging import RichHandler
|
|
8
|
+
from rich.theme import Theme
|
|
9
|
+
|
|
10
|
+
theme = Theme(
|
|
11
|
+
{
|
|
12
|
+
"info": "cyan",
|
|
13
|
+
"warning": "yellow",
|
|
14
|
+
"error": "bold red",
|
|
15
|
+
"metric": "bold green",
|
|
16
|
+
"metric.name": "dim",
|
|
17
|
+
"epoch": "bold magenta",
|
|
18
|
+
"step": "dim cyan",
|
|
19
|
+
"lr": "dim yellow",
|
|
20
|
+
"loss": "bold orange1",
|
|
21
|
+
"gpu": "bold green",
|
|
22
|
+
"path": "underline blue",
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
console = Console(theme=theme)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def success(msg: str) -> None:
|
|
30
|
+
console.print(f"[bold green]{msg}[/bold green]")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def warn(msg: str) -> None:
|
|
34
|
+
console.print(f"[bold yellow]{msg}[/bold yellow]")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def dim(msg: str) -> None:
|
|
38
|
+
console.print(f"[dim]{msg}[/dim]")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def rule(title: str) -> None:
|
|
42
|
+
console.rule(f"[bold magenta]{title}[/bold magenta]")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def wrote(path: str) -> None:
|
|
46
|
+
"""Announce a file the program just wrote, with its absolute path."""
|
|
47
|
+
console.print(f"[dim]Wrote[/dim] [path]{os.path.abspath(path)}[/path]")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def setup_logging(level: int = logging.INFO) -> None:
|
|
51
|
+
logging.basicConfig(
|
|
52
|
+
level=level,
|
|
53
|
+
format="%(message)s",
|
|
54
|
+
datefmt="[%X]",
|
|
55
|
+
handlers=[
|
|
56
|
+
RichHandler(
|
|
57
|
+
console=console,
|
|
58
|
+
rich_tracebacks=True,
|
|
59
|
+
tracebacks_show_locals=True,
|
|
60
|
+
show_path=False,
|
|
61
|
+
markup=True,
|
|
62
|
+
)
|
|
63
|
+
],
|
|
64
|
+
force=True,
|
|
65
|
+
)
|