# ilyalasy/dom-lm architecture

> Architecture diagram of the GitHub repository ilyalasy/dom-lm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ilyalasy/dom-lm
- Repository: https://github.com/ilyalasy/dom-lm

## Overview

DOM-LM is an unofficial PyTorch implementation for learning from webpage structure. The principal workflow is SWDE HTML pages → DOM-aware feature preprocessing → serialized feature dataset → whole-node masked-language-model training. The model combines DOM/tree embeddings with a Transformer encoder and task heads. The README also identifies fine-tuning for attribute extraction, open information extraction, and QA as future work; the code exposes token-classification and QA model classes, but no complete fine-tuning workflow is documented. Arrows reflect shown calls, data handling, or README workflow; unsampled details are omitted.

Main entry points: [`src/train.py`](https://github.com/ilyalasy/dom-lm/blob/main/src/train.py) (Training orchestration), [`src/preprocess_swde.py`](https://github.com/ilyalasy/dom-lm/blob/main/src/preprocess_swde.py) (SWDE preprocessing), [`src/preprocess.py`](https://github.com/ilyalasy/dom-lm/blob/main/src/preprocess.py) (DOM features), [`src/domlm/modeling_domlm.py`](https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/modeling_domlm.py) (Masked-LM head)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["DOM preprocessing"]
  node_clean["HTML cleanup<br/>[html_utils.py]"]
  node_features["DOM features<br/>[preprocess.py]"]
  node_swdeprep["SWDE preprocessing<br/>[preprocess_swde.py]"]
end

subgraph group_data["Training data"]
  node_featurefiles[("Feature files")]
  node_dataset["SWDE dataset<br/>[dataset.py]"]
  node_collator["Node-mask collator<br/>[data_collator.py]"]
end

subgraph group_model["DOM-LM model"]
  node_config["Model configuration"]
  node_embeddings["DOM embeddings<br/>[modeling_domlm.py]"]
  node_encoder["Transformer encoder<br/>[modeling_domlm.py]"]
  node_mlm["Masked-LM head<br/>[modeling_domlm.py]"]
  node_taskheads["Task heads<br/>[modeling_domlm.py]"]
end

subgraph group_tasks["Training and tasks"]
  node_trainer["Training orchestration<br/>[train.py]"]
  node_mlmresult["Trained MLM"]
  node_attr["Attribute extraction<br/>[preprocess.py]"]
  node_qa["Question answering<br/>[modeling_domlm.py]"]
end

node_engineer(("Researcher"))
node_swde["SWDE HTML"]

node_engineer -->|"runs preprocessing"| node_swdeprep
node_swde -->|"provides pages"| node_swdeprep
node_swdeprep -->|"extracts features"| node_features
node_features -->|"cleans HTML"| node_clean
node_swdeprep -->|"writes features"| node_featurefiles
node_featurefiles -->|"loads pickles"| node_dataset
node_engineer -->|"runs training"| node_trainer
node_trainer -->|"uses samples"| node_dataset
node_trainer -->|"configures batches"| node_collator
node_trainer -->|"trains model"| node_mlm
node_config -->|"configures"| node_embeddings
node_embeddings -->|"feeds representations"| node_encoder
node_encoder -->|"feeds hidden states"| node_mlm
node_trainer -->|"produces"| node_mlmresult
node_features -->|"supports task features"| node_attr
node_mlm -.->|"shares DOMLM backbone"| node_taskheads
node_taskheads -.->|"includes QA model"| node_qa

click node_clean "https://github.com/ilyalasy/dom-lm/blob/main/src/html_utils.py"
click node_features "https://github.com/ilyalasy/dom-lm/blob/main/src/preprocess.py"
click node_swdeprep "https://github.com/ilyalasy/dom-lm/blob/main/src/preprocess_swde.py"
click node_dataset "https://github.com/ilyalasy/dom-lm/blob/main/src/dataset.py"
click node_collator "https://github.com/ilyalasy/dom-lm/blob/main/src/data_collator.py"
click node_config "https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/configuration_domlm.py"
click node_embeddings "https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/modeling_domlm.py"
click node_encoder "https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/modeling_domlm.py"
click node_mlm "https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/modeling_domlm.py"
click node_taskheads "https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/modeling_domlm.py"
click node_trainer "https://github.com/ilyalasy/dom-lm/blob/main/src/train.py"
click node_attr "https://github.com/ilyalasy/dom-lm/blob/main/src/preprocess.py"
click node_qa "https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/modeling_domlm.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_clean,node_features,node_swdeprep toneBlue
class node_featurefiles,node_dataset,node_collator toneAmber
class node_config,node_embeddings,node_encoder,node_mlm,node_taskheads toneMint
class node_trainer,node_mlmresult,node_attr,node_qa toneRose
class node_engineer,node_swde toneIndigo
```

## Components

### DOM preprocessing

- [HTML cleanup](https://github.com/ilyalasy/dom-lm/blob/main/src/html_utils.py): `src/html_utils.py`
- [DOM features](https://github.com/ilyalasy/dom-lm/blob/main/src/preprocess.py): `src/preprocess.py`
- [SWDE preprocessing](https://github.com/ilyalasy/dom-lm/blob/main/src/preprocess_swde.py): `src/preprocess_swde.py`

### Training data

- **Feature files**
- [SWDE dataset](https://github.com/ilyalasy/dom-lm/blob/main/src/dataset.py): `src/dataset.py`
- [Node-mask collator](https://github.com/ilyalasy/dom-lm/blob/main/src/data_collator.py): `src/data_collator.py`

### DOM-LM model

- [Model configuration](https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/configuration_domlm.py): `src/domlm/configuration_domlm.py`
- [DOM embeddings](https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/modeling_domlm.py): `src/domlm/modeling_domlm.py`
- [Transformer encoder](https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/modeling_domlm.py): `src/domlm/modeling_domlm.py`
- [Masked-LM head](https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/modeling_domlm.py): `src/domlm/modeling_domlm.py`
- [Task heads](https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/modeling_domlm.py): `src/domlm/modeling_domlm.py`

### Training and tasks

- [Training orchestration](https://github.com/ilyalasy/dom-lm/blob/main/src/train.py): `src/train.py`
- **Trained MLM**
- [Attribute extraction](https://github.com/ilyalasy/dom-lm/blob/main/src/preprocess.py): `src/preprocess.py`
- [Question answering](https://github.com/ilyalasy/dom-lm/blob/main/src/domlm/modeling_domlm.py): `src/domlm/modeling_domlm.py`

### Other components

- **Researcher**
- **SWDE HTML**

## Connections

- Researcher → SWDE preprocessing: runs preprocessing (evidence: `README.md`)
- SWDE HTML → SWDE preprocessing: provides pages (evidence: `src/preprocess_swde.py`)
- SWDE preprocessing → DOM features: extracts features (evidence: `src/preprocess_swde.py`)
- DOM features → HTML cleanup: cleans HTML (evidence: `src/preprocess.py`)
- SWDE preprocessing → Feature files: writes features (evidence: `src/preprocess_swde.py`)
- Feature files → SWDE dataset: loads pickles (evidence: `src/dataset.py`)
- Researcher → Training orchestration: runs training (evidence: `README.md`)
- Training orchestration → SWDE dataset: uses samples (evidence: `src/train.py`)
- Training orchestration → Node-mask collator: configures batches (evidence: `src/train.py`)
- Training orchestration → Masked-LM head: trains model (evidence: `src/train.py`)
- Model configuration → DOM embeddings: configures (evidence: `src/domlm/modeling_domlm.py`)
- DOM embeddings → Transformer encoder: feeds representations (evidence: `src/domlm/modeling_domlm.py`)
- Transformer encoder → Masked-LM head: feeds hidden states (evidence: `src/domlm/modeling_domlm.py`)
- Training orchestration → Trained MLM: produces (evidence: `src/train.py`)
- DOM features → Attribute extraction: supports task features (evidence: `src/preprocess.py`)
- Masked-LM head → Task heads: shares DOMLM backbone (evidence: `src/domlm/modeling_domlm.py`)
- Task heads → Question answering: includes QA model (evidence: `src/domlm/modeling_domlm.py`)
