# tobiia/tasc architecture

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

- Interactive diagram: https://gitdiagram.com/tobiia/tasc
- Repository: https://github.com/tobiia/tasc

## Overview

1. **This repo has two main products.**  
   The first is the **LSC analysis library** in `lib/LSC`, which computes lexical semantic change scores from two corpora. The second is the **TASC interactive app** in `src/`, which serves a backend API and a React/Plotly frontend for 3D topic-aware visualization.

2. **The LSC library is a staged pipeline.**  
   `lsc/extraction/word_extractor.py` and `word_cache.py` identify candidate terms from corpora, likely with stop-word/POS filtering and cached word lists. That feeds `lsc/representation/embedding_creator.py`, which builds contextual embeddings for selected terms. The output is then consumed by `lsc/assessment/scoring.py` for semantic-shift metrics.

3. **Embedding generation is a core boundary.**  
   The repo is optimized around expensive transformer inference. `lsc/representation/embed_cache.py` stores embeddings as cached NPZ files so repeated runs reuse results instead of recomputing. `lsc/representation/models.py` defines the data structures used to move term-level results through the pipeline.

4. **Semantic change scoring is separate from visualization.**  
   `lsc/assessment/scoring.py` supports evaluation against gold labels and reports metrics such as APD and PRT. This is the “batch analysis” side of the system, distinct from the interactive app. The README’s `score` command points to this path.

5. **Topic modeling is provided by a vendored Top2Vec fork.**  
   `lib/Top2Vec` is bundled in-repo, not treated as an external runtime dependency. It is used by the visualization app to discover topic clusters in the analyzed corpus and provide topic labels/top words alongside semantic-change trajectories.

6. **The visualization backend is the orchestration layer.**  
   `src/backend/app/main.py`, `core.py`, and `topic.py` form the API server. `core.py` appears to handle loading corpus/embedding data and PCA fitting; `topic.py` handles topic extraction and related topic metadata; `main.py` exposes the endpoints and startup/shutdown lifecycle. This backend is the bridge between cached NLP outputs and the UI.

7. **The frontend is a single-page visualization client.**  
   `src/frontend` is a Vite/React app with Plotly-based 3D rendering. `App.jsx` is the root container, `api.js` talks to the backend, `Plotly.jsx` wraps chart behavior, and the components directory splits the UI into word selection, topic lists, word lists, occurrence/sentence examples, and the plot canvas.

8. **Data flows from corpora to caches to API to UI.**  
   Raw text corpora are read from dataset directories, transformed into embeddings, then reused from cache on subsequent runs. The backend combines those embeddings with PCA projections and topic-model output, and the frontend renders word trajectories, topic clusters, and example sentences for selected lemmas.

9. **The repository is dataset- and cache-driven.**  
   The README’s corpus layout under `corpora/` and the cache naming conventions are important architectural constraints. Cache keys are derived from dataset names, and `config.toml` / `src/config.py` / `lib/LSC/src/lsc/config.py` hold the paths that bind the selected dataset to the pipeline.

10. **There are multiple execution modes.**  
   The root `pyproject.toml`, `src/cli.py`, `Run.bat`, `run.sh`, and the `.app` wrappers indicate packaged entry points for both production and development. The app can be launched as a local visualization service, while the LSC library can be used independently for offline scoring/evaluation.

11. **Build and installation are split across Python and Node.**  
   `scripts/install.py`, `install.sh`, `install.bat`, and `build_zip.py` automate environment setup and release packaging. The frontend has its own `package.json`/Vite toolchain, while the Python side packages the analysis library and backend.

12. **The main architectural boundary is “analysis engine” vs “interactive presentation.”**  
   `lib/LSC` and `lib/Top2Vec` implement NLP computation; `src/backend` adapts those results into API-ready data; `src/frontend` renders the final interactive experience. That separation is what you would draw first in an architecture diagram.

Main entry points: [`src/frontend/src/App.jsx`](https://github.com/tobiia/tasc/blob/main/src/frontend/src/App.jsx) (Frontend app), [`lib/LSC/src/lsc/representation/embedding_creator.py`](https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/representation/embedding_creator.py) (Embedding creator), [`src/backend/app/core.py`](https://github.com/tobiia/tasc/blob/main/src/backend/app/core.py) (Core data), [`src/backend/app/main.py`](https://github.com/tobiia/tasc/blob/main/src/backend/app/main.py) (API server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_analysis["Analysis engine"]
  node_corpora[("Corpora<br/>dataset roots<br/>[README.md]")]
  node_word_extractor["Word extractor<br/>candidate terms<br/>[word_extractor.py]"]
  node_word_cache[("Word cache<br/>term cache<br/>[word_cache.py]")]
  node_embedding_creator["Embedding creator<br/>context embeddings"]
  node_embed_cache[("Embedding cache<br/>npz cache<br/>[embed_cache.py]")]
  node_lsc_models["Models<br/>[models.py]"]
  node_scoring["Scoring<br/>shift metrics<br/>[scoring.py]"]
  node_top2vec["Top2Vec<br/>topic model<br/>[top2vec.py]"]
  node_lsc_config["LSC config<br/>pipeline config<br/>[config.py]"]
end

subgraph group_app["Interactive app"]
  node_backend_main["API server<br/>backend lifecycle<br/>[main.py]"]
  node_backend_core["Core data<br/>backend orchestration<br/>[core.py]"]
  node_backend_topic["Topic service<br/>topic orchestration<br/>[topic.py]"]
  node_frontend_app["Frontend app<br/>React SPA<br/>[App.jsx]"]
  node_frontend_api["API client<br/>browser data client<br/>[api.js]"]
  node_plotly_wrap["Plotly view<br/>3D chart wrapper<br/>[Plotly.jsx]"]
  node_plot_canvas["Plot canvas<br/>visual canvas<br/>[PlotCanvas.jsx]"]
  node_topic_list["Topic list<br/>selection panel<br/>[TopicList.jsx]"]
  node_word_list["Word list<br/>selection panel<br/>[WordList.jsx]"]
  node_occurrence_bar["Examples panel<br/>evidence panel<br/>[OccurrenceBar.jsx]"]
end

subgraph group_ops["Packaging"]
  node_cli_entry["CLI<br/>command entrypoint<br/>[cli.py]"]
  node_installer["Installer<br/>setup scripts<br/>[install.py]"]
  node_launchers["Launchers<br/>run wrappers<br/>[run.sh]"]
end

node_corpora -->|"read terms"| node_word_extractor
node_word_extractor -->|"cache lists"| node_word_cache
node_word_cache -->|"select terms"| node_embedding_creator
node_embedding_creator -->|"store vectors"| node_embed_cache
node_embedding_creator -->|"emit results"| node_lsc_models
node_embed_cache -->|"reuse embeddings"| node_scoring
node_lsc_models -->|"score shifts"| node_scoring
node_lsc_config -->|"paths"| node_word_extractor
node_lsc_config -->|"model config"| node_embedding_creator
node_corpora -->|"load data"| node_backend_core
node_embed_cache -->|"serve vectors"| node_backend_core
node_backend_core -->|"shared state"| node_backend_topic
node_top2vec -->|"topic discovery"| node_backend_topic
node_backend_core -->|"register data"| node_backend_main
node_backend_topic -->|"register topics"| node_backend_main
node_backend_main -->|"serve API"| node_frontend_api
node_frontend_api -->|"hydrate UI"| node_frontend_app
node_frontend_app -->|"render chart"| node_plotly_wrap
node_plotly_wrap -->|"draw trajectories"| node_plot_canvas
node_frontend_app -->|"show topics"| node_topic_list
node_frontend_app -->|"show words"| node_word_list
node_frontend_app -->|"show evidence"| node_occurrence_bar
node_cli_entry -->|"start service"| node_backend_main
node_installer -->|"prepare release"| node_launchers

click node_corpora "https://github.com/tobiia/tasc/blob/main/README.md"
click node_word_extractor "https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/extraction/word_extractor.py"
click node_word_cache "https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/extraction/word_cache.py"
click node_embedding_creator "https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/representation/embedding_creator.py"
click node_embed_cache "https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/representation/embed_cache.py"
click node_lsc_models "https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/representation/models.py"
click node_scoring "https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/assessment/scoring.py"
click node_top2vec "https://github.com/tobiia/tasc/blob/main/lib/Top2Vec/top2vec/top2vec.py"
click node_lsc_config "https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/config.py"
click node_backend_main "https://github.com/tobiia/tasc/blob/main/src/backend/app/main.py"
click node_backend_core "https://github.com/tobiia/tasc/blob/main/src/backend/app/core.py"
click node_backend_topic "https://github.com/tobiia/tasc/blob/main/src/backend/app/topic.py"
click node_frontend_app "https://github.com/tobiia/tasc/blob/main/src/frontend/src/App.jsx"
click node_frontend_api "https://github.com/tobiia/tasc/blob/main/src/frontend/src/api.js"
click node_plotly_wrap "https://github.com/tobiia/tasc/blob/main/src/frontend/src/Plotly.jsx"
click node_plot_canvas "https://github.com/tobiia/tasc/blob/main/src/frontend/src/components/PlotCanvas.jsx"
click node_topic_list "https://github.com/tobiia/tasc/blob/main/src/frontend/src/components/TopicList.jsx"
click node_word_list "https://github.com/tobiia/tasc/blob/main/src/frontend/src/components/WordList.jsx"
click node_occurrence_bar "https://github.com/tobiia/tasc/blob/main/src/frontend/src/components/OccurrenceBar.jsx"
click node_cli_entry "https://github.com/tobiia/tasc/blob/main/src/cli.py"
click node_installer "https://github.com/tobiia/tasc/blob/main/scripts/install.py"
click node_launchers "https://github.com/tobiia/tasc/blob/main/run.sh"

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_corpora,node_word_extractor,node_word_cache,node_embedding_creator,node_embed_cache,node_lsc_models,node_scoring,node_top2vec,node_lsc_config toneBlue
class node_backend_main,node_backend_core,node_backend_topic,node_frontend_app,node_frontend_api,node_plotly_wrap,node_plot_canvas,node_topic_list,node_word_list,node_occurrence_bar toneAmber
class node_cli_entry,node_installer,node_launchers toneMint
```

## Components

### Analysis engine

Offline lexical semantic change pipeline and bundled topic modeling

- [Corpora](https://github.com/tobiia/tasc/blob/main/README.md): dataset roots · Source text collections and dataset-specific inputs used by both analysis and app · `README.md`
- [Word extractor](https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/extraction/word_extractor.py): candidate terms · Finds target lemmas from corpora with filtering and cache support · `lib/LSC/src/lsc/extraction/word_extractor.py`
- [Word cache](https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/extraction/word_cache.py): term cache · Stores extracted word lists for reuse across runs · `lib/LSC/src/lsc/extraction/word_cache.py`
- [Embedding creator](https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/representation/embedding_creator.py): context embeddings · Builds contextual embeddings for selected terms · `lib/LSC/src/lsc/representation/embedding_creator.py`
- [Embedding cache](https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/representation/embed_cache.py): npz cache · Persists expensive embedding outputs to avoid recomputation · `lib/LSC/src/lsc/representation/embed_cache.py`
- [Models](https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/representation/models.py): result models · Data structures passed between extraction, embedding, and scoring stages · `lib/LSC/src/lsc/representation/models.py`
- [Scoring](https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/assessment/scoring.py): shift metrics · Computes lexical semantic change metrics and evaluation against gold labels · `lib/LSC/src/lsc/assessment/scoring.py`
- [Top2Vec](https://github.com/tobiia/tasc/blob/main/lib/Top2Vec/top2vec/top2vec.py): topic model · Vendored topic discovery and labeling library used by the app · `lib/Top2Vec/top2vec/top2vec.py`
- [LSC config](https://github.com/tobiia/tasc/blob/main/lib/LSC/src/lsc/config.py): pipeline config · Configures corpus paths and analysis pipeline settings · `lib/LSC/src/lsc/config.py`

### Interactive app

Backend API and React frontend for topic-aware visualization

- [API server](https://github.com/tobiia/tasc/blob/main/src/backend/app/main.py): backend lifecycle · Starts the backend service and exposes endpoints to the frontend · `src/backend/app/main.py`
- [Core data](https://github.com/tobiia/tasc/blob/main/src/backend/app/core.py): backend orchestration · Loads corpus and embedding data and prepares PCA-ready state · `src/backend/app/core.py`
- [Topic service](https://github.com/tobiia/tasc/blob/main/src/backend/app/topic.py): topic orchestration · Derives topic clusters and topic metadata for visualization · `src/backend/app/topic.py`
- [Frontend app](https://github.com/tobiia/tasc/blob/main/src/frontend/src/App.jsx): React SPA · Root client container for the interactive visualization · `src/frontend/src/App.jsx`
- [API client](https://github.com/tobiia/tasc/blob/main/src/frontend/src/api.js): browser data client · Fetches backend data for the UI · `src/frontend/src/api.js`
- [Plotly view](https://github.com/tobiia/tasc/blob/main/src/frontend/src/Plotly.jsx): 3D chart wrapper · Encapsulates Plotly chart behavior for semantic trajectories · `src/frontend/src/Plotly.jsx`
- [Plot canvas](https://github.com/tobiia/tasc/blob/main/src/frontend/src/components/PlotCanvas.jsx): visual canvas · Renders the 3D trajectory and topic-aware scatter view · `src/frontend/src/components/PlotCanvas.jsx`
- [Topic list](https://github.com/tobiia/tasc/blob/main/src/frontend/src/components/TopicList.jsx): selection panel · Shows discovered topics and related metadata · `src/frontend/src/components/TopicList.jsx`
- [Word list](https://github.com/tobiia/tasc/blob/main/src/frontend/src/components/WordList.jsx): selection panel · Lets users browse and select tracked lemmas · `src/frontend/src/components/WordList.jsx`
- [Examples panel](https://github.com/tobiia/tasc/blob/main/src/frontend/src/components/OccurrenceBar.jsx): evidence panel · Displays occurrence and sentence evidence for selected words · `src/frontend/src/components/OccurrenceBar.jsx`

### Packaging

Install, launch, and release entry points

- [CLI](https://github.com/tobiia/tasc/blob/main/src/cli.py): command entrypoint · Command-line interface for running the app and utilities · `src/cli.py`
- [Installer](https://github.com/tobiia/tasc/blob/main/scripts/install.py): setup scripts · Automates environment setup and release packaging · `scripts/install.py`
- [Launchers](https://github.com/tobiia/tasc/blob/main/run.sh): run wrappers · Shell, batch, and app wrappers for production and development start-up · `run.sh`

## Connections

- Corpora → Word extractor: read terms · Corpora are scanned to identify candidate lemmas
- Word extractor → Word cache: cache lists · Extracted word sets are persisted for reuse
- Word cache → Embedding creator: select terms · Cached target terms feed embedding generation
- Embedding creator → Embedding cache: store vectors · Generated contextual embeddings are cached on disk
- Embedding creator → Models: emit results · Embedding outputs are packaged into pipeline data models
- Embedding cache → Scoring: reuse embeddings · Cached embeddings are consumed by scoring and evaluation
- Models → Scoring: score shifts · Structured term-level outputs feed semantic change metrics
- LSC config → Word extractor: paths · Pipeline configuration binds analysis inputs
- LSC config → Embedding creator: model config · Embedding generation depends on configured resources
- Corpora → Core data: load data · Backend loads corpus data for visualization state
- Embedding cache → Core data: serve vectors · Backend reads cached embeddings for projections and lookup
- Core data → Topic service: shared state · Topic analysis builds on loaded corpus and embedding state
- Top2Vec → Topic service: topic discovery · Vendored topic model provides clusters and labels
- Core data → API server: register data · Core services are exposed through the API server
- Topic service → API server: register topics · Topic endpoints and metadata are exposed through the API server
- API server → API client: serve API · Frontend fetches analysis and topic data from the backend
- API client → Frontend app: hydrate UI · Fetched data drives the root app state
- Frontend app → Plotly view: render chart · Root app delegates plot rendering to the Plotly wrapper
- Plotly view → Plot canvas: draw trajectories · Plotly wrapper powers the 3D visualization canvas
- Frontend app → Topic list: show topics · Topic metadata is surfaced in the selection panel
- Frontend app → Word list: show words · Tracked lemmas are surfaced for user selection
- Frontend app → Examples panel: show evidence · Selected lemmas reveal occurrence and sentence examples
- CLI → API server: start service · CLI can launch the backend application
- Installer → Launchers: prepare release · Installation scripts produce runnable app wrappers
