# oliverguhr/german-sentiment-lib architecture

> Architecture diagram of the GitHub repository oliverguhr/german-sentiment-lib, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/oliverguhr/german-sentiment-lib
- Repository: https://github.com/oliverguhr/german-sentiment-lib

## Overview

##### Project Type and Purpose
- This is a Python library (a pip-installable package) for German text sentiment classification. It wraps a pre-trained BERT model (from the Hugging Face ecosystem) behind a simple API (`SentimentModel`) that takes raw German text and returns sentiment labels (and optional probabilities).

##### File-Structure Analysis
- Top-level:
- setup.py – package metadata and install script
- README.md / dev-readme.md – user and developer documentation
- germansentiment/ – package source
- Inside germansentiment/:
- __init__.py – package initializer, exports `SentimentModel`
- sentimentmodel.py – implementation of the main API class
- sentimentmodel_test.py – unit tests for `SentimentModel`
- No frontend or persistent database–this is purely a library.
- Dependencies (implied by code and README): transformers (tokenizer + model loading), PyTorch or TensorFlow backend, possibly huggingface-hub.

##### Key Insights from README
- Usage is single-class: `SentimentModel.predict_sentiment(texts, output_probabilities=False)`
- Behind the scenes it:
a. Loads BERT tokenizer & model weights (possibly from local cache or remote)
b. Performs tokenization → tensor creation → forward pass → softmax
c. Maps output logits to labels (“positive”, “negative”, “neutral”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User & Developer Flow
    subgraph "User & Developer Flow"
        UD["README.md"]:::docs
        DD["dev-readme.md"]:::docs
        PM["setup.py"]:::library
        UT["sentimentmodel_test.py"]:::library
        Dev["Developer Tools"]:::external
        PyPI["PyPI"]:::external
    end

    %% Main Library Code
    subgraph "Library Code"
        Root["germansentiment/"]:::library
        Init["__init__.py"]:::library
        API["SentimentModel API"]:::library
        PP["Post-Processing"]:::library
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Tokenizer["BERT Tokenizer"]:::external
        Engine["Inference Engine"]:::external
        Hub["Hugging Face Hub"]:::external
    end

    %% Data Stores
    subgraph "Model Weights Store"
        Cache["Model Weights Cache"]:::store
    end

    %% Client
    Client["Client Application"]:::external

    %% Flows
    Client -->|imports| Init
    Init -->|exports| API
    Client -->|calls predict_sentiment| API
    API -->|tokenize| Tokenizer
    API -->|infer| Engine
    Tokenizer -->|provides tokens| Engine
    Engine -->|loads weights| Cache
    Engine -->|fetch weights| Hub
    Engine -->|outputs logits| PP
    PP -->|returns labels| Client

    Dev -->|runs tests| UT
    UT -->|tests| API
    PM -->|packages| Root
    PM -->|publishes| PyPI

    %% Click Events
    click API "https://github.com/oliverguhr/german-sentiment-lib/blob/master/germansentiment/sentimentmodel.py"
    click Init "https://github.com/oliverguhr/german-sentiment-lib/blob/master/germansentiment/__init__.py"
    click UT "https://github.com/oliverguhr/german-sentiment-lib/blob/master/germansentiment/sentimentmodel_test.py"
    click PM "https://github.com/oliverguhr/german-sentiment-lib/blob/master/setup.py"
    click UD "https://github.com/oliverguhr/german-sentiment-lib/blob/master/README.md"
    click DD "https://github.com/oliverguhr/german-sentiment-lib/blob/master/dev-readme.md"
    click Root "https://github.com/oliverguhr/german-sentiment-lib/tree/master/germansentiment/"

    %% Styles
    classDef library fill:#b7e4c7,stroke:#2d6a4f,color:#1b4332;
    classDef external fill:#a0c4ff,stroke:#4361ee,color:#1a237e;
    classDef store fill:#ffba08,stroke:#f77f00,color:#6a040f;
    classDef docs fill:#caffbf,stroke:#52b788,color:#1b4332;
```
