# invincibleagam/amazon-ml-challenge architecture

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

- Interactive diagram: https://gitdiagram.com/invincibleagam/amazon-ml-challenge
- Repository: https://github.com/invincibleagam/amazon-ml-challenge

## Overview

This repository implements a business-record entity-resolution pipeline: it finds Source 2 and Source 3 records matching each Source 1 business, prioritizing precision under macro F0.5. The documented workflow normalizes records, retrieves candidates, prunes them, then refines pair scores through similarity, difference, and collective-context models before decoding matches. Shared feature and model helpers support the stages; optional text-model scores can enrich Stage 4. The graph follows documented stages and visible imports; unsampled implementation details are not inferred beyond those relationships.

Main entry points: [`code/business_entity_resolution/src/preprocess.py`](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/preprocess.py) (Normalize records), [`code/business_entity_resolution/src/stage1.py`](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage1.py) (Stage 1 pruning), [`code/business_entity_resolution/src/stage2.py`](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage2.py) (Stage 2 matching), [`code/business_entity_resolution/src/stage3.py`](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage3.py) (Stage 3 corrections)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Input preparation"]
  node_preprocessing["Normalize records<br/>[preprocess.py]"]
  node_normalizer["Text normalization<br/>[normalize.py]"]
  node_transliteration["Indic transliteration<br/>[translit.py]"]
  node_shared_io["Shared data access<br/>[common.py]"]
end

subgraph group_matching["Candidate matching"]
  node_blocking["Candidate blocking<br/>[blocking.py]"]
  node_stage1["Stage 1 pruning<br/>[stage1.py]"]
  node_features["Pair features<br/>[features.py]"]
  node_models["Boosted models<br/>[models.py]"]
end

subgraph group_refinement["Score refinement"]
  node_stage2["Stage 2 matching<br/>[stage2.py]"]
  node_stage3["Stage 3 corrections<br/>[stage3.py]"]
  node_swap_rules["Word-swap analysis<br/>[swap.py]"]
  node_stage4["Stage 4 context<br/>[stage4.py]"]
  node_text_model["Text-model scores<br/>[text_model.py]"]
end

subgraph group_results["Decision and output"]
  node_decision["Match decoding<br/>[stage2.py]"]
  node_submission["Submission output<br/>[make_submission.py]"]
  node_metric["Macro F0.5<br/>[evaluate.py]"]
end

node_challenge_data[("Challenge records")]

node_challenge_data -->|"reads records"| node_preprocessing
node_preprocessing -->|"normalizes with"| node_normalizer
node_preprocessing -->|"transliterates with"| node_transliteration
node_preprocessing -->|"reads through"| node_shared_io
node_preprocessing -->|"provides normalized records"| node_blocking
node_blocking -->|"generates candidates for"| node_stage1
node_stage1 -->|"builds pruning features"| node_features
node_stage1 -->|"fits and scores with"| node_models
node_stage1 -->|"passes pruned pairs"| node_stage2
node_stage2 -->|"builds pair features"| node_features
node_stage2 -->|"fits and scores with"| node_models
node_stage2 -->|"passes pair scores"| node_stage3
node_stage3 -->|"describes word differences"| node_swap_rules
node_stage3 -->|"passes uncertain pairs"| node_stage4
node_stage4 -.->|"uses optional scores"| node_text_model
node_stage4 -->|"refines candidate scores"| node_decision
node_decision -->|"tunes against"| node_metric
node_decision -->|"writes matches for"| node_submission

click node_preprocessing "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/preprocess.py"
click node_normalizer "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/normalize.py"
click node_transliteration "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/translit.py"
click node_shared_io "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/common.py"
click node_blocking "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/blocking.py"
click node_stage1 "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage1.py"
click node_features "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/features.py"
click node_models "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/models.py"
click node_stage2 "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage2.py"
click node_stage3 "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage3.py"
click node_swap_rules "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/swap.py"
click node_stage4 "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage4.py"
click node_text_model "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/text_model.py"
click node_decision "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage2.py"
click node_submission "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/make_submission.py"
click node_metric "https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/evaluate.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_preprocessing,node_normalizer,node_transliteration,node_shared_io toneBlue
class node_blocking,node_stage1,node_features,node_models,node_challenge_data toneAmber
class node_stage2,node_stage3,node_swap_rules,node_stage4,node_text_model toneMint
class node_decision,node_submission,node_metric toneRose
```

## Components

### Input preparation

- [Normalize records](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/preprocess.py): `code/business_entity_resolution/src/preprocess.py`
- [Text normalization](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/normalize.py): `code/business_entity_resolution/src/normalize.py`
- [Indic transliteration](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/translit.py): `code/business_entity_resolution/src/translit.py`
- [Shared data access](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/common.py): `code/business_entity_resolution/src/common.py`

### Candidate matching

- [Candidate blocking](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/blocking.py): `code/business_entity_resolution/src/blocking.py`
- [Stage 1 pruning](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage1.py): `code/business_entity_resolution/src/stage1.py`
- [Pair features](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/features.py): `code/business_entity_resolution/src/features.py`
- [Boosted models](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/models.py): `code/business_entity_resolution/src/models.py`

### Score refinement

- [Stage 2 matching](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage2.py): `code/business_entity_resolution/src/stage2.py`
- [Stage 3 corrections](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage3.py): `code/business_entity_resolution/src/stage3.py`
- [Word-swap analysis](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/swap.py): `code/business_entity_resolution/src/swap.py`
- [Stage 4 context](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage4.py): `code/business_entity_resolution/src/stage4.py`
- [Text-model scores](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/text_model.py): `code/business_entity_resolution/src/text_model.py`

### Decision and output

- [Match decoding](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/stage2.py): `code/business_entity_resolution/src/stage2.py`
- [Submission output](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/make_submission.py): `code/business_entity_resolution/src/make_submission.py`
- [Macro F0.5](https://github.com/invincibleagam/amazon-ml-challenge/blob/main/code/business_entity_resolution/src/evaluate.py): `code/business_entity_resolution/src/evaluate.py`

### Other components

- **Challenge records**

## Connections

- Challenge records → Normalize records: reads records (evidence: `README.md`)
- Normalize records → Text normalization: normalizes with (evidence: `code/business_entity_resolution/src/preprocess.py`)
- Normalize records → Indic transliteration: transliterates with (evidence: `code/business_entity_resolution/src/preprocess.py`)
- Normalize records → Shared data access: reads through (evidence: `code/business_entity_resolution/src/preprocess.py`)
- Normalize records → Candidate blocking: provides normalized records (evidence: `README.md`)
- Candidate blocking → Stage 1 pruning: generates candidates for (evidence: `README.md`)
- Stage 1 pruning → Pair features: builds pruning features (evidence: `code/business_entity_resolution/src/stage1.py`)
- Stage 1 pruning → Boosted models: fits and scores with (evidence: `code/business_entity_resolution/src/stage1.py`)
- Stage 1 pruning → Stage 2 matching: passes pruned pairs (evidence: `README.md`)
- Stage 2 matching → Pair features: builds pair features (evidence: `code/business_entity_resolution/src/stage2.py`)
- Stage 2 matching → Boosted models: fits and scores with (evidence: `code/business_entity_resolution/src/stage2.py`)
- Stage 2 matching → Stage 3 corrections: passes pair scores (evidence: `README.md`)
- Stage 3 corrections → Word-swap analysis: describes word differences (evidence: `code/business_entity_resolution/src/stage3.py`)
- Stage 3 corrections → Stage 4 context: passes uncertain pairs (evidence: `README.md`)
- Stage 4 context → Text-model scores: uses optional scores (evidence: `code/business_entity_resolution/src/stage4.py`)
- Stage 4 context → Match decoding: refines candidate scores (evidence: `README.md`)
- Match decoding → Macro F0.5: tunes against (evidence: `code/business_entity_resolution/src/stage2.py`)
- Match decoding → Submission output: writes matches for (evidence: `README.md`)
