Parse then place
Parse-Then-Place Transformers-style conversion package.
ParseThenPlaceConfig ¶
Bases: PretrainedConfig
Stores Parse-Then-Place dataset and generation defaults.
Source code in models/parse-then-place/src/parse_then_place/configuration_parse_then_place.py
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 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 | |
__init__ ¶
__init__(
dataset_name: str = "rico",
stage2_mode: Stage2Mode | str = Stage2Mode.finetune,
parser_model_name: str = "google/t5-v1_1-base",
parser_generation_max_length: int = 600,
placement_generation_max_length: int = 500,
temperature: float = 0.7,
num_return_sequences: int = 5,
canvas_size: tuple[int, int] | list[int] | None = None,
id2label: dict[int | str, str] | None = None,
parser_subfolder: str = "semantic_parser",
placement_subfolder: str = "placement",
pad_token_id: int = 0,
eos_token_id: int = 1,
decoder_start_token_id: int = 0,
is_encoder_decoder: bool = True,
transformers_version: str | None = None,
architectures: list[str] | None = None,
output_hidden_states: bool | None = False,
return_dict: bool | None = True,
dtype: str | None = None,
torch_dtype: str | None = None,
chunk_size_feed_forward: int = 0,
problem_type: Literal[
"regression",
"single_label_classification",
"multi_label_classification",
]
| None = None,
name_or_path: str = "",
_commit_hash: str | None = None,
attn_implementation: str | None = None,
**kwargs: str | int | float | bool | None,
) -> None
Initialize the composite checkpoint configuration.
Source code in models/parse-then-place/src/parse_then_place/configuration_parse_then_place.py
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 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 | |
ParseThenPlaceDatasetName ¶
Bases: StrEnum
Datasets supported by the original Parse-Then-Place release.
Source code in models/parse-then-place/src/parse_then_place/labels.py
11 12 13 14 15 | |
Stage2Mode ¶
Bases: StrEnum
Released stage-2 checkpoint modes.
Source code in models/parse-then-place/src/parse_then_place/labels.py
18 19 20 21 22 | |
ParseThenPlacePipeline ¶
Bases: LayoutGenerationPipeline
Compose standard seq2seq parser and placement models.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
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 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 | |
__init__ ¶
__init__(
config: ParseThenPlaceConfig,
processor: ParseThenPlaceProcessor,
*,
parser: PreTrainedModel | None = None,
placement: PreTrainedModel | None = None,
) -> None
Initialize the composite pipeline.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | Path,
*,
parser: PreTrainedModel | None = None,
placement: PreTrainedModel | None = None,
processor: ParseThenPlaceProcessor | None = None,
local_files_only: bool = False,
config: ParseThenPlaceConfig
| PretrainedConfig
| None = None,
) -> ParseThenPlacePipeline
Load a composite pipeline from a root directory.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
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 | |
parse ¶
parse(
input_ids: Int[Tensor, "batch tokens"],
attention_mask: Bool[Tensor, "batch tokens"]
| None = None,
*,
generation_max_length: int | None = None,
**generate_kwargs: str
| int
| float
| bool
| Generator
| None,
) -> Int[torch.Tensor, "batch tokens"]
Generate logical-form token ids with the parser stage.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
place ¶
place(
input_ids: Int[Tensor, "batch tokens"],
attention_mask: Bool[Tensor, "batch tokens"]
| None = None,
*,
generation_max_length: int | None = None,
num_return_sequences: int | None = None,
temperature: float | None = None,
do_sample: bool = True,
generator: Generator | None = None,
**generate_kwargs: str
| float
| bool
| Generator
| None,
) -> Int[torch.Tensor, "batch tokens"]
Generate layout token ids with the placement stage.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
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 | |
__call__ ¶
__call__(
*,
prompt: str | Sequence[str] | None = None,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.text,
labels: Int[Tensor, "batch elements"]
| list[ArrayLikeInput]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| list[ArrayLikeInput]
| None = None,
mask: Bool[Tensor, "batch elements"]
| list[ArrayLikeInput]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
num_inference_steps: int | None = None,
num_return_sequences: int | None = None,
temperature: float | None = None,
output_candidate: Literal[
"first", "all", "best"
] = "first",
output_type: Literal["dataclass", "dict"] = "dataclass",
return_intermediates: bool = False,
layout_text: str
| list[str]
| list[list[str]]
| None = None,
) -> LayoutGenerationOutput | ParseThenPlaceOutputDict
Generate a layout from natural-language text.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
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 | |
ParseThenPlaceProcessor ¶
Bases: ProcessorMixin
Build stage inputs and parse placement-model output text.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 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 | |
__init__ ¶
__init__(
parser_tokenizer: PreTrainedTokenizerBase | None = None,
placement_tokenizer: PreTrainedTokenizerBase
| None = None,
dataset_name: ParseThenPlaceDatasetName
| str = ParseThenPlaceDatasetName.rico,
canvas_size: tuple[int, int] | None = None,
id2label: dict[int, str] | None = None,
) -> None
Initialize tokenizer handles and dataset metadata.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 | |
from_config
classmethod
¶
from_config(
dataset_name: ParseThenPlaceDatasetName
| str = ParseThenPlaceDatasetName.rico,
*,
canvas_size: tuple[int, int] | None = None,
id2label: dict[int, str] | None = None,
) -> ParseThenPlaceProcessor
Construct metadata-only processor for tests and local smoke checks.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
preprocess_prompt ¶
preprocess_prompt(
prompt: str, *, replace_explicit_value: bool = True
) -> PromptEncoding
Apply the released text normalization used before stage-1 parsing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Natural-language text prompt. |
required |
replace_explicit_value
|
bool
|
Whether quoted values should be replaced by
deterministic |
True
|
Returns:
| Type | Description |
|---|---|
PromptEncoding
|
Normalized prompt and the placeholder recovery map. |
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 | |
__call__ ¶
__call__(
prompt: str | Sequence[str],
*,
replace_explicit_value: bool = True,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Tokenize prompt text for the semantic parser stage.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 | |
postprocess_ir ¶
postprocess_ir(
generated_ids: Int[Tensor, "batch tokens"]
| Sequence[str],
*,
value_maps: list[dict[str, str] | None] | None = None,
) -> list[str]
Decode and lightly normalize stage-1 logical forms.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
ir_to_placement_inputs ¶
ir_to_placement_inputs(
logical_forms: Sequence[str],
) -> list[str]
Convert logical forms to placement-constraint strings.
Runtime keeps this method deterministic and accepts already-linearized constraints, which is also the artifact stored in stage-1 prediction JSON files. The current parity scripts do not execute the released grammar executor.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
237 238 239 240 241 242 243 244 245 | |
encode_placement_inputs ¶
encode_placement_inputs(
placement_inputs: Sequence[str],
*,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Tokenize stage-2 placement constraints.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
decode_layout_sequences ¶
decode_layout_sequences(
generated_ids: Int[Tensor, "batch tokens"]
| Sequence[str],
*,
batch_size: int,
num_return_sequences: int,
) -> list[list[str]]
Decode stage-2 generated ids into grouped layout strings.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 | |
layout_text_to_output ¶
layout_text_to_output(
layout_text: Sequence[str] | Sequence[Sequence[str]],
*,
output_candidate: Literal[
"first", "all", "best"
] = "first",
output_type: Literal["dataclass", "dict"] = "dataclass",
return_intermediates: bool = False,
) -> LayoutGenerationOutput | ParseThenPlaceOutputDict
Parse generated label left top width height text into schema.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 | |
canvas_size_for_dataset ¶
canvas_size_for_dataset(
dataset_name: ParseThenPlaceDatasetName | str,
) -> tuple[int, int]
Return the dataset canvas size as (width, height).
Source code in models/parse-then-place/src/parse_then_place/labels.py
127 128 129 130 131 | |
id2label_for_dataset ¶
id2label_for_dataset(
dataset_name: ParseThenPlaceDatasetName | str,
) -> dict[int, str]
Return the dataset-local integer-id label map.
Source code in models/parse-then-place/src/parse_then_place/labels.py
111 112 113 114 115 | |
label2id_for_dataset ¶
label2id_for_dataset(
dataset_name: ParseThenPlaceDatasetName | str,
) -> dict[str, int]
Return lower-case label names mapped to dataset-local ids.
Source code in models/parse-then-place/src/parse_then_place/labels.py
118 119 120 121 122 123 124 | |
normalize_dataset_name ¶
normalize_dataset_name(
dataset_name: ParseThenPlaceDatasetName | str,
) -> ParseThenPlaceDatasetName
Normalize Parse-Then-Place dataset names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
ParseThenPlaceDatasetName | str
|
Dataset enum value or public/release string. |
required |
Returns:
| Type | Description |
|---|---|
ParseThenPlaceDatasetName
|
Canonical Parse-Then-Place dataset name. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Source code in models/parse-then-place/src/parse_then_place/labels.py
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 | |
normalize_stage2_mode ¶
normalize_stage2_mode(
stage2_mode: Stage2Mode | str,
) -> Stage2Mode
Normalize a released stage-2 checkpoint mode.
Source code in models/parse-then-place/src/parse_then_place/labels.py
94 95 96 97 98 99 100 101 | |
configuration_parse_then_place ¶
Configuration for Parse-Then-Place composite checkpoints.
ParseThenPlaceConfig ¶
Bases: PretrainedConfig
Stores Parse-Then-Place dataset and generation defaults.
Source code in models/parse-then-place/src/parse_then_place/configuration_parse_then_place.py
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 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 | |
__init__ ¶
__init__(
dataset_name: str = "rico",
stage2_mode: Stage2Mode | str = Stage2Mode.finetune,
parser_model_name: str = "google/t5-v1_1-base",
parser_generation_max_length: int = 600,
placement_generation_max_length: int = 500,
temperature: float = 0.7,
num_return_sequences: int = 5,
canvas_size: tuple[int, int] | list[int] | None = None,
id2label: dict[int | str, str] | None = None,
parser_subfolder: str = "semantic_parser",
placement_subfolder: str = "placement",
pad_token_id: int = 0,
eos_token_id: int = 1,
decoder_start_token_id: int = 0,
is_encoder_decoder: bool = True,
transformers_version: str | None = None,
architectures: list[str] | None = None,
output_hidden_states: bool | None = False,
return_dict: bool | None = True,
dtype: str | None = None,
torch_dtype: str | None = None,
chunk_size_feed_forward: int = 0,
problem_type: Literal[
"regression",
"single_label_classification",
"multi_label_classification",
]
| None = None,
name_or_path: str = "",
_commit_hash: str | None = None,
attn_implementation: str | None = None,
**kwargs: str | int | float | bool | None,
) -> None
Initialize the composite checkpoint configuration.
Source code in models/parse-then-place/src/parse_then_place/configuration_parse_then_place.py
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 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 | |
labels ¶
Dataset metadata for Parse-Then-Place checkpoints.
ParseThenPlaceDatasetName ¶
Bases: StrEnum
Datasets supported by the original Parse-Then-Place release.
Source code in models/parse-then-place/src/parse_then_place/labels.py
11 12 13 14 15 | |
Stage2Mode ¶
Bases: StrEnum
Released stage-2 checkpoint modes.
Source code in models/parse-then-place/src/parse_then_place/labels.py
18 19 20 21 22 | |
DatasetMetadata ¶
Bases: TypedDict
Static conversion metadata for one dataset.
Source code in models/parse-then-place/src/parse_then_place/labels.py
25 26 27 28 29 30 | |
normalize_dataset_name ¶
normalize_dataset_name(
dataset_name: ParseThenPlaceDatasetName | str,
) -> ParseThenPlaceDatasetName
Normalize Parse-Then-Place dataset names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
ParseThenPlaceDatasetName | str
|
Dataset enum value or public/release string. |
required |
Returns:
| Type | Description |
|---|---|
ParseThenPlaceDatasetName
|
Canonical Parse-Then-Place dataset name. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Source code in models/parse-then-place/src/parse_then_place/labels.py
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 | |
normalize_stage2_mode ¶
normalize_stage2_mode(
stage2_mode: Stage2Mode | str,
) -> Stage2Mode
Normalize a released stage-2 checkpoint mode.
Source code in models/parse-then-place/src/parse_then_place/labels.py
94 95 96 97 98 99 100 101 | |
dataset_metadata ¶
dataset_metadata(
dataset_name: ParseThenPlaceDatasetName | str,
) -> DatasetMetadata
Return static metadata for a Parse-Then-Place dataset.
Source code in models/parse-then-place/src/parse_then_place/labels.py
104 105 106 107 108 | |
id2label_for_dataset ¶
id2label_for_dataset(
dataset_name: ParseThenPlaceDatasetName | str,
) -> dict[int, str]
Return the dataset-local integer-id label map.
Source code in models/parse-then-place/src/parse_then_place/labels.py
111 112 113 114 115 | |
label2id_for_dataset ¶
label2id_for_dataset(
dataset_name: ParseThenPlaceDatasetName | str,
) -> dict[str, int]
Return lower-case label names mapped to dataset-local ids.
Source code in models/parse-then-place/src/parse_then_place/labels.py
118 119 120 121 122 123 124 | |
canvas_size_for_dataset ¶
canvas_size_for_dataset(
dataset_name: ParseThenPlaceDatasetName | str,
) -> tuple[int, int]
Return the dataset canvas size as (width, height).
Source code in models/parse-then-place/src/parse_then_place/labels.py
127 128 129 130 131 | |
pipeline_parse_then_place ¶
Pipeline wrapper for Parse-Then-Place composite checkpoints.
ParseThenPlacePipeline ¶
Bases: LayoutGenerationPipeline
Compose standard seq2seq parser and placement models.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
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 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 | |
__init__ ¶
__init__(
config: ParseThenPlaceConfig,
processor: ParseThenPlaceProcessor,
*,
parser: PreTrainedModel | None = None,
placement: PreTrainedModel | None = None,
) -> None
Initialize the composite pipeline.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | Path,
*,
parser: PreTrainedModel | None = None,
placement: PreTrainedModel | None = None,
processor: ParseThenPlaceProcessor | None = None,
local_files_only: bool = False,
config: ParseThenPlaceConfig
| PretrainedConfig
| None = None,
) -> ParseThenPlacePipeline
Load a composite pipeline from a root directory.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
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 | |
parse ¶
parse(
input_ids: Int[Tensor, "batch tokens"],
attention_mask: Bool[Tensor, "batch tokens"]
| None = None,
*,
generation_max_length: int | None = None,
**generate_kwargs: str
| int
| float
| bool
| Generator
| None,
) -> Int[torch.Tensor, "batch tokens"]
Generate logical-form token ids with the parser stage.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
place ¶
place(
input_ids: Int[Tensor, "batch tokens"],
attention_mask: Bool[Tensor, "batch tokens"]
| None = None,
*,
generation_max_length: int | None = None,
num_return_sequences: int | None = None,
temperature: float | None = None,
do_sample: bool = True,
generator: Generator | None = None,
**generate_kwargs: str
| float
| bool
| Generator
| None,
) -> Int[torch.Tensor, "batch tokens"]
Generate layout token ids with the placement stage.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
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 | |
__call__ ¶
__call__(
*,
prompt: str | Sequence[str] | None = None,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.text,
labels: Int[Tensor, "batch elements"]
| list[ArrayLikeInput]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| list[ArrayLikeInput]
| None = None,
mask: Bool[Tensor, "batch elements"]
| list[ArrayLikeInput]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
num_inference_steps: int | None = None,
num_return_sequences: int | None = None,
temperature: float | None = None,
output_candidate: Literal[
"first", "all", "best"
] = "first",
output_type: Literal["dataclass", "dict"] = "dataclass",
return_intermediates: bool = False,
layout_text: str
| list[str]
| list[list[str]]
| None = None,
) -> LayoutGenerationOutput | ParseThenPlaceOutputDict
Generate a layout from natural-language text.
Source code in models/parse-then-place/src/parse_then_place/pipeline_parse_then_place.py
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 | |
processing_parse_then_place ¶
Processor for Parse-Then-Place text, IR, and generated layout strings.
PromptEncoding ¶
Bases: TypedDict
Preprocessed prompt and value placeholders.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
24 25 26 27 28 | |
ParsedElement ¶
Bases: TypedDict
One parsed generated layout element.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
31 32 33 34 35 | |
TensorLike ¶
Bases: Protocol
Runtime-safe protocol for tensor-like processor dictionary values.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
46 47 48 49 50 51 52 53 | |
ParseThenPlaceProcessor ¶
Bases: ProcessorMixin
Build stage inputs and parse placement-model output text.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 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 | |
__init__ ¶
__init__(
parser_tokenizer: PreTrainedTokenizerBase | None = None,
placement_tokenizer: PreTrainedTokenizerBase
| None = None,
dataset_name: ParseThenPlaceDatasetName
| str = ParseThenPlaceDatasetName.rico,
canvas_size: tuple[int, int] | None = None,
id2label: dict[int, str] | None = None,
) -> None
Initialize tokenizer handles and dataset metadata.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 | |
from_config
classmethod
¶
from_config(
dataset_name: ParseThenPlaceDatasetName
| str = ParseThenPlaceDatasetName.rico,
*,
canvas_size: tuple[int, int] | None = None,
id2label: dict[int, str] | None = None,
) -> ParseThenPlaceProcessor
Construct metadata-only processor for tests and local smoke checks.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
preprocess_prompt ¶
preprocess_prompt(
prompt: str, *, replace_explicit_value: bool = True
) -> PromptEncoding
Apply the released text normalization used before stage-1 parsing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Natural-language text prompt. |
required |
replace_explicit_value
|
bool
|
Whether quoted values should be replaced by
deterministic |
True
|
Returns:
| Type | Description |
|---|---|
PromptEncoding
|
Normalized prompt and the placeholder recovery map. |
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 | |
__call__ ¶
__call__(
prompt: str | Sequence[str],
*,
replace_explicit_value: bool = True,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Tokenize prompt text for the semantic parser stage.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 | |
postprocess_ir ¶
postprocess_ir(
generated_ids: Int[Tensor, "batch tokens"]
| Sequence[str],
*,
value_maps: list[dict[str, str] | None] | None = None,
) -> list[str]
Decode and lightly normalize stage-1 logical forms.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
ir_to_placement_inputs ¶
ir_to_placement_inputs(
logical_forms: Sequence[str],
) -> list[str]
Convert logical forms to placement-constraint strings.
Runtime keeps this method deterministic and accepts already-linearized constraints, which is also the artifact stored in stage-1 prediction JSON files. The current parity scripts do not execute the released grammar executor.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
237 238 239 240 241 242 243 244 245 | |
encode_placement_inputs ¶
encode_placement_inputs(
placement_inputs: Sequence[str],
*,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Tokenize stage-2 placement constraints.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
decode_layout_sequences ¶
decode_layout_sequences(
generated_ids: Int[Tensor, "batch tokens"]
| Sequence[str],
*,
batch_size: int,
num_return_sequences: int,
) -> list[list[str]]
Decode stage-2 generated ids into grouped layout strings.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 | |
layout_text_to_output ¶
layout_text_to_output(
layout_text: Sequence[str] | Sequence[Sequence[str]],
*,
output_candidate: Literal[
"first", "all", "best"
] = "first",
output_type: Literal["dataclass", "dict"] = "dataclass",
return_intermediates: bool = False,
) -> LayoutGenerationOutput | ParseThenPlaceOutputDict
Parse generated label left top width height text into schema.
Source code in models/parse-then-place/src/parse_then_place/processing_parse_then_place.py
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 | |