Source code for hydra.utils.types

"""Typing utilities."""

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

[docs] class LabelDict(TypedDict): """Model-predicted labels before or after preprocessing.""" 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]
[docs] class DatasetInstance(TypedDict): """A dataset instance as used in Hydra training and evaluation.""" 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]
[docs] class HydraAnalysis(TypedDict): """An analysis of a single sentence as returned by :meth:`~hydra.parser.Hydra.parse`.""" 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]