type_utils.py
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from typing import Any, Sequence, TypedDict, NotRequired
type TokenList = list[str]
type IntLabelList = list[int | None]
type StrLabelList = list[str | None]
type SimpleLabelList = IntLabelList | StrLabelList
type NestedIntLabelList = list[IntLabelList]
type NestedStrLabelList = list[StrLabelList]
type NestedLabelList = NestedIntLabelList | NestedStrLabelList
type AnyLabelList = SimpleLabelList | NestedLabelList
class LabelDict(TypedDict):
segs: NotRequired[StrLabelList]
nps: NotRequired[list[bool]]
lemmas: NotRequired[StrLabelList]
lemma_cases: NotRequired[StrLabelList]
lemma_rules: NotRequired[StrLabelList]
tags: NotRequired[StrLabelList]
heads: NotRequired[IntLabelList]
adjacency_matrix: NotRequired[NestedIntLabelList]
deprels: NotRequired[StrLabelList]
graph_heads: NotRequired[NestedIntLabelList]
graph_adjacency_matrix: NotRequired[NestedIntLabelList]
graph_deprels: NotRequired[NestedStrLabelList]
spines: NotRequired[StrLabelList]
anchors: NotRequired[StrLabelList]
anchor_hs: NotRequired[StrLabelList]
ne_iobs: NotRequired[StrLabelList]
class DatasetInstance(TypedDict):
tokens: NotRequired[TokenList]
segs: NotRequired[SimpleLabelList] # str/int before/after column casting
lemmas: NotRequired[StrLabelList]
lemma_cases: NotRequired[SimpleLabelList]
lemma_rules: NotRequired[SimpleLabelList]
tags: NotRequired[IntLabelList]
heads: NotRequired[IntLabelList]
adjacency_matrix: NotRequired[NestedIntLabelList]
deprels: NotRequired[IntLabelList]
graph_heads: NotRequired[NestedIntLabelList]
graph_adjacency_matrix: NotRequired[NestedIntLabelList]
graph_deprels: NotRequired[NestedIntLabelList]
nonterminals: NotRequired[Any]
spines: NotRequired[SimpleLabelList]
anchors: NotRequired[SimpleLabelList]
anchor_hs: NotRequired[SimpleLabelList]
ne_iobs: NotRequired[IntLabelList]
type EvalResults = list[tuple[str, dict[str, Any]]]
type TreeDict = dict[str, Any]
#type HydraAnalysis = dict[str, Any]
class HydraAnalysis(TypedDict):
sentence: str
tokens: TokenList
metadata: dict[str, Any]
logits: NotRequired[Any]
labels: NotRequired[LabelDict]
tree: NotRequired[Any]
json: NotRequired[dict[str, Any] | None]
conllu: NotRequired[str]