# devigenix/rxhate architecture

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

- Interactive diagram: https://gitdiagram.com/devigenix/rxhate
- Repository: https://github.com/devigenix/rxhate

## Overview

RX-Hate is a research toolkit for explainable, reward-optimised multimodal hate-speech detection. Its main workflow takes a post’s text, image and context, builds features, predicts a label and rationale, then evaluates classification, fairness and explanation quality. A second documented path trains and evaluates an instruction-tuned LLM with shared rewards. The README describes data loaders and synthetic-data generation at paths absent from the supplied tree, so those implementations are not represented; relationships shown for broader workflows rely on README statements.

Main entry points: [`rxhate/features.py`](https://github.com/devigenix/rxhate/blob/main/rxhate/features.py) (Multimodal features), [`rxhate/model.py`](https://github.com/devigenix/rxhate/blob/main/rxhate/model.py) (Fusion policy), [`llm/data.py`](https://github.com/devigenix/rxhate/blob/main/llm/data.py) (LLM data adapter), [`rxhate/grpo.py`](https://github.com/devigenix/rxhate/blob/main/rxhate/grpo.py) (GRPO trainer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Input features"]
  node_realdata["Real-data preparation"]
  node_text["Text normalization<br/>[text.py]"]
  node_image["Image features<br/>[vision.py]"]
  node_features["Multimodal features<br/>[features.py]"]
end

subgraph group_policy["Detection and training"]
  node_baselines["Baseline models<br/>[baselines.py]"]
  node_model["Fusion policy<br/>[model.py]"]
  node_rewards["Shared rewards<br/>[rewards.py]"]
  node_grpo["GRPO trainer<br/>[grpo.py]"]
  node_experiment["Experiment workflow<br/>[run_experiments.py]"]
end

subgraph group_explain["Explanations and evaluation"]
  node_xai["XAI explainers<br/>[xai.py]"]
  node_metrics["Quality metrics<br/>[metrics.py]"]
  node_evaluation["Policy evaluation<br/>[evaluate.py]"]
end

subgraph group_llm["LLM pathway"]
  node_llmdata["LLM data adapter<br/>[data.py]"]
  node_prompts["Moderation prompts<br/>[prompts.py]"]
  node_llmrewards["TRL reward wrappers<br/>[reward_funcs.py]"]
  node_llmsft["LLM SFT training<br/>[train_sft.py]"]
  node_llmgrpo["LLM GRPO training<br/>[train_grpo.py]"]
  node_llmeval["LLM evaluation<br/>[evaluate.py]"]
end

node_user(("Post submitter"))

node_user -->|"provides post"| node_features
node_realdata -.->|"prepares records"| node_features
node_text -->|"featurizes text"| node_features
node_image -->|"extracts descriptors"| node_features
node_features -->|"builds inputs"| node_model
node_model -->|"explains predictions"| node_xai
node_features -->|"provides tokens"| node_xai
node_model -->|"optimizes policy"| node_grpo
node_grpo -->|"scores actions"| node_rewards
node_grpo -->|"updates policy"| node_model
node_experiment -->|"runs comparisons"| node_baselines
node_experiment -->|"runs training"| node_grpo
node_experiment -->|"compares explainers"| node_xai
node_evaluation -->|"computes measures"| node_metrics
node_evaluation -->|"evaluates policy"| node_model
node_llmdata -->|"builds messages"| node_prompts
node_llmdata -->|"checks identity"| node_features
node_llmsft -->|"loads training data"| node_llmdata
node_llmgrpo -->|"loads training data"| node_llmdata
node_llmgrpo -->|"uses reward wrappers"| node_llmrewards
node_llmrewards -->|"wraps shared rewards"| node_rewards
node_llmeval -->|"loads evaluation data"| node_llmdata
node_llmeval -->|"reports metrics"| node_metrics

click node_realdata "https://github.com/devigenix/rxhate/blob/main/scripts/prepare_real_data.py"
click node_text "https://github.com/devigenix/rxhate/blob/main/rxhate/text.py"
click node_image "https://github.com/devigenix/rxhate/blob/main/rxhate/vision.py"
click node_features "https://github.com/devigenix/rxhate/blob/main/rxhate/features.py"
click node_baselines "https://github.com/devigenix/rxhate/blob/main/rxhate/baselines.py"
click node_model "https://github.com/devigenix/rxhate/blob/main/rxhate/model.py"
click node_rewards "https://github.com/devigenix/rxhate/blob/main/rxhate/rewards.py"
click node_grpo "https://github.com/devigenix/rxhate/blob/main/rxhate/grpo.py"
click node_experiment "https://github.com/devigenix/rxhate/blob/main/scripts/run_experiments.py"
click node_xai "https://github.com/devigenix/rxhate/blob/main/rxhate/xai.py"
click node_metrics "https://github.com/devigenix/rxhate/blob/main/rxhate/metrics.py"
click node_evaluation "https://github.com/devigenix/rxhate/blob/main/rxhate/evaluate.py"
click node_llmdata "https://github.com/devigenix/rxhate/blob/main/llm/data.py"
click node_prompts "https://github.com/devigenix/rxhate/blob/main/llm/prompts.py"
click node_llmrewards "https://github.com/devigenix/rxhate/blob/main/llm/reward_funcs.py"
click node_llmsft "https://github.com/devigenix/rxhate/blob/main/llm/train_sft.py"
click node_llmgrpo "https://github.com/devigenix/rxhate/blob/main/llm/train_grpo.py"
click node_llmeval "https://github.com/devigenix/rxhate/blob/main/llm/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_realdata,node_text,node_image,node_features toneBlue
class node_baselines,node_model,node_rewards,node_grpo,node_experiment toneAmber
class node_xai,node_metrics,node_evaluation toneMint
class node_llmdata,node_prompts,node_llmrewards,node_llmsft,node_llmgrpo,node_llmeval toneRose
class node_user toneIndigo
```

## Components

### Input features

- [Real-data preparation](https://github.com/devigenix/rxhate/blob/main/scripts/prepare_real_data.py): `scripts/prepare_real_data.py`
- [Text normalization](https://github.com/devigenix/rxhate/blob/main/rxhate/text.py): `rxhate/text.py`
- [Image features](https://github.com/devigenix/rxhate/blob/main/rxhate/vision.py): `rxhate/vision.py`
- [Multimodal features](https://github.com/devigenix/rxhate/blob/main/rxhate/features.py): `rxhate/features.py`

### Detection and training

- [Baseline models](https://github.com/devigenix/rxhate/blob/main/rxhate/baselines.py): `rxhate/baselines.py`
- [Fusion policy](https://github.com/devigenix/rxhate/blob/main/rxhate/model.py): `rxhate/model.py`
- [Shared rewards](https://github.com/devigenix/rxhate/blob/main/rxhate/rewards.py): `rxhate/rewards.py`
- [GRPO trainer](https://github.com/devigenix/rxhate/blob/main/rxhate/grpo.py): `rxhate/grpo.py`
- [Experiment workflow](https://github.com/devigenix/rxhate/blob/main/scripts/run_experiments.py): `scripts/run_experiments.py`

### Explanations and evaluation

- [XAI explainers](https://github.com/devigenix/rxhate/blob/main/rxhate/xai.py): `rxhate/xai.py`
- [Quality metrics](https://github.com/devigenix/rxhate/blob/main/rxhate/metrics.py): `rxhate/metrics.py`
- [Policy evaluation](https://github.com/devigenix/rxhate/blob/main/rxhate/evaluate.py): `rxhate/evaluate.py`

### LLM pathway

- [LLM data adapter](https://github.com/devigenix/rxhate/blob/main/llm/data.py): `llm/data.py`
- [Moderation prompts](https://github.com/devigenix/rxhate/blob/main/llm/prompts.py): `llm/prompts.py`
- [TRL reward wrappers](https://github.com/devigenix/rxhate/blob/main/llm/reward_funcs.py): `llm/reward_funcs.py`
- [LLM SFT training](https://github.com/devigenix/rxhate/blob/main/llm/train_sft.py): `llm/train_sft.py`
- [LLM GRPO training](https://github.com/devigenix/rxhate/blob/main/llm/train_grpo.py): `llm/train_grpo.py`
- [LLM evaluation](https://github.com/devigenix/rxhate/blob/main/llm/evaluate.py): `llm/evaluate.py`

### Other components

- **Post submitter**

## Connections

- Post submitter → Multimodal features: provides post (evidence: `README.md`)
- Real-data preparation → Multimodal features: prepares records (evidence: `README.md`)
- Text normalization → Multimodal features: featurizes text (evidence: `rxhate/features.py`)
- Image features → Multimodal features: extracts descriptors (evidence: `rxhate/features.py`)
- Multimodal features → Fusion policy: builds inputs (evidence: `README.md`)
- Fusion policy → XAI explainers: explains predictions (evidence: `rxhate/xai.py`)
- Multimodal features → XAI explainers: provides tokens (evidence: `rxhate/xai.py`)
- Fusion policy → GRPO trainer: optimizes policy (evidence: `rxhate/grpo.py`)
- GRPO trainer → Shared rewards: scores actions (evidence: `rxhate/grpo.py`)
- GRPO trainer → Fusion policy: updates policy (evidence: `rxhate/grpo.py`)
- Experiment workflow → Baseline models: runs comparisons (evidence: `README.md`)
- Experiment workflow → GRPO trainer: runs training (evidence: `README.md`)
- Experiment workflow → XAI explainers: compares explainers (evidence: `README.md`)
- Policy evaluation → Quality metrics: computes measures (evidence: `rxhate/evaluate.py`)
- Policy evaluation → Fusion policy: evaluates policy (evidence: `rxhate/evaluate.py`)
- LLM data adapter → Moderation prompts: builds messages (evidence: `llm/data.py`)
- LLM data adapter → Multimodal features: checks identity (evidence: `llm/data.py`)
- LLM SFT training → LLM data adapter: loads training data (evidence: `README.md`)
- LLM GRPO training → LLM data adapter: loads training data (evidence: `README.md`)
- LLM GRPO training → TRL reward wrappers: uses reward wrappers (evidence: `README.md`)
- TRL reward wrappers → Shared rewards: wraps shared rewards (evidence: `llm/reward_funcs.py`)
- LLM evaluation → LLM data adapter: loads evaluation data (evidence: `README.md`)
- LLM evaluation → Quality metrics: reports metrics (evidence: `README.md`)
