# niez233/hadsf architecture

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

- Interactive diagram: https://gitdiagram.com/niez233/hadsf
- Repository: https://github.com/niez233/hadsf

## Overview

#### Purpose and execution surface
HADSF implements a two-stage pipeline for explainable recommendation: derive a controlled, domain-specific aspect vocabulary, then extract history-aware aspect–opinion signals from reviews for recommendation modeling. The repository is script-oriented rather than a deployed service. Likely runnable entry points are `aspect_extract/example.py`, `aspect_extract/extract_aspect_raw.py`, `aspect_extract/extract_review.py`, `model/ANR/model_run.py`, and `model/tgnn/model_run.py`.

#### Stage I: controlled aspect vocabulary
Raw review text is processed into candidate aspects, then consolidated into the compact vocabulary A*. `aspect_extract/extract_aspect_raw.py` is the raw aspect-extraction stage; `aspect_extract/extract_review.py` appears to manage review-level extraction/processing. `aspect_extract/example.py` provides an example orchestration surface. This stage establishes the semantic control boundary consumed by later extraction and modeling.

#### Hallucination/semantic-quality evaluation
Two standalone evaluators quantify adherence to the controlled semantics:
- Aspect Drift Rate (ADR), implemented in `aspect_extract/ADR.py`, measures whether generated/extracted aspects deviate from A*.
- Opinion Fidelity Rate (OFR), implemented in `aspect_extract/OFR.py`, measures whether opinions remain semantically grounded in the source review.
These scripts form a quality boundary between extraction outputs and downstream recommendation inputs.

#### Stage II: dynamic review and preference processing
The second stage uses user–item interaction/review history to produce fine-grained aspect-aware representations and update preferences over time. The TGNN pipeline’s ingestion and graph-data preparation are centered in `model/tgnn/load_data.py` and `model/tgnn/rhg_data.py`. NLP preparation utilities reside in `model/tgnn/nlp_util.py`, while `model/tgnn/util.py` likely provides shared pipeline support.

#### Temporal/relational graph recommendation model
The principal dynamic model is implemented by relational history graph components: `model/tgnn/rhgc.py` and aspect-specific `model/tgnn/rhgc_aspect.py`. These consume prepared historical user/item/review/aspect signals and encode their evolving relationships. `model/tgnn/model_run.py` is the training/evaluation execution boundary for this model family.

#### Embedding semantic layer
BERT-based embedding normalization/whitening supports semantic comparison or model inputs: `model/tgnn/bert_whitening.py` handles general text embeddings, and `model/tgnn/bert_whitening_aspect.py` handles aspect-oriented embeddings. This is the likely bridge from text/aspect extraction to dense representations used by clustering, fidelity evaluation, or graph modeling.

#### Alternate recommendation baseline/model path
`model/ANR/model_run.py` supplies a separate ANR model execution path, likely for comparison or an alternative recommendation architecture. It is isolated from the TGNN directory, implying independently prepared inputs and runs rather than a shared end-to-end runtime.

#### Runtime and external dependencies
The project is Python-based. The only explicit dependency manifest is `model/tgnn/requirements.txt`; BERT references imply a pretrained language-model/embedding runtime, while the README points to a Google Drive-hosted processed dataset. No API server, database, scheduler, or cloud deployment infrastructure is represented in the tree.

Main entry points: [`aspect_extract/extract_review.py`](https://github.com/niez233/hadsf/blob/main/aspect_extract/extract_review.py) (Review processing), [`model/tgnn/rhg_data.py`](https://github.com/niez233/hadsf/blob/main/model/tgnn/rhg_data.py) (Relational history graph data), [`model/tgnn/nlp_util.py`](https://github.com/niez233/hadsf/blob/main/model/tgnn/nlp_util.py) (NLP preparation), [`model/tgnn/load_data.py`](https://github.com/niez233/hadsf/blob/main/model/tgnn/load_data.py) (TGNN data loading)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_aspect["Stage I · Aspect Extraction"]
  node_raw_reviews["Raw review text<br/>input data"]
  node_raw_aspects["Raw aspect extraction<br/>Python script"]
  node_review_extraction["Review processing<br/>Python script<br/>[extract_review.py]"]
  node_aspect_vocabulary["Controlled vocabulary A*<br/>semantic artifact"]
  node_aspect_example["Extraction example<br/>Python entry point<br/>[example.py]"]
end

subgraph group_quality["Semantic Quality"]
  node_adr["Aspect Drift Rate<br/>evaluation script<br/>[ADR.py]"]
  node_ofr["Opinion Fidelity Rate<br/>evaluation script<br/>[OFR.py]"]
end

subgraph group_tgnn["Stage II · TGNN"]
  node_processed_dataset[("Processed interaction data<br/>dataset")]
  node_tgnn_load["TGNN data loading<br/>Python module<br/>[load_data.py]"]
  node_tgnn_nlp["NLP preparation<br/>Python module<br/>[nlp_util.py]"]
  node_text_embeddings["Text embeddings<br/>embedding layer<br/>[bert_whitening.py]"]
  node_aspect_embeddings["Aspect embeddings<br/>embedding layer"]
  node_history_graph_data["Relational history graph data<br/>graph-data preparation<br/>[rhg_data.py]"]
  node_rhgc["Relational history encoder<br/>TGNN component<br/>[rhgc.py]"]
  node_rhgc_aspect["Aspect history encoder<br/>TGNN component<br/>[rhgc_aspect.py]"]
  node_tgnn_run["TGNN train and evaluate<br/>Python entry point<br/>[model_run.py]"]
  node_tgnn_requirements["TGNN dependencies<br/>Python requirements<br/>[requirements.txt]"]
end

subgraph group_anr["Alternate Model"]
  node_anr_run["ANR train and evaluate<br/>Python entry point<br/>[model_run.py]"]
end

node_raw_reviews -->|"extract candidates"| node_raw_aspects
node_raw_aspects -->|"consolidate"| node_aspect_vocabulary
node_raw_reviews -->|"process reviews"| node_review_extraction
node_aspect_vocabulary -->|"constrain aspects"| node_review_extraction
node_aspect_example -.->|"orchestrates"| node_raw_aspects
node_aspect_example -.->|"orchestrates"| node_review_extraction
node_aspect_vocabulary -->|"reference vocabulary"| node_adr
node_review_extraction -->|"evaluate aspects"| node_adr
node_raw_reviews -->|"source reviews"| node_ofr
node_review_extraction -->|"evaluate opinions"| node_ofr
node_processed_dataset -->|"load histories"| node_tgnn_load
node_review_extraction -->|"aspect–opinion signals"| node_tgnn_nlp
node_tgnn_load -->|"review text"| node_tgnn_nlp
node_tgnn_nlp -->|"embed text"| node_text_embeddings
node_tgnn_nlp -->|"embed aspects"| node_aspect_embeddings
node_tgnn_load -->|"interaction history"| node_history_graph_data
node_text_embeddings -->|"text features"| node_history_graph_data
node_aspect_embeddings -->|"aspect features"| node_history_graph_data
node_history_graph_data -->|"temporal relations"| node_rhgc
node_history_graph_data -->|"aspect relations"| node_rhgc_aspect
node_rhgc -->|"user/item representations"| node_tgnn_run
node_rhgc_aspect -->|"aspect representations"| node_tgnn_run
node_tgnn_requirements -.->|"runtime dependencies"| node_tgnn_run
node_processed_dataset -.->|"independent inputs"| node_anr_run

click node_raw_aspects "https://github.com/niez233/hadsf/blob/main/aspect_extract/extract_aspect_raw.py"
click node_review_extraction "https://github.com/niez233/hadsf/blob/main/aspect_extract/extract_review.py"
click node_aspect_example "https://github.com/niez233/hadsf/blob/main/aspect_extract/example.py"
click node_adr "https://github.com/niez233/hadsf/blob/main/aspect_extract/ADR.py"
click node_ofr "https://github.com/niez233/hadsf/blob/main/aspect_extract/OFR.py"
click node_tgnn_load "https://github.com/niez233/hadsf/blob/main/model/tgnn/load_data.py"
click node_tgnn_nlp "https://github.com/niez233/hadsf/blob/main/model/tgnn/nlp_util.py"
click node_text_embeddings "https://github.com/niez233/hadsf/blob/main/model/tgnn/bert_whitening.py"
click node_aspect_embeddings "https://github.com/niez233/hadsf/blob/main/model/tgnn/bert_whitening_aspect.py"
click node_history_graph_data "https://github.com/niez233/hadsf/blob/main/model/tgnn/rhg_data.py"
click node_rhgc "https://github.com/niez233/hadsf/blob/main/model/tgnn/rhgc.py"
click node_rhgc_aspect "https://github.com/niez233/hadsf/blob/main/model/tgnn/rhgc_aspect.py"
click node_tgnn_run "https://github.com/niez233/hadsf/blob/main/model/tgnn/model_run.py"
click node_tgnn_requirements "https://github.com/niez233/hadsf/blob/main/model/tgnn/requirements.txt"
click node_anr_run "https://github.com/niez233/hadsf/blob/main/model/ANR/model_run.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_raw_reviews,node_raw_aspects,node_review_extraction,node_aspect_vocabulary,node_aspect_example toneBlue
class node_adr,node_ofr toneAmber
class node_processed_dataset,node_tgnn_load,node_tgnn_nlp,node_text_embeddings,node_aspect_embeddings,node_history_graph_data,node_rhgc,node_rhgc_aspect,node_tgnn_run,node_tgnn_requirements toneMint
class node_anr_run toneRose
```

## Components

### Stage I · Aspect Extraction

Builds the controlled aspect vocabulary and review signals.

- **Raw review text**: input data
- [Raw aspect extraction](https://github.com/niez233/hadsf/blob/main/aspect_extract/extract_aspect_raw.py): Python script · `aspect_extract/extract_aspect_raw.py`
- [Review processing](https://github.com/niez233/hadsf/blob/main/aspect_extract/extract_review.py): Python script · Produces review-level aspect–opinion signals. · `aspect_extract/extract_review.py`
- **Controlled vocabulary A***: semantic artifact · Compact domain-specific aspect vocabulary.
- [Extraction example](https://github.com/niez233/hadsf/blob/main/aspect_extract/example.py): Python entry point · Example orchestration for Stage I. · `aspect_extract/example.py`

### Semantic Quality

Standalone checks for extraction quality.

- [Aspect Drift Rate](https://github.com/niez233/hadsf/blob/main/aspect_extract/ADR.py): evaluation script · Measures aspect deviation from A*. · `aspect_extract/ADR.py`
- [Opinion Fidelity Rate](https://github.com/niez233/hadsf/blob/main/aspect_extract/OFR.py): evaluation script · Checks whether opinions are grounded in reviews. · `aspect_extract/OFR.py`

### Stage II · TGNN

Prepares temporal review histories and trains the graph recommender.

- **Processed interaction data**: dataset · External processed dataset with user–item review history.
- [TGNN data loading](https://github.com/niez233/hadsf/blob/main/model/tgnn/load_data.py): Python module · `model/tgnn/load_data.py`
- [NLP preparation](https://github.com/niez233/hadsf/blob/main/model/tgnn/nlp_util.py): Python module · `model/tgnn/nlp_util.py`
- [Text embeddings](https://github.com/niez233/hadsf/blob/main/model/tgnn/bert_whitening.py): embedding layer · BERT-normalized semantic representations. · `model/tgnn/bert_whitening.py`
- [Aspect embeddings](https://github.com/niez233/hadsf/blob/main/model/tgnn/bert_whitening_aspect.py): embedding layer · BERT-normalized aspect representations. · `model/tgnn/bert_whitening_aspect.py`
- [Relational history graph data](https://github.com/niez233/hadsf/blob/main/model/tgnn/rhg_data.py): graph-data preparation · Builds temporal user, item, review, and aspect relations. · `model/tgnn/rhg_data.py`
- [Relational history encoder](https://github.com/niez233/hadsf/blob/main/model/tgnn/rhgc.py): TGNN component · Encodes evolving user–item–review relationships. · `model/tgnn/rhgc.py`
- [Aspect history encoder](https://github.com/niez233/hadsf/blob/main/model/tgnn/rhgc_aspect.py): TGNN component · Encodes aspect-specific relational histories. · `model/tgnn/rhgc_aspect.py`
- [TGNN train and evaluate](https://github.com/niez233/hadsf/blob/main/model/tgnn/model_run.py): Python entry point · `model/tgnn/model_run.py`
- [TGNN dependencies](https://github.com/niez233/hadsf/blob/main/model/tgnn/requirements.txt): Python requirements · `model/tgnn/requirements.txt`

### Alternate Model

- [ANR train and evaluate](https://github.com/niez233/hadsf/blob/main/model/ANR/model_run.py): Python entry point · Independent alternate recommendation path. · `model/ANR/model_run.py`

## Connections

- Raw review text → Raw aspect extraction: extract candidates
- Raw aspect extraction → Controlled vocabulary A*: consolidate
- Raw review text → Review processing: process reviews
- Controlled vocabulary A* → Review processing: constrain aspects
- Extraction example → Raw aspect extraction: orchestrates
- Extraction example → Review processing: orchestrates
- Controlled vocabulary A* → Aspect Drift Rate: reference vocabulary
- Review processing → Aspect Drift Rate: evaluate aspects
- Raw review text → Opinion Fidelity Rate: source reviews
- Review processing → Opinion Fidelity Rate: evaluate opinions
- Processed interaction data → TGNN data loading: load histories
- Review processing → NLP preparation: aspect–opinion signals
- TGNN data loading → NLP preparation: review text
- NLP preparation → Text embeddings: embed text
- NLP preparation → Aspect embeddings: embed aspects
- TGNN data loading → Relational history graph data: interaction history
- Text embeddings → Relational history graph data: text features
- Aspect embeddings → Relational history graph data: aspect features
- Relational history graph data → Relational history encoder: temporal relations
- Relational history graph data → Aspect history encoder: aspect relations
- Relational history encoder → TGNN train and evaluate: user/item representations
- Aspect history encoder → TGNN train and evaluate: aspect representations
- TGNN dependencies → TGNN train and evaluate: runtime dependencies
- Processed interaction data → ANR train and evaluate: independent inputs
