"""Label sets shared by the synthetic data generator, the extraction model and JSON assembly.""" FIELD_LABELS = [ "other", # decorative / irrelevant text "key", # a label such as "Total:" or "Invoice No." whose value is a separate segment "merchant_name", "merchant_address", "merchant_phone", "merchant_tax_id", "customer", # bill-to block on invoices "invoice_number", "date", "due_date", "time", "item_desc", "item_qty", "item_unit_price", "item_amount", "subtotal", "tax", "discount", "total", "amount_paid", "change", "heading", "paragraph", "list_item", "table_cell", "formula", # display maths: detected and skipped (not transcribed) ] LABEL_ID = {n: i for i, n in enumerate(FIELD_LABELS)} DOC_TYPES = ["receipt", "invoice", "general"] DOC_ID = {n: i for i, n in enumerate(DOC_TYPES)} # Pairwise relations between segments. # same_row: both segments belong to the same line item / table row (symmetric) # key_value: segment i is the key whose value is segment j (directed) # same_block: both segments belong to the same layout block (paragraph, list item, table, caption...) # New labels and relations are appended so older checkpoints load into the matching rows (train --init). REL_TYPES = ["same_row", "key_value", "same_block"] MONEY_FIELDS = {"item_unit_price", "item_amount", "subtotal", "tax", "discount", "total", "amount_paid", "change"} ITEM_FIELDS = {"item_desc", "item_qty", "item_unit_price", "item_amount"} STRUCTURE_LABELS = {"heading", "paragraph", "list_item", "table_cell", "formula"}