gliformer 0.1.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.
- gliformer/__init__.py +96 -0
- gliformer/backbones/__init__.py +161 -0
- gliformer/backbones/deberta_2d.py +898 -0
- gliformer/backbones/flash_deberta.py +231 -0
- gliformer/backbones/qwen3.py +483 -0
- gliformer/backbones/qwen3_5.py +366 -0
- gliformer/config.py +3141 -0
- gliformer/encoders/__init__.py +56 -0
- gliformer/encoders/audio.py +424 -0
- gliformer/encoders/base.py +634 -0
- gliformer/encoders/media.py +311 -0
- gliformer/encoders/omni.py +879 -0
- gliformer/encoders/text.py +122 -0
- gliformer/encoders/vision.py +425 -0
- gliformer/gliformer.py +2139 -0
- gliformer/layers/__init__.py +123 -0
- gliformer/layers/anchor_layer.py +970 -0
- gliformer/layers/anchor_modeling.py +341 -0
- gliformer/layers/anchor_normalization.py +335 -0
- gliformer/layers/anchor_relations.py +258 -0
- gliformer/layers/anchored_scorer.py +78 -0
- gliformer/layers/attention.py +136 -0
- gliformer/layers/attention_bias.py +601 -0
- gliformer/layers/groups.py +1222 -0
- gliformer/layers/mlp.py +55 -0
- gliformer/layers/pair_rep.py +136 -0
- gliformer/layers/pooling.py +77 -0
- gliformer/layers/position.py +1383 -0
- gliformer/layers/positional_layer.py +66 -0
- gliformer/layers/rnn.py +29 -0
- gliformer/layers/rotary.py +59 -0
- gliformer/layers/structuring_relations.py +404 -0
- gliformer/model.py +3414 -0
- gliformer/outputs.py +135 -0
- gliformer/processing/__init__.py +5 -0
- gliformer/processing/_structuring_alignment.py +1462 -0
- gliformer/processing/_structuring_hierarchy.py +892 -0
- gliformer/processing/collator.py +241 -0
- gliformer/processing/decoder.py +133 -0
- gliformer/processing/formatting.py +574 -0
- gliformer/processing/label_augmentation.py +496 -0
- gliformer/processing/mappings.py +285 -0
- gliformer/processing/pdf.py +589 -0
- gliformer/processing/processor.py +2258 -0
- gliformer/processing/schema.py +1115 -0
- gliformer/processing/structuring_decoder.py +792 -0
- gliformer/processing/structuring_processor.py +992 -0
- gliformer/processing/structuring_types.py +647 -0
- gliformer/tasks/__init__.py +711 -0
- gliformer/tasks/anchored_extraction.py +176 -0
- gliformer/tasks/audio/__init__.py +11 -0
- gliformer/tasks/audio/decoder.py +61 -0
- gliformer/tasks/audio/model.py +332 -0
- gliformer/tasks/audio/processor.py +161 -0
- gliformer/tasks/box_ops.py +141 -0
- gliformer/tasks/classification/__init__.py +10 -0
- gliformer/tasks/classification/decoder.py +77 -0
- gliformer/tasks/classification/model.py +123 -0
- gliformer/tasks/classification/processor.py +164 -0
- gliformer/tasks/classification/scorer.py +134 -0
- gliformer/tasks/count/__init__.py +2 -0
- gliformer/tasks/count/decoder.py +33 -0
- gliformer/tasks/count/model.py +69 -0
- gliformer/tasks/count/processor.py +56 -0
- gliformer/tasks/embedding/__init__.py +2 -0
- gliformer/tasks/embedding/decoder.py +23 -0
- gliformer/tasks/embedding/model.py +237 -0
- gliformer/tasks/embedding/processor.py +116 -0
- gliformer/tasks/joint_relex/__init__.py +2 -0
- gliformer/tasks/joint_relex/decoder.py +259 -0
- gliformer/tasks/joint_relex/model.py +1398 -0
- gliformer/tasks/joint_relex/processor.py +349 -0
- gliformer/tasks/losses.py +193 -0
- gliformer/tasks/matcher.py +291 -0
- gliformer/tasks/media.py +611 -0
- gliformer/tasks/media_processor.py +308 -0
- gliformer/tasks/ner/__init__.py +2 -0
- gliformer/tasks/ner/decoder.py +144 -0
- gliformer/tasks/ner/model.py +180 -0
- gliformer/tasks/ner/processor.py +590 -0
- gliformer/tasks/open_relex/__init__.py +11 -0
- gliformer/tasks/open_relex/decoder.py +444 -0
- gliformer/tasks/open_relex/model.py +734 -0
- gliformer/tasks/open_relex/processor.py +637 -0
- gliformer/tasks/span_decoder.py +324 -0
- gliformer/tasks/span_processor.py +378 -0
- gliformer/tasks/structuring/__init__.py +11 -0
- gliformer/tasks/structuring/decoder.py +189 -0
- gliformer/tasks/structuring/model.py +1073 -0
- gliformer/tasks/structuring/processor.py +13 -0
- gliformer/tasks/vision/__init__.py +13 -0
- gliformer/tasks/vision/decoder.py +84 -0
- gliformer/tasks/vision/model.py +1081 -0
- gliformer/tasks/vision/processor.py +219 -0
- gliformer/training.py +513 -0
- gliformer/utils.py +18 -0
- gliformer-0.1.0.dist-info/METADATA +408 -0
- gliformer-0.1.0.dist-info/RECORD +108 -0
- gliformer-0.1.0.dist-info/WHEEL +5 -0
- gliformer-0.1.0.dist-info/top_level.txt +2 -0
- gliformer_eval/__init__.py +1 -0
- gliformer_eval/eval_box_accuracy.py +105 -0
- gliformer_eval/eval_classification.py +483 -0
- gliformer_eval/eval_ner.py +414 -0
- gliformer_eval/eval_qa.py +684 -0
- gliformer_eval/eval_relex.py +1105 -0
- gliformer_eval/eval_structuring.py +1310 -0
- gliformer_eval/eval_sts.py +402 -0
gliformer/__init__.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
try:
|
|
2
|
+
import wcwidth
|
|
3
|
+
|
|
4
|
+
if not hasattr(wcwidth, "wcswidth"):
|
|
5
|
+
wcwidth.wcswidth = lambda text: sum( # type: ignore[attr-defined]
|
|
6
|
+
max(getattr(wcwidth, "wcwidth", lambda _: 1)(char), 0)
|
|
7
|
+
for char in str(text)
|
|
8
|
+
)
|
|
9
|
+
if not hasattr(wcwidth, "wcwidth"):
|
|
10
|
+
wcwidth.wcwidth = lambda char: 1 # type: ignore[attr-defined]
|
|
11
|
+
except Exception:
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
from .config import (
|
|
15
|
+
GLiFormerConfig,
|
|
16
|
+
GLiFormerAudioConfig,
|
|
17
|
+
TaskHeadConfig,
|
|
18
|
+
AnchorHeadConfig,
|
|
19
|
+
BaseHeadConfig,
|
|
20
|
+
NERHeadConfig,
|
|
21
|
+
ClassificationHeadConfig,
|
|
22
|
+
MediaClassificationHeadConfig,
|
|
23
|
+
ImageClassificationHeadConfig,
|
|
24
|
+
AudioClassificationHeadConfig,
|
|
25
|
+
SetPredictionHeadConfig,
|
|
26
|
+
GLiFormerLayoutConfig,
|
|
27
|
+
GLiFormerOmniConfig,
|
|
28
|
+
GLiFormerTextConfig,
|
|
29
|
+
GLiFormerVisionConfig,
|
|
30
|
+
ObjectDetectionHeadConfig,
|
|
31
|
+
SegmentationHeadConfig,
|
|
32
|
+
AudioSegmentationHeadConfig,
|
|
33
|
+
JointRelexHeadConfig,
|
|
34
|
+
OpenRelexHeadConfig,
|
|
35
|
+
StructuringModeConfig,
|
|
36
|
+
StructuringHeadConfig,
|
|
37
|
+
CountHeadConfig,
|
|
38
|
+
EmbeddingHeadConfig,
|
|
39
|
+
)
|
|
40
|
+
from .model import (
|
|
41
|
+
BaseGLiFormerModel,
|
|
42
|
+
GLiFormerAudioModel,
|
|
43
|
+
GLiFormerAudioOutput,
|
|
44
|
+
GLiFormerLayoutModel,
|
|
45
|
+
GLiFormerLayoutOutput,
|
|
46
|
+
GLiFormerOmniModel,
|
|
47
|
+
GLiFormerOmniOutput,
|
|
48
|
+
GLiFormerModel,
|
|
49
|
+
GLiFormerOutput,
|
|
50
|
+
GLiFormerTextModel,
|
|
51
|
+
GLiFormerTextOutput,
|
|
52
|
+
GLiFormerVisionModel,
|
|
53
|
+
GLiFormerVisionOutput,
|
|
54
|
+
resolve_gliformer_model_class,
|
|
55
|
+
)
|
|
56
|
+
from .processing.processor import GLiFormerProcessor
|
|
57
|
+
from .processing.pdf import GLiFormerPDFProcessor, PDFTableProcessor
|
|
58
|
+
from .processing.decoder import GLiFormerDecoder
|
|
59
|
+
from .processing.collator import (
|
|
60
|
+
BaseGLiFormerDataCollator,
|
|
61
|
+
GLiFormerAudioDataCollator,
|
|
62
|
+
GLiFormerDataCollator,
|
|
63
|
+
GLiFormerLayoutDataCollator,
|
|
64
|
+
GLiFormerOmniDataCollator,
|
|
65
|
+
GLiFormerTextDataCollator,
|
|
66
|
+
GLiFormerVisionDataCollator,
|
|
67
|
+
resolve_gliformer_collator_class,
|
|
68
|
+
)
|
|
69
|
+
from .processing.schema import GLiFormerSchema
|
|
70
|
+
from .processing.formatting import StructuringOutputFormatter, FieldType
|
|
71
|
+
from .processing.mappings import (
|
|
72
|
+
BaseClassMapping,
|
|
73
|
+
CatClassMapping,
|
|
74
|
+
ExtractionItemMapping,
|
|
75
|
+
ExtractionClassMapping,
|
|
76
|
+
StructuringItemMapping,
|
|
77
|
+
StructuringClassMapping,
|
|
78
|
+
OpenRelexItemMapping,
|
|
79
|
+
OpenRelexClassMapping,
|
|
80
|
+
VisionItemMapping,
|
|
81
|
+
VisionClassMapping,
|
|
82
|
+
BatchClassesMapping,
|
|
83
|
+
)
|
|
84
|
+
from .gliformer import (
|
|
85
|
+
BaseGLiFormer,
|
|
86
|
+
GLiFormer,
|
|
87
|
+
GLiFormerAudio,
|
|
88
|
+
GLiFormerLayout,
|
|
89
|
+
GLiFormerOmni,
|
|
90
|
+
GLiFormerText,
|
|
91
|
+
GLiFormerVision,
|
|
92
|
+
)
|
|
93
|
+
from .training import GLiFormerTrainer
|
|
94
|
+
|
|
95
|
+
# Backward compat alias
|
|
96
|
+
RelationsHeadConfig = JointRelexHeadConfig
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
|
|
4
|
+
from transformers import AutoConfig, AutoModel
|
|
5
|
+
|
|
6
|
+
from .deberta_2d import (
|
|
7
|
+
Deberta2DConfig,
|
|
8
|
+
Deberta2DModel,
|
|
9
|
+
LayoutDebertaConfig,
|
|
10
|
+
LayoutDebertaModel,
|
|
11
|
+
)
|
|
12
|
+
from .flash_deberta import (
|
|
13
|
+
ATTN_KERNELS,
|
|
14
|
+
flash_kernels_available,
|
|
15
|
+
is_flash_kernel,
|
|
16
|
+
normalize_attn_kernel,
|
|
17
|
+
)
|
|
18
|
+
from .qwen3 import GLiFormerQwen3Model, Qwen3BidirectionalModel
|
|
19
|
+
from .qwen3_5 import (
|
|
20
|
+
QWEN3_5_AVAILABLE,
|
|
21
|
+
GLiFormerQwen3_5Model,
|
|
22
|
+
GLiFormerQwen3_5TextModel,
|
|
23
|
+
Qwen3_5BidirectionalModel,
|
|
24
|
+
Qwen3_5Config,
|
|
25
|
+
Qwen3_5TextConfig,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
AutoConfig.register(LayoutDebertaConfig.model_type, LayoutDebertaConfig)
|
|
30
|
+
AutoModel.register(LayoutDebertaConfig, LayoutDebertaModel)
|
|
31
|
+
except ValueError:
|
|
32
|
+
# Transformers raises when a notebook/process imports this module twice.
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
AutoModel.register(GLiFormerQwen3Model.config_class, GLiFormerQwen3Model, exist_ok=True)
|
|
37
|
+
except ValueError:
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
if QWEN3_5_AVAILABLE:
|
|
41
|
+
try:
|
|
42
|
+
AutoModel.register(Qwen3_5Config, GLiFormerQwen3_5Model, exist_ok=True)
|
|
43
|
+
AutoModel.register(Qwen3_5TextConfig, GLiFormerQwen3_5TextModel, exist_ok=True)
|
|
44
|
+
except ValueError:
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass(frozen=True)
|
|
49
|
+
class BackboneSpec:
|
|
50
|
+
name: str
|
|
51
|
+
model_class: type
|
|
52
|
+
config_class: type | None = None
|
|
53
|
+
aliases: tuple[str, ...] = ()
|
|
54
|
+
model_class_names: tuple[str, ...] = ()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
BACKBONE_REGISTRY: dict[str, BackboneSpec] = {}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def register_backbone(
|
|
61
|
+
name: str,
|
|
62
|
+
model_class: type,
|
|
63
|
+
config_class: type | None = None,
|
|
64
|
+
aliases: Iterable[str] = (),
|
|
65
|
+
model_class_names: Iterable[str] = (),
|
|
66
|
+
) -> BackboneSpec:
|
|
67
|
+
normalized = normalize_backbone_type(name)
|
|
68
|
+
alias_tuple = tuple(normalize_backbone_type(alias) for alias in aliases)
|
|
69
|
+
spec = BackboneSpec(
|
|
70
|
+
name=normalized,
|
|
71
|
+
model_class=model_class,
|
|
72
|
+
config_class=config_class,
|
|
73
|
+
aliases=alias_tuple,
|
|
74
|
+
model_class_names=tuple(model_class_names),
|
|
75
|
+
)
|
|
76
|
+
keys = (normalized, *alias_tuple)
|
|
77
|
+
seen = set()
|
|
78
|
+
for key in keys:
|
|
79
|
+
if key in seen or key in BACKBONE_REGISTRY:
|
|
80
|
+
raise ValueError(f"Backbone {key!r} is already registered")
|
|
81
|
+
seen.add(key)
|
|
82
|
+
for key in keys:
|
|
83
|
+
BACKBONE_REGISTRY[key] = spec
|
|
84
|
+
return spec
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def normalize_backbone_type(backbone_type: str | None) -> str:
|
|
88
|
+
return (backbone_type or "auto").replace("-", "_").lower()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def get_backbone(backbone_type: str | None) -> BackboneSpec | None:
|
|
92
|
+
normalized = normalize_backbone_type(backbone_type)
|
|
93
|
+
if normalized == "auto":
|
|
94
|
+
return None
|
|
95
|
+
try:
|
|
96
|
+
return BACKBONE_REGISTRY[normalized]
|
|
97
|
+
except KeyError as exc:
|
|
98
|
+
raise ValueError(
|
|
99
|
+
f"Unknown GLiFormer backbone_type {backbone_type!r}. "
|
|
100
|
+
f"Available backbones: {', '.join(available_backbones())}"
|
|
101
|
+
) from exc
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def available_backbones(include_auto: bool = False) -> tuple[str, ...]:
|
|
105
|
+
names = sorted({spec.name for spec in BACKBONE_REGISTRY.values()})
|
|
106
|
+
if include_auto:
|
|
107
|
+
return ("auto", *names)
|
|
108
|
+
return tuple(names)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
register_backbone(
|
|
112
|
+
"deberta_2d",
|
|
113
|
+
LayoutDebertaModel,
|
|
114
|
+
LayoutDebertaConfig,
|
|
115
|
+
aliases=("layout_deberta",),
|
|
116
|
+
model_class_names=("LayoutDebertaModel", "Deberta2DModel"),
|
|
117
|
+
)
|
|
118
|
+
register_backbone(
|
|
119
|
+
"qwen3",
|
|
120
|
+
GLiFormerQwen3Model,
|
|
121
|
+
GLiFormerQwen3Model.config_class,
|
|
122
|
+
aliases=("qwen3_bidirectional",),
|
|
123
|
+
model_class_names=("GLiFormerQwen3Model", "Qwen3BidirectionalModel"),
|
|
124
|
+
)
|
|
125
|
+
if QWEN3_5_AVAILABLE:
|
|
126
|
+
register_backbone(
|
|
127
|
+
"qwen3_5",
|
|
128
|
+
GLiFormerQwen3_5Model,
|
|
129
|
+
Qwen3_5Config,
|
|
130
|
+
aliases=("qwen3_5_bidirectional",),
|
|
131
|
+
model_class_names=("GLiFormerQwen3_5Model", "Qwen3_5BidirectionalModel"),
|
|
132
|
+
)
|
|
133
|
+
register_backbone(
|
|
134
|
+
"qwen3_5_text",
|
|
135
|
+
GLiFormerQwen3_5TextModel,
|
|
136
|
+
Qwen3_5TextConfig,
|
|
137
|
+
model_class_names=("GLiFormerQwen3_5TextModel",),
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
__all__ = [
|
|
141
|
+
"ATTN_KERNELS",
|
|
142
|
+
"BACKBONE_REGISTRY",
|
|
143
|
+
"BackboneSpec",
|
|
144
|
+
"available_backbones",
|
|
145
|
+
"Deberta2DConfig",
|
|
146
|
+
"Deberta2DModel",
|
|
147
|
+
"flash_kernels_available",
|
|
148
|
+
"get_backbone",
|
|
149
|
+
"GLiFormerQwen3_5Model",
|
|
150
|
+
"GLiFormerQwen3_5TextModel",
|
|
151
|
+
"GLiFormerQwen3Model",
|
|
152
|
+
"is_flash_kernel",
|
|
153
|
+
"LayoutDebertaConfig",
|
|
154
|
+
"LayoutDebertaModel",
|
|
155
|
+
"normalize_attn_kernel",
|
|
156
|
+
"normalize_backbone_type",
|
|
157
|
+
"QWEN3_5_AVAILABLE",
|
|
158
|
+
"Qwen3_5BidirectionalModel",
|
|
159
|
+
"Qwen3BidirectionalModel",
|
|
160
|
+
"register_backbone",
|
|
161
|
+
]
|