# hhansi/embed2detect architecture

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

- Interactive diagram: https://gitdiagram.com/hhansi/embed2detect
- Repository: https://github.com/hhansi/embed2detect

## Overview

Embed2Detect is a Python social-media event-detection system. Its primary workflow accepts timestamped TSV posts, preprocesses and time-filters them, learns per-window word embeddings, identifies event windows, and writes event words. The repository also contains event-evaluation tools and a separate BERT language-modeling experiment. The pipeline links are supported by the README and the main module’s imports/calls; evaluation and BERT links rely on SOURCE INDEX references. Unsampled implementations are represented only where the tree or index supports them.

Main entry points: [`embed2detect/main.py`](https://github.com/hhansi/embed2detect/blob/master/embed2detect/main.py) (Detection entry), [`algo/cluster_change_calculation.py`](https://github.com/hhansi/embed2detect/blob/master/algo/cluster_change_calculation.py) (Cluster change), [`embed2detect/word_embedding_learner.py`](https://github.com/hhansi/embed2detect/blob/master/embed2detect/word_embedding_learner.py) (Embedding learner), [`embed2detect/event_window_identifier.py`](https://github.com/hhansi/embed2detect/blob/master/embed2detect/event_window_identifier.py) (Window identification)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["Detection pipeline"]
  node_main["Detection entry<br/>[main.py]"]
  node_preprocess["Text preprocessing"]
  node_chunker["Time chunking<br/>[stream_chunker.py]"]
  node_stats["Data statistics<br/>[stat_generator.py]"]
  node_learner["Embedding learner"]
  node_word2vec["Word2Vec training<br/>[word2vec.py]"]
  node_fasttext["FastText training<br/>[fasttext.py]"]
end

subgraph group_analysis["Event analysis"]
  node_window_id["Window identification"]
  node_cluster_change["Cluster change"]
  node_dendrogram["Dendrogram similarity"]
  node_matrix["Similarity matrices"]
  node_vocabulary["Vocabulary calculation"]
  node_vocab_change["Vocabulary change"]
  node_extractor["Event word extraction"]
end

subgraph group_shared["Shared utilities"]
  node_file_utils["File utilities<br/>[file_utils.py]"]
  node_embedding_utils["Embedding utilities"]
end

subgraph group_evaluation["Evaluation"]
  node_groundtruth["Ground-truth processing"]
  node_evaluate["Evaluation runner<br/>[evaluate.py]"]
  node_keyword_eval["Keyword evaluation"]
  node_topic_eval["Topic evaluation<br/>[topic_evaluate.py]"]
end

subgraph group_bert["BERT experiments"]
  node_finetuning["Fine-tuning experiment"]
  node_lm_model["Language model"]
  node_lm_utils["Language-model utilities"]
  node_lm_models["Model definitions<br/>[models.py]"]
  node_model_args["Model arguments<br/>[model_args.py]"]
end

node_user(("Data operator"))
node_results["Event word files"]

node_user -->|"runs with data"| node_main
node_main -->|"preprocesses"| node_preprocess
node_main -->|"time-filters"| node_chunker
node_main -->|"generates stats"| node_stats
node_main -->|"learns embeddings"| node_learner
node_main -->|"identifies windows"| node_window_id
node_main -->|"extracts words"| node_extractor
node_main -->|"gets filename"| node_file_utils
node_learner -->|"trains when configured"| node_word2vec
node_learner -->|"trains when configured"| node_fasttext
node_learner -->|"formats training data"| node_embedding_utils
node_window_id -->|"calculates changes"| node_cluster_change
node_window_id -->|"uses vocabulary"| node_vocabulary
node_window_id -->|"calculates vocabulary change"| node_vocab_change
node_cluster_change -->|"uses similarity"| node_dendrogram
node_cluster_change -->|"calculates matrix differences"| node_matrix
node_cluster_change -->|"saves vocabulary"| node_vocabulary
node_cluster_change -->|"gets embeddings"| node_embedding_utils
node_extractor -->|"uses matrix helpers"| node_matrix
node_main -->|"writes event files"| node_results
node_evaluate -->|"loads labels"| node_groundtruth
node_evaluate -->|"evaluates keywords"| node_keyword_eval
node_evaluate -->|"evaluates topics"| node_topic_eval
node_finetuning -->|"runs model"| node_lm_model
node_lm_model -->|"uses arguments"| node_model_args
node_lm_model -->|"uses utilities"| node_lm_utils
node_lm_model -->|"uses model definitions"| node_lm_models

click node_main "https://github.com/hhansi/embed2detect/blob/master/embed2detect/main.py"
click node_preprocess "https://github.com/hhansi/embed2detect/blob/master/data_analysis/data_preprocessor.py"
click node_chunker "https://github.com/hhansi/embed2detect/blob/master/embed2detect/stream_chunker.py"
click node_stats "https://github.com/hhansi/embed2detect/blob/master/data_analysis/stat_generator.py"
click node_learner "https://github.com/hhansi/embed2detect/blob/master/embed2detect/word_embedding_learner.py"
click node_word2vec "https://github.com/hhansi/embed2detect/blob/master/algo/word2vec.py"
click node_fasttext "https://github.com/hhansi/embed2detect/blob/master/algo/fasttext.py"
click node_window_id "https://github.com/hhansi/embed2detect/blob/master/embed2detect/event_window_identifier.py"
click node_cluster_change "https://github.com/hhansi/embed2detect/blob/master/algo/cluster_change_calculation.py"
click node_dendrogram "https://github.com/hhansi/embed2detect/blob/master/algo/utils/dendrogram_level_calculation.py"
click node_matrix "https://github.com/hhansi/embed2detect/blob/master/algo/utils/matrix_calculation.py"
click node_vocabulary "https://github.com/hhansi/embed2detect/blob/master/algo/utils/vocabulary_calculation.py"
click node_vocab_change "https://github.com/hhansi/embed2detect/blob/master/algo/vocabulary_change_calculation.py"
click node_extractor "https://github.com/hhansi/embed2detect/blob/master/embed2detect/event_word_extractor.py"
click node_groundtruth "https://github.com/hhansi/embed2detect/blob/master/data_analysis/groundtruth_processor.py"
click node_evaluate "https://github.com/hhansi/embed2detect/blob/master/experiments/twitter_event_data_2019/evaluation/evaluate.py"
click node_keyword_eval "https://github.com/hhansi/embed2detect/blob/master/experiments/twitter_event_data_2019/evaluation/keyword_evaluate.py"
click node_topic_eval "https://github.com/hhansi/embed2detect/blob/master/experiments/twitter_event_data_2019/evaluation/topic_evaluate.py"
click node_file_utils "https://github.com/hhansi/embed2detect/blob/master/utils/file_utils.py"
click node_embedding_utils "https://github.com/hhansi/embed2detect/blob/master/utils/word_embedding_util.py"
click node_finetuning "https://github.com/hhansi/embed2detect/blob/master/bert_experiments/language_finetuning_experiment.py"
click node_lm_model "https://github.com/hhansi/embed2detect/blob/master/bert_experiments/transformers/language_modeling/language_modeling_model.py"
click node_lm_utils "https://github.com/hhansi/embed2detect/blob/master/bert_experiments/transformers/language_modeling/language_modeling_utils.py"
click node_lm_models "https://github.com/hhansi/embed2detect/blob/master/bert_experiments/transformers/language_modeling/models.py"
click node_model_args "https://github.com/hhansi/embed2detect/blob/master/bert_experiments/transformers/args/model_args.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_main,node_preprocess,node_chunker,node_stats,node_learner,node_word2vec,node_fasttext toneBlue
class node_window_id,node_cluster_change,node_dendrogram,node_matrix,node_vocabulary,node_vocab_change,node_extractor toneAmber
class node_file_utils,node_embedding_utils toneMint
class node_groundtruth,node_evaluate,node_keyword_eval,node_topic_eval toneRose
class node_finetuning,node_lm_model,node_lm_utils,node_lm_models,node_model_args,node_user,node_results toneIndigo
```

## Components

### Detection pipeline

- [Detection entry](https://github.com/hhansi/embed2detect/blob/master/embed2detect/main.py): `embed2detect/main.py`
- [Text preprocessing](https://github.com/hhansi/embed2detect/blob/master/data_analysis/data_preprocessor.py): `data_analysis/data_preprocessor.py`
- [Time chunking](https://github.com/hhansi/embed2detect/blob/master/embed2detect/stream_chunker.py): `embed2detect/stream_chunker.py`
- [Data statistics](https://github.com/hhansi/embed2detect/blob/master/data_analysis/stat_generator.py): `data_analysis/stat_generator.py`
- [Embedding learner](https://github.com/hhansi/embed2detect/blob/master/embed2detect/word_embedding_learner.py): `embed2detect/word_embedding_learner.py`
- [Word2Vec training](https://github.com/hhansi/embed2detect/blob/master/algo/word2vec.py): `algo/word2vec.py`
- [FastText training](https://github.com/hhansi/embed2detect/blob/master/algo/fasttext.py): `algo/fasttext.py`

### Event analysis

- [Window identification](https://github.com/hhansi/embed2detect/blob/master/embed2detect/event_window_identifier.py): `embed2detect/event_window_identifier.py`
- [Cluster change](https://github.com/hhansi/embed2detect/blob/master/algo/cluster_change_calculation.py): `algo/cluster_change_calculation.py`
- [Dendrogram similarity](https://github.com/hhansi/embed2detect/blob/master/algo/utils/dendrogram_level_calculation.py): `algo/utils/dendrogram_level_calculation.py`
- [Similarity matrices](https://github.com/hhansi/embed2detect/blob/master/algo/utils/matrix_calculation.py): `algo/utils/matrix_calculation.py`
- [Vocabulary calculation](https://github.com/hhansi/embed2detect/blob/master/algo/utils/vocabulary_calculation.py): `algo/utils/vocabulary_calculation.py`
- [Vocabulary change](https://github.com/hhansi/embed2detect/blob/master/algo/vocabulary_change_calculation.py): `algo/vocabulary_change_calculation.py`
- [Event word extraction](https://github.com/hhansi/embed2detect/blob/master/embed2detect/event_word_extractor.py): `embed2detect/event_word_extractor.py`

### Shared utilities

- [File utilities](https://github.com/hhansi/embed2detect/blob/master/utils/file_utils.py): `utils/file_utils.py`
- [Embedding utilities](https://github.com/hhansi/embed2detect/blob/master/utils/word_embedding_util.py): `utils/word_embedding_util.py`

### Evaluation

- [Ground-truth processing](https://github.com/hhansi/embed2detect/blob/master/data_analysis/groundtruth_processor.py): `data_analysis/groundtruth_processor.py`
- [Evaluation runner](https://github.com/hhansi/embed2detect/blob/master/experiments/twitter_event_data_2019/evaluation/evaluate.py): `experiments/twitter_event_data_2019/evaluation/evaluate.py`
- [Keyword evaluation](https://github.com/hhansi/embed2detect/blob/master/experiments/twitter_event_data_2019/evaluation/keyword_evaluate.py): `experiments/twitter_event_data_2019/evaluation/keyword_evaluate.py`
- [Topic evaluation](https://github.com/hhansi/embed2detect/blob/master/experiments/twitter_event_data_2019/evaluation/topic_evaluate.py): `experiments/twitter_event_data_2019/evaluation/topic_evaluate.py`

### BERT experiments

- [Fine-tuning experiment](https://github.com/hhansi/embed2detect/blob/master/bert_experiments/language_finetuning_experiment.py): `bert_experiments/language_finetuning_experiment.py`
- [Language model](https://github.com/hhansi/embed2detect/blob/master/bert_experiments/transformers/language_modeling/language_modeling_model.py): `bert_experiments/transformers/language_modeling/language_modeling_model.py`
- [Language-model utilities](https://github.com/hhansi/embed2detect/blob/master/bert_experiments/transformers/language_modeling/language_modeling_utils.py): `bert_experiments/transformers/language_modeling/language_modeling_utils.py`
- [Model definitions](https://github.com/hhansi/embed2detect/blob/master/bert_experiments/transformers/language_modeling/models.py): `bert_experiments/transformers/language_modeling/models.py`
- [Model arguments](https://github.com/hhansi/embed2detect/blob/master/bert_experiments/transformers/args/model_args.py): `bert_experiments/transformers/args/model_args.py`

### Other components

- **Data operator**
- **Event word files**

## Connections

- Data operator → Detection entry: runs with data (evidence: `README.md`)
- Detection entry → Text preprocessing: preprocesses (evidence: `embed2detect/main.py`)
- Detection entry → Time chunking: time-filters (evidence: `embed2detect/main.py`)
- Detection entry → Data statistics: generates stats (evidence: `embed2detect/main.py`)
- Detection entry → Embedding learner: learns embeddings (evidence: `embed2detect/main.py`)
- Detection entry → Window identification: identifies windows (evidence: `embed2detect/main.py`)
- Detection entry → Event word extraction: extracts words (evidence: `embed2detect/main.py`)
- Detection entry → File utilities: gets filename (evidence: `embed2detect/main.py`)
- Embedding learner → Word2Vec training: trains when configured (evidence: `embed2detect/word_embedding_learner.py`)
- Embedding learner → FastText training: trains when configured (evidence: `embed2detect/word_embedding_learner.py`)
- Embedding learner → Embedding utilities: formats training data (evidence: `embed2detect/word_embedding_learner.py`)
- Window identification → Cluster change: calculates changes (evidence: `embed2detect/event_window_identifier.py`)
- Window identification → Vocabulary calculation: uses vocabulary (evidence: `embed2detect/event_window_identifier.py`)
- Window identification → Vocabulary change: calculates vocabulary change (evidence: `embed2detect/event_window_identifier.py`)
- Cluster change → Dendrogram similarity: uses similarity (evidence: `algo/cluster_change_calculation.py`)
- Cluster change → Similarity matrices: calculates matrix differences (evidence: `algo/cluster_change_calculation.py`)
- Cluster change → Vocabulary calculation: saves vocabulary (evidence: `algo/cluster_change_calculation.py`)
- Cluster change → Embedding utilities: gets embeddings (evidence: `algo/cluster_change_calculation.py`)
- Event word extraction → Similarity matrices: uses matrix helpers (evidence: `embed2detect/event_word_extractor.py`)
- Detection entry → Event word files: writes event files (evidence: `README.md`)
- Evaluation runner → Ground-truth processing: loads labels (evidence: `experiments/twitter_event_data_2019/evaluation/evaluate.py`)
- Evaluation runner → Keyword evaluation: evaluates keywords (evidence: `experiments/twitter_event_data_2019/evaluation/evaluate.py`)
- Evaluation runner → Topic evaluation: evaluates topics (evidence: `experiments/twitter_event_data_2019/evaluation/evaluate.py`)
- Fine-tuning experiment → Language model: runs model (evidence: `bert_experiments/language_finetuning_experiment.py`)
- Language model → Model arguments: uses arguments (evidence: `bert_experiments/transformers/language_modeling/language_modeling_model.py`)
- Language model → Language-model utilities: uses utilities (evidence: `bert_experiments/transformers/language_modeling/language_modeling_model.py`)
- Language model → Model definitions: uses model definitions (evidence: `bert_experiments/transformers/language_modeling/language_modeling_model.py`)
