Layoutprompter
LayoutPrompter Pydantic AI agent package.
ConditionType ¶
Bases: StrEnum
Canonical condition names used by layout generation interfaces.
Source code in lib/laygen/src/laygen/common/conditions.py
9 10 11 12 13 14 15 16 17 18 19 20 21 | |
LayoutPrompter ¶
Bases: BaseLayoutAgent[LayoutPrompterOutput]
High-level LayoutPrompter Pydantic AI agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutPrompterConfig
|
Runtime prompt, retrieval, parser, and model settings. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the config contains an unsupported mode. |
Examples:
>>> import numpy as np
>>> from pydantic_ai.models.test import TestModel
>>> model = TestModel(custom_output_args={"elements": []})
>>> agent = LayoutPrompter(LayoutPrompterConfig(model=model, num_prompt=1))
>>> isinstance(agent, LayoutPrompter)
True
Source code in models/layoutprompter/src/layoutprompter/agent.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 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 | |
__init__ ¶
__init__(config: LayoutPrompterConfig) -> None
Create a LayoutPrompter runner from runtime config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutPrompterConfig
|
Agent configuration. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a config mode cannot be normalized. |
Source code in models/layoutprompter/src/layoutprompter/agent.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
build_prompt ¶
build_prompt(
train_data: Sequence[LayoutRecord],
test_data: LayoutRecord,
) -> str
Select exemplars and build the final LayoutPrompter prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_data
|
Sequence[LayoutRecord]
|
Candidate exemplar records with |
required |
test_data
|
LayoutRecord
|
Test record containing task-specific constraints. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The final few-shot prompt sent to the configured model. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If required record fields are missing. |
Examples:
>>> import numpy as np
>>> from pydantic_ai.models.test import TestModel
>>> record = {
... "labels": np.asarray([0]),
... "bboxes": np.asarray([[1, 2, 3, 4]]),
... "discrete_gold_bboxes": np.asarray([[1, 2, 3, 4]]),
... }
>>> agent = LayoutPrompter(
... LayoutPrompterConfig(model=TestModel(), shuffle=False, num_prompt=1)
... )
>>> "Element Type Constraint" in agent.build_prompt([record], record)
True
Source code in models/layoutprompter/src/layoutprompter/agent.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
run_sync ¶
run_sync(
train_data: Sequence[LayoutRecord],
test_data: LayoutRecord,
) -> LayoutGenerationOutput
Run the Pydantic AI model and return the common layout schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_data
|
Sequence[LayoutRecord]
|
Candidate exemplar records. |
required |
test_data
|
LayoutRecord
|
Test record containing task-specific constraints. |
required |
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput
|
A |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the model output cannot be parsed. |
Examples:
>>> import numpy as np
>>> from pydantic_ai.models.test import TestModel
>>> model = TestModel(custom_output_args={"elements": []})
>>> record = {
... "labels": np.asarray([0]),
... "bboxes": np.asarray([[1, 2, 3, 4]]),
... "discrete_gold_bboxes": np.asarray([[1, 2, 3, 4]]),
... }
>>> agent = LayoutPrompter(LayoutPrompterConfig(model=model, num_prompt=1))
>>> agent.run_sync([record], record).labels.shape[0]
1
Source code in models/layoutprompter/src/layoutprompter/agent.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
__call__ ¶
__call__(
*,
train_data: Sequence[LayoutRecord],
test_data: LayoutRecord,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType | str | None = None,
labels: Int[ndarray, "batch elements"]
| LayoutRecordPayload
| None = None,
bbox: Float[ndarray, "batch elements 4"]
| LayoutRecordPayload
| None = None,
mask: Bool[ndarray, "batch elements"]
| LayoutRecordPayload
| None = None,
num_elements: int
| list[int]
| Int[ndarray, "batch"]
| LayoutRecordPayload
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
num_inference_steps: int | None = None,
output_type: OutputType | str = OutputType.DATACLASS,
return_intermediates: bool = False,
) -> LayoutGenerationOutput | LayoutOutputDict
Expose the shared generation signature for LayoutPrompter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_data
|
Sequence[LayoutRecord]
|
Candidate exemplar records. |
required |
test_data
|
LayoutRecord
|
Test record containing task-specific constraints. |
required |
batch_size
|
int
|
Accepted for shared interface compatibility. |
1
|
seed
|
int | None
|
Accepted for shared interface compatibility. |
None
|
generator
|
Generator | None
|
Accepted for shared interface compatibility. |
None
|
condition_type
|
ConditionType | str | None
|
Accepted for shared interface compatibility. |
None
|
labels
|
Int[ndarray, 'batch elements'] | LayoutRecordPayload | None
|
Accepted for shared interface compatibility. |
None
|
bbox
|
Float[ndarray, 'batch elements 4'] | LayoutRecordPayload | None
|
Accepted for shared interface compatibility. |
None
|
mask
|
Bool[ndarray, 'batch elements'] | LayoutRecordPayload | None
|
Accepted for shared interface compatibility. |
None
|
num_elements
|
int | list[int] | Int[ndarray, 'batch'] | LayoutRecordPayload | None
|
Accepted for shared interface compatibility. |
None
|
box_format
|
BoxFormat | str
|
Public input box format name; validated at the boundary. |
xywh
|
normalized
|
bool
|
Accepted for shared interface compatibility. |
True
|
canvas_size
|
tuple[int, int] | None
|
Accepted for shared interface compatibility. |
None
|
num_inference_steps
|
int | None
|
Accepted for shared interface compatibility. |
None
|
output_type
|
OutputType | str
|
|
DATACLASS
|
return_intermediates
|
bool
|
Accepted for shared interface compatibility. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | LayoutOutputDict
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import numpy as np
>>> from pydantic_ai.models.test import TestModel
>>> model = TestModel(custom_output_args={"elements": []})
>>> record = {
... "labels": np.asarray([0]),
... "bboxes": np.asarray([[1, 2, 3, 4]]),
... "discrete_gold_bboxes": np.asarray([[1, 2, 3, 4]]),
... }
>>> agent = LayoutPrompter(LayoutPrompterConfig(model=model, num_prompt=1))
>>> isinstance(agent(train_data=[record], test_data=record), LayoutGenerationOutput)
True
Source code in models/layoutprompter/src/layoutprompter/agent.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
) -> None
Persist the dataset and prompt configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | PathLike[str]
|
Target directory for |
required |
Returns:
| Type | Description |
|---|---|
None
|
None. |
Raises:
| Type | Description |
|---|---|
OSError
|
If the directory or config file cannot be written. |
Examples:
>>> from tempfile import TemporaryDirectory
>>> from pydantic_ai.models.test import TestModel
>>> agent = LayoutPrompter(LayoutPrompterConfig(model=TestModel()))
>>> with TemporaryDirectory() as tmpdir:
... agent.save_pretrained(tmpdir)
Source code in models/layoutprompter/src/layoutprompter/agent.py
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 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | PathLike[str],
*,
model: ModelLike = None,
) -> "LayoutPrompter"
Load a saved LayoutPrompter dataset and prompt configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | PathLike[str]
|
Directory containing
|
required |
model
|
ModelLike
|
Replacement Pydantic AI model or model string. |
None
|
Returns:
| Type | Description |
|---|---|
'LayoutPrompter'
|
A configured |
Raises:
| Type | Description |
|---|---|
OSError
|
If the config file cannot be read. |
ValueError
|
If saved config modes are unsupported. |
Examples:
>>> from tempfile import TemporaryDirectory
>>> from pydantic_ai.models.test import TestModel
>>> model = TestModel(custom_output_args={"elements": []})
>>> agent = LayoutPrompter(LayoutPrompterConfig(model=model))
>>> with TemporaryDirectory() as tmpdir:
... agent.save_pretrained(tmpdir)
... loaded = LayoutPrompter.from_pretrained(tmpdir, model=model)
>>> isinstance(loaded, LayoutPrompter)
True
Source code in models/layoutprompter/src/layoutprompter/agent.py
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 | |
resolve_model ¶
resolve_model(model: ModelLike = None) -> ModelLike
Resolve constructor or per-call model with LayoutPrompter defaults.
Source code in models/layoutprompter/src/layoutprompter/agent.py
441 442 443 | |
LayoutPrompterConfig
dataclass
¶
Runtime configuration for LayoutPrompter prompt generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
SupportedDataset | str
|
Dataset vocabulary to use. Public strings are normalized to
|
publaynet
|
condition_type
|
ConditionType | str
|
Public condition name or release alias. |
label
|
input_format
|
PromptFormat | str
|
Prompt input format, either |
SEQ
|
output_format
|
PromptFormat | str
|
Model output format, either |
SEQ
|
candidate_size
|
int
|
Number of training candidates to keep before retrieval.
|
DEFAULT_CANDIDATE_SIZE
|
num_prompt
|
int
|
Maximum number of few-shot exemplars in each prompt. |
DEFAULT_NUM_PROMPT
|
shuffle
|
bool
|
Whether to shuffle selected exemplars after ranking. |
True
|
seed
|
int | None
|
Optional deterministic seed for exemplar selection. |
None
|
max_length
|
int
|
Maximum prompt length used while adding exemplars. |
DEFAULT_MAX_LENGTH
|
temperature
|
float
|
Model sampling temperature passed to Pydantic AI. |
DEFAULT_TEMPERATURE
|
top_p
|
float
|
Nucleus sampling value passed to Pydantic AI. |
DEFAULT_TOP_P
|
model
|
ModelLike
|
Pydantic AI model instance or model string. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a dataset, condition, or prompt format is unsupported. |
Examples:
>>> from pydantic_ai.models.test import TestModel
>>> config = LayoutPrompterConfig(
... dataset="webui",
... condition_type="label",
... model=TestModel(custom_output_args={"elements": []}),
... )
>>> config.task
'gent'
Source code in models/layoutprompter/src/layoutprompter/agent.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
__post_init__ ¶
__post_init__() -> None
Normalize public string modes to enums at the config boundary.
Source code in models/layoutprompter/src/layoutprompter/agent.py
122 123 124 125 126 127 128 129 130 131 132 133 | |
LayoutPrompterDataset ¶
Bases: StrEnum
LayoutPrompter-only dataset names absent from the shared registry.
Source code in models/layoutprompter/src/layoutprompter/enums.py
8 9 10 11 12 | |
LayoutPrompterTask ¶
Bases: StrEnum
Released task keys supported by LayoutPrompter.
Source code in models/layoutprompter/src/layoutprompter/enums.py
29 30 31 32 33 34 35 36 37 38 | |
OutputType ¶
Bases: StrEnum
Supported return containers for the shared call interface.
Source code in models/layoutprompter/src/layoutprompter/enums.py
22 23 24 25 26 | |
PromptFormat ¶
Bases: StrEnum
Supported LayoutPrompter prompt encodings.
Source code in models/layoutprompter/src/layoutprompter/enums.py
15 16 17 18 19 | |
LayoutPrompterOutput ¶
Bases: BaseModel
Structured output requested from the Pydantic AI model.
Source code in models/layoutprompter/src/layoutprompter/schemas.py
32 33 34 35 | |
agent ¶
Pydantic AI wrapper for LayoutPrompter.
LayoutPrompterConfig
dataclass
¶
Runtime configuration for LayoutPrompter prompt generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
SupportedDataset | str
|
Dataset vocabulary to use. Public strings are normalized to
|
publaynet
|
condition_type
|
ConditionType | str
|
Public condition name or release alias. |
label
|
input_format
|
PromptFormat | str
|
Prompt input format, either |
SEQ
|
output_format
|
PromptFormat | str
|
Model output format, either |
SEQ
|
candidate_size
|
int
|
Number of training candidates to keep before retrieval.
|
DEFAULT_CANDIDATE_SIZE
|
num_prompt
|
int
|
Maximum number of few-shot exemplars in each prompt. |
DEFAULT_NUM_PROMPT
|
shuffle
|
bool
|
Whether to shuffle selected exemplars after ranking. |
True
|
seed
|
int | None
|
Optional deterministic seed for exemplar selection. |
None
|
max_length
|
int
|
Maximum prompt length used while adding exemplars. |
DEFAULT_MAX_LENGTH
|
temperature
|
float
|
Model sampling temperature passed to Pydantic AI. |
DEFAULT_TEMPERATURE
|
top_p
|
float
|
Nucleus sampling value passed to Pydantic AI. |
DEFAULT_TOP_P
|
model
|
ModelLike
|
Pydantic AI model instance or model string. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a dataset, condition, or prompt format is unsupported. |
Examples:
>>> from pydantic_ai.models.test import TestModel
>>> config = LayoutPrompterConfig(
... dataset="webui",
... condition_type="label",
... model=TestModel(custom_output_args={"elements": []}),
... )
>>> config.task
'gent'
Source code in models/layoutprompter/src/layoutprompter/agent.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
__post_init__ ¶
__post_init__() -> None
Normalize public string modes to enums at the config boundary.
Source code in models/layoutprompter/src/layoutprompter/agent.py
122 123 124 125 126 127 128 129 130 131 132 133 | |
LayoutPrompter ¶
Bases: BaseLayoutAgent[LayoutPrompterOutput]
High-level LayoutPrompter Pydantic AI agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutPrompterConfig
|
Runtime prompt, retrieval, parser, and model settings. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the config contains an unsupported mode. |
Examples:
>>> import numpy as np
>>> from pydantic_ai.models.test import TestModel
>>> model = TestModel(custom_output_args={"elements": []})
>>> agent = LayoutPrompter(LayoutPrompterConfig(model=model, num_prompt=1))
>>> isinstance(agent, LayoutPrompter)
True
Source code in models/layoutprompter/src/layoutprompter/agent.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 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 | |
__init__ ¶
__init__(config: LayoutPrompterConfig) -> None
Create a LayoutPrompter runner from runtime config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutPrompterConfig
|
Agent configuration. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a config mode cannot be normalized. |
Source code in models/layoutprompter/src/layoutprompter/agent.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
build_prompt ¶
build_prompt(
train_data: Sequence[LayoutRecord],
test_data: LayoutRecord,
) -> str
Select exemplars and build the final LayoutPrompter prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_data
|
Sequence[LayoutRecord]
|
Candidate exemplar records with |
required |
test_data
|
LayoutRecord
|
Test record containing task-specific constraints. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The final few-shot prompt sent to the configured model. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If required record fields are missing. |
Examples:
>>> import numpy as np
>>> from pydantic_ai.models.test import TestModel
>>> record = {
... "labels": np.asarray([0]),
... "bboxes": np.asarray([[1, 2, 3, 4]]),
... "discrete_gold_bboxes": np.asarray([[1, 2, 3, 4]]),
... }
>>> agent = LayoutPrompter(
... LayoutPrompterConfig(model=TestModel(), shuffle=False, num_prompt=1)
... )
>>> "Element Type Constraint" in agent.build_prompt([record], record)
True
Source code in models/layoutprompter/src/layoutprompter/agent.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
run_sync ¶
run_sync(
train_data: Sequence[LayoutRecord],
test_data: LayoutRecord,
) -> LayoutGenerationOutput
Run the Pydantic AI model and return the common layout schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_data
|
Sequence[LayoutRecord]
|
Candidate exemplar records. |
required |
test_data
|
LayoutRecord
|
Test record containing task-specific constraints. |
required |
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput
|
A |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the model output cannot be parsed. |
Examples:
>>> import numpy as np
>>> from pydantic_ai.models.test import TestModel
>>> model = TestModel(custom_output_args={"elements": []})
>>> record = {
... "labels": np.asarray([0]),
... "bboxes": np.asarray([[1, 2, 3, 4]]),
... "discrete_gold_bboxes": np.asarray([[1, 2, 3, 4]]),
... }
>>> agent = LayoutPrompter(LayoutPrompterConfig(model=model, num_prompt=1))
>>> agent.run_sync([record], record).labels.shape[0]
1
Source code in models/layoutprompter/src/layoutprompter/agent.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
__call__ ¶
__call__(
*,
train_data: Sequence[LayoutRecord],
test_data: LayoutRecord,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType | str | None = None,
labels: Int[ndarray, "batch elements"]
| LayoutRecordPayload
| None = None,
bbox: Float[ndarray, "batch elements 4"]
| LayoutRecordPayload
| None = None,
mask: Bool[ndarray, "batch elements"]
| LayoutRecordPayload
| None = None,
num_elements: int
| list[int]
| Int[ndarray, "batch"]
| LayoutRecordPayload
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
num_inference_steps: int | None = None,
output_type: OutputType | str = OutputType.DATACLASS,
return_intermediates: bool = False,
) -> LayoutGenerationOutput | LayoutOutputDict
Expose the shared generation signature for LayoutPrompter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_data
|
Sequence[LayoutRecord]
|
Candidate exemplar records. |
required |
test_data
|
LayoutRecord
|
Test record containing task-specific constraints. |
required |
batch_size
|
int
|
Accepted for shared interface compatibility. |
1
|
seed
|
int | None
|
Accepted for shared interface compatibility. |
None
|
generator
|
Generator | None
|
Accepted for shared interface compatibility. |
None
|
condition_type
|
ConditionType | str | None
|
Accepted for shared interface compatibility. |
None
|
labels
|
Int[ndarray, 'batch elements'] | LayoutRecordPayload | None
|
Accepted for shared interface compatibility. |
None
|
bbox
|
Float[ndarray, 'batch elements 4'] | LayoutRecordPayload | None
|
Accepted for shared interface compatibility. |
None
|
mask
|
Bool[ndarray, 'batch elements'] | LayoutRecordPayload | None
|
Accepted for shared interface compatibility. |
None
|
num_elements
|
int | list[int] | Int[ndarray, 'batch'] | LayoutRecordPayload | None
|
Accepted for shared interface compatibility. |
None
|
box_format
|
BoxFormat | str
|
Public input box format name; validated at the boundary. |
xywh
|
normalized
|
bool
|
Accepted for shared interface compatibility. |
True
|
canvas_size
|
tuple[int, int] | None
|
Accepted for shared interface compatibility. |
None
|
num_inference_steps
|
int | None
|
Accepted for shared interface compatibility. |
None
|
output_type
|
OutputType | str
|
|
DATACLASS
|
return_intermediates
|
bool
|
Accepted for shared interface compatibility. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | LayoutOutputDict
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import numpy as np
>>> from pydantic_ai.models.test import TestModel
>>> model = TestModel(custom_output_args={"elements": []})
>>> record = {
... "labels": np.asarray([0]),
... "bboxes": np.asarray([[1, 2, 3, 4]]),
... "discrete_gold_bboxes": np.asarray([[1, 2, 3, 4]]),
... }
>>> agent = LayoutPrompter(LayoutPrompterConfig(model=model, num_prompt=1))
>>> isinstance(agent(train_data=[record], test_data=record), LayoutGenerationOutput)
True
Source code in models/layoutprompter/src/layoutprompter/agent.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
) -> None
Persist the dataset and prompt configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | PathLike[str]
|
Target directory for |
required |
Returns:
| Type | Description |
|---|---|
None
|
None. |
Raises:
| Type | Description |
|---|---|
OSError
|
If the directory or config file cannot be written. |
Examples:
>>> from tempfile import TemporaryDirectory
>>> from pydantic_ai.models.test import TestModel
>>> agent = LayoutPrompter(LayoutPrompterConfig(model=TestModel()))
>>> with TemporaryDirectory() as tmpdir:
... agent.save_pretrained(tmpdir)
Source code in models/layoutprompter/src/layoutprompter/agent.py
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 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | PathLike[str],
*,
model: ModelLike = None,
) -> "LayoutPrompter"
Load a saved LayoutPrompter dataset and prompt configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | PathLike[str]
|
Directory containing
|
required |
model
|
ModelLike
|
Replacement Pydantic AI model or model string. |
None
|
Returns:
| Type | Description |
|---|---|
'LayoutPrompter'
|
A configured |
Raises:
| Type | Description |
|---|---|
OSError
|
If the config file cannot be read. |
ValueError
|
If saved config modes are unsupported. |
Examples:
>>> from tempfile import TemporaryDirectory
>>> from pydantic_ai.models.test import TestModel
>>> model = TestModel(custom_output_args={"elements": []})
>>> agent = LayoutPrompter(LayoutPrompterConfig(model=model))
>>> with TemporaryDirectory() as tmpdir:
... agent.save_pretrained(tmpdir)
... loaded = LayoutPrompter.from_pretrained(tmpdir, model=model)
>>> isinstance(loaded, LayoutPrompter)
True
Source code in models/layoutprompter/src/layoutprompter/agent.py
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 | |
resolve_model ¶
resolve_model(model: ModelLike = None) -> ModelLike
Resolve constructor or per-call model with LayoutPrompter defaults.
Source code in models/layoutprompter/src/layoutprompter/agent.py
441 442 443 | |
normalize_prompt_format ¶
normalize_prompt_format(
prompt_format: PromptFormat | str,
) -> PromptFormat
Return a prompt-format enum from a public string value.
Source code in models/layoutprompter/src/layoutprompter/agent.py
59 60 61 62 63 64 | |
normalize_output_type ¶
normalize_output_type(
output_type: OutputType | str,
) -> OutputType
Return an output-type enum from a public string value.
Source code in models/layoutprompter/src/layoutprompter/agent.py
67 68 69 70 71 72 | |
arrays ¶
Array normalization helpers for LayoutPrompter's numpy-only pipeline.
as_int_array ¶
as_int_array(
value: ArrayInputScalar
| Int[ndarray, "..."]
| Float[ndarray, "..."]
| Bool[ndarray, "..."]
| Sequence[ArrayInputScalar]
| Sequence[Sequence[ArrayInputScalar]],
) -> Int[np.ndarray, "..."]
Return an integer numpy array from an array-like record value.
Source code in models/layoutprompter/src/layoutprompter/arrays.py
14 15 16 17 18 19 20 21 22 23 | |
as_float_array ¶
as_float_array(
value: ArrayInputScalar
| Int[ndarray, "..."]
| Float[ndarray, "..."]
| Bool[ndarray, "..."]
| Sequence[ArrayInputScalar]
| Sequence[Sequence[ArrayInputScalar]],
) -> Float[np.ndarray, "..."]
Return a float numpy array from an array-like record value.
Source code in models/layoutprompter/src/layoutprompter/arrays.py
26 27 28 29 30 31 32 33 34 35 | |
data ¶
Dataset constants used by LayoutPrompter prompts and parsing.
normalize_dataset ¶
normalize_dataset(
dataset: SupportedDataset | str,
) -> SupportedDataset
Return a supported dataset enum from a public string value.
Source code in models/layoutprompter/src/layoutprompter/data.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
id2label ¶
id2label(dataset: SupportedDataset | str) -> dict[int, str]
Return public 0-based dataset-local label mapping.
Source code in models/layoutprompter/src/layoutprompter/data.py
72 73 74 | |
label2id ¶
label2id(dataset: SupportedDataset | str) -> dict[str, int]
Return public 0-based dataset-local label ids.
Source code in models/layoutprompter/src/layoutprompter/data.py
77 78 79 | |
enums ¶
Closed string vocabularies used by the LayoutPrompter package.
LayoutPrompterDataset ¶
Bases: StrEnum
LayoutPrompter-only dataset names absent from the shared registry.
Source code in models/layoutprompter/src/layoutprompter/enums.py
8 9 10 11 12 | |
PromptFormat ¶
Bases: StrEnum
Supported LayoutPrompter prompt encodings.
Source code in models/layoutprompter/src/layoutprompter/enums.py
15 16 17 18 19 | |
OutputType ¶
Bases: StrEnum
Supported return containers for the shared call interface.
Source code in models/layoutprompter/src/layoutprompter/enums.py
22 23 24 25 26 | |
LayoutPrompterTask ¶
Bases: StrEnum
Released task keys supported by LayoutPrompter.
Source code in models/layoutprompter/src/layoutprompter/enums.py
29 30 31 32 33 34 35 36 37 38 | |
normalize_layoutprompter_task ¶
normalize_layoutprompter_task(
task: LayoutPrompterTask | str,
) -> LayoutPrompterTask
Return a LayoutPrompter task enum from a public or release string.
Source code in models/layoutprompter/src/layoutprompter/enums.py
41 42 43 44 45 46 47 48 | |
parsing ¶
Prediction parsing for seq/html LayoutPrompter outputs.
Parser ¶
Bases: BaseResponseParser[LayoutGenerationOutput]
Parse raw or structured predictions into the common output schema.
Source code in models/layoutprompter/src/layoutprompter/parsing.py
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
__init__ ¶
__init__(
dataset: SupportedDataset | str,
output_format: PromptFormat | str,
) -> None
Create a parser for one dataset and output format.
Source code in models/layoutprompter/src/layoutprompter/parsing.py
27 28 29 30 31 32 33 34 35 36 37 38 39 | |
__call__ ¶
__call__(
text: str, *, canvas_size: int | None = None
) -> LayoutGenerationOutput
Parse repaired provider text through the shared parser protocol.
Source code in models/layoutprompter/src/layoutprompter/parsing.py
41 42 43 44 45 46 | |
parse_one ¶
parse_one(
prediction: str | LayoutPrompterOutput,
) -> LayoutGenerationOutput
Parse one prediction into LayoutGenerationOutput.
Source code in models/layoutprompter/src/layoutprompter/parsing.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
parse_many ¶
parse_many(
predictions: list[str],
) -> list[LayoutGenerationOutput]
Parse all valid string predictions and skip malformed ones.
Source code in models/layoutprompter/src/layoutprompter/parsing.py
67 68 69 70 71 72 73 74 75 | |
parse_vendor_compatible ¶
parse_vendor_compatible(
prediction: str,
) -> tuple[
Int[np.ndarray, "elements"],
Float[np.ndarray, "elements 4"],
]
Parse string output as checkpoint-compatible normalized top-left xywh.
Source code in models/layoutprompter/src/layoutprompter/parsing.py
77 78 79 80 81 82 83 84 85 86 87 88 89 | |
records ¶
Typed record keys used by LayoutPrompter serializers and selectors.
LayoutRecordKey ¶
Bases: StrEnum
Closed key set for dict-like layout records.
Source code in models/layoutprompter/src/layoutprompter/records.py
15 16 17 18 19 20 21 22 23 24 25 26 | |
LayoutRecord ¶
Bases: TypedDict
Structured LayoutPrompter record accepted by prompt and selector code.
Source code in models/layoutprompter/src/layoutprompter/records.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
record_value ¶
record_value(
data: LayoutRecordInput, key: LayoutRecordKey
) -> (
LayoutRecordScalar
| Int[np.ndarray, ...]
| Float[np.ndarray, ...]
| Bool[np.ndarray, ...]
| Sequence[int | float | str | bool | None]
| Sequence[Sequence[int | float | str | bool | None]]
)
Return a layout-record value by enum key.
Source code in models/layoutprompter/src/layoutprompter/records.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
optional_record_value ¶
optional_record_value(
data: LayoutRecordInput,
key: LayoutRecordKey,
default: LayoutRecordScalar
| Int[ndarray, ...]
| Float[ndarray, ...]
| Bool[ndarray, ...]
| Sequence[int | float | str | bool | None]
| Sequence[Sequence[int | float | str | bool | None]],
) -> (
LayoutRecordScalar
| Int[np.ndarray, ...]
| Float[np.ndarray, ...]
| Bool[np.ndarray, ...]
| Sequence[int | float | str | bool | None]
| Sequence[Sequence[int | float | str | bool | None]]
)
Return a layout-record value by enum key, or a default.
Source code in models/layoutprompter/src/layoutprompter/records.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
schemas ¶
Pydantic schemas for LayoutPrompter structured output.
PixelBBox ¶
Bases: BaseModel
Top-left pixel xywh bbox emitted by the language model.
Source code in models/layoutprompter/src/layoutprompter/schemas.py
10 11 12 13 14 15 16 | |
LayoutElement ¶
Bases: BaseModel
One predicted layout element.
Source code in models/layoutprompter/src/layoutprompter/schemas.py
19 20 21 22 23 24 25 26 27 28 29 | |
normalize_label
classmethod
¶
normalize_label(value: str) -> str
Normalize model-produced labels for dataset lookup.
Source code in models/layoutprompter/src/layoutprompter/schemas.py
25 26 27 28 29 | |
LayoutPrompterOutput ¶
Bases: BaseModel
Structured output requested from the Pydantic AI model.
Source code in models/layoutprompter/src/layoutprompter/schemas.py
32 33 34 35 | |
selection ¶
Exemplar selection strategies for LayoutPrompter prompt construction.
ExemplarSelection
dataclass
¶
Bases: BaseExemplarSelector[LayoutRecord]
Base selector with candidate truncation and zero-size filtering.
Source code in models/layoutprompter/src/layoutprompter/selection.py
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 62 63 64 65 66 67 68 69 | |
__post_init__ ¶
__post_init__() -> None
Normalize candidate records and initialize deterministic randomness.
Source code in models/layoutprompter/src/layoutprompter/selection.py
41 42 43 44 45 46 47 | |
__call__ ¶
__call__(test_data: LayoutRecord) -> list[LayoutRecord]
Return selected exemplars for a test sample.
Source code in models/layoutprompter/src/layoutprompter/selection.py
49 50 51 | |
GenTypeExemplarSelection
dataclass
¶
Bases: ExemplarSelection
Select exemplars by element-type multiset similarity.
Source code in models/layoutprompter/src/layoutprompter/selection.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
__call__ ¶
__call__(test_data: LayoutRecord) -> list[LayoutRecord]
Return exemplars ranked by label overlap.
Source code in models/layoutprompter/src/layoutprompter/selection.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
GenTypeSizeExemplarSelection
dataclass
¶
Bases: ExemplarSelection
Select exemplars by labels and element sizes.
Source code in models/layoutprompter/src/layoutprompter/selection.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
__call__ ¶
__call__(test_data: LayoutRecord) -> list[LayoutRecord]
Return exemplars ranked by label and size similarity.
Source code in models/layoutprompter/src/layoutprompter/selection.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
GenRelationExemplarSelection
dataclass
¶
Bases: GenTypeExemplarSelection
Select relation-conditioned exemplars by label similarity.
Source code in models/layoutprompter/src/layoutprompter/selection.py
116 117 | |
CompletionExemplarSelection
dataclass
¶
Bases: ExemplarSelection
Select layout-completion exemplars by the first visible element.
Source code in models/layoutprompter/src/layoutprompter/selection.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
__call__ ¶
__call__(test_data: LayoutRecord) -> list[LayoutRecord]
Return exemplars ranked by the first partial element.
Source code in models/layoutprompter/src/layoutprompter/selection.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
RefinementExemplarSelection
dataclass
¶
Bases: ExemplarSelection
Select refinement exemplars by labels and noisy boxes.
Source code in models/layoutprompter/src/layoutprompter/selection.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
__call__ ¶
__call__(test_data: LayoutRecord) -> list[LayoutRecord]
Return exemplars ranked by noisy layout similarity.
Source code in models/layoutprompter/src/layoutprompter/selection.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
ContentAwareExemplarSelection
dataclass
¶
Bases: ExemplarSelection
Select poster exemplars by content-mask IoU.
Source code in models/layoutprompter/src/layoutprompter/selection.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
__call__ ¶
__call__(test_data: LayoutRecord) -> list[LayoutRecord]
Return exemplars ranked by content-mask IoU.
Source code in models/layoutprompter/src/layoutprompter/selection.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
TextToLayoutExemplarSelection
dataclass
¶
Bases: ExemplarSelection
Select text-to-layout exemplars by embedding dot product.
Source code in models/layoutprompter/src/layoutprompter/selection.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
__call__ ¶
__call__(test_data: LayoutRecord) -> list[LayoutRecord]
Return exemplars ranked by text embedding similarity.
Source code in models/layoutprompter/src/layoutprompter/selection.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
create_selector ¶
create_selector(
task: LayoutPrompterTask | str,
train_data: Sequence[LayoutRecord],
candidate_size: int,
num_prompt: int,
*,
shuffle: bool = True,
seed: int | None = None,
) -> ExemplarSelection
Create a selector for a LayoutPrompter task.
Source code in models/layoutprompter/src/layoutprompter/selection.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
serialization ¶
Prompt serialization ported from the LayoutPrompter notebooks.
Serializer
dataclass
¶
Base serializer for seq/html prompt examples.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
__post_init__ ¶
__post_init__() -> None
Normalize public string formats to enums.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
73 74 75 76 | |
build_input ¶
build_input(data: LayoutRecord) -> str
Serialize test constraints.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
78 79 80 81 82 83 84 | |
build_output ¶
build_output(
data: LayoutRecord,
label_key: LayoutRecordKey = K.labels,
bbox_key: LayoutRecordKey = K.discrete_gold_bboxes,
) -> str
Serialize an exemplar output layout.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
86 87 88 89 90 91 92 93 94 95 96 97 | |
GenTypeSerializer
dataclass
¶
Bases: Serializer
Serializer for element-type conditioned generation.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
build_input ¶
build_input(data: LayoutRecord) -> str
Serialize type constraints with the task prefix.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
184 185 186 187 | |
GenTypeSizeSerializer
dataclass
¶
Bases: GenTypeSerializer
Serializer for element-type and size conditioned generation.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
GenRelationSerializer
dataclass
¶
Bases: GenTypeSerializer
Serializer for relation-conditioned generation.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
build_input ¶
build_input(data: LayoutRecord) -> str
Serialize type and relation constraints.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
CompletionSerializer
dataclass
¶
Bases: Serializer
Serializer for layout completion.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
build_input ¶
build_input(data: LayoutRecord) -> str
Serialize partial layout constraints with the task prefix.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
324 325 326 327 | |
RefinementSerializer
dataclass
¶
Bases: Serializer
Serializer for noisy-layout refinement.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
build_input ¶
build_input(data: LayoutRecord) -> str
Serialize noisy layout constraints with the task prefix.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
344 345 346 347 | |
TextToLayoutSerializer
dataclass
¶
Bases: Serializer
Serializer for text-to-layout prompts.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
build_input ¶
build_input(data: LayoutRecord) -> str
Serialize text input with the task prefix.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
369 370 371 372 | |
ContentAwareSerializer
dataclass
¶
Bases: GenTypeSerializer
Serializer for content-aware poster layout generation.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
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 | |
build_input ¶
build_input(data: LayoutRecord) -> str
Serialize content masks and element type constraints.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
403 404 405 406 | |
create_serializer ¶
create_serializer(
dataset: SupportedDataset | str,
task: LayoutPrompterTask | str,
input_format: PromptFormat | str,
output_format: PromptFormat | str,
*,
add_index_token: bool = True,
add_sep_token: bool = True,
add_unk_token: bool = False,
) -> Serializer
Create a task serializer.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | |
build_prompt ¶
build_prompt(
serializer: Serializer,
exemplars: Sequence[LayoutRecord],
test_data: LayoutRecord,
dataset: SupportedDataset | str,
*,
max_length: int = DEFAULT_MAX_LENGTH,
separator_in_samples: str = "\n",
separator_between_samples: str = "\n\n",
) -> str
Build the final few-shot LayoutPrompter prompt.
Source code in models/layoutprompter/src/layoutprompter/serialization.py
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 | |
similarity ¶
Similarity functions ported from LayoutPrompter exemplar selection.
labels_similarity ¶
labels_similarity(
labels_1: Int[ndarray, "elements"],
labels_2: Int[ndarray, "elements"],
) -> float
Compute the reference multiset label overlap score.
Source code in models/layoutprompter/src/layoutprompter/similarity.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
bboxes_similarity ¶
bboxes_similarity(
labels_1: Int[ndarray, "elements_1"],
bboxes_1: Float[ndarray, "elements_1 4"],
labels_2: Int[ndarray, "elements_2"],
bboxes_2: Float[ndarray, "elements_2 4"],
) -> float
Compute LayoutPrompter's label-masked bbox matching score.
Source code in models/layoutprompter/src/layoutprompter/similarity.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
labels_bboxes_similarity ¶
labels_bboxes_similarity(
labels_1: Int[ndarray, "elements_1"],
bboxes_1: Float[ndarray, "elements_1 dims"],
labels_2: Int[ndarray, "elements_2"],
bboxes_2: Float[ndarray, "elements_2 dims"],
labels_weight: float,
bboxes_weight: float,
) -> float
Combine label and bbox similarities with reference weights.
Source code in models/layoutprompter/src/layoutprompter/similarity.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
vendor_parity ¶
Small deterministic records shared by reference parity scripts and tests.
fixture_records ¶
fixture_records() -> tuple[
list[LayoutRecord], LayoutRecord
]
Return fixed train/test records shared by reference and local tests.
Source code in models/layoutprompter/src/layoutprompter/vendor_parity.py
12 13 14 15 16 17 18 19 20 | |
parser_prediction ¶
parser_prediction() -> str
Return a cached LLM-like response string for parser parity.
Source code in models/layoutprompter/src/layoutprompter/vendor_parity.py
23 24 25 | |