# huggingface/setfit architecture

> Architecture diagram of the GitHub repository huggingface/setfit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/huggingface/setfit
- Repository: https://github.com/huggingface/setfit

## Overview

##### Main Components

a) Core Components:
- Sentence Transformer Body (Model Backbone)
- Classification Head (either scikit-learn or SetFitHead)
- SetFit Trainer
- Data Processing Pipeline
- Model Export System

b) Integration Components:
- Hugging Face Hub Integration
- Dataset Loading Interface
- Model Card Generation System

**┌─ Input Layer ─────────────────────────────────────┐**
- Text Data → Dataset Loading → Sampling Strategy   │
- ┬───────────────────────────┘
- ↓
**┌─ Core Processing Layer ──────────────────────────┐**
- ┌─ SetFit Model ────────────────────┐           │
- ┌─ Sentence Transformer ─┐        │           │
- Text → Embeddings     │        │           │
- ┬────────────┘        │           │
- ↓                      │           │
- ┌─ Classification Head ─┐         │           │
- Scikit-learn       │         │           │
- SetFitHead         │         │           │
- ┘         │           │
- ┘           │
- ┬───────────────────────────┘
- ↓
**┌─ Training Layer ──────────────────────────────────┐**
- SetFit Trainer                                    │
- Training Loop                                   │
- Evaluation                                      │
- Metrics Tracking                                │
- ┬───────────────────────────┘
- ↓
**┌─ Export Layer ────────────────────────────────────┐**
- Model Serialization                             │
- ONNX Export                                     │
- OpenVINO Export                                 │
- ┬───────────────────────────┘
- ↓
**┌─ Integration Layer ─────────────────────────────┐**
- Hugging Face Hub                              │
- Model Cards                                   │
- External APIs                                 │
- ┘

##### Implementation Details

- Input/Output formats at each stage
- Key configuration parameters
- Performance monitoring points
- Error handling paths

##### Notes for Scale

- Keep the main components visible at a glance
- Use collapsible/expandable sections for detailed views
- Maintain a clear hierarchy of components

## Diagram (Mermaid)

```mermaid
graph TB
    %% Input Layer
    subgraph Input
        TextData[Text Data]
        DatasetLoader[Dataset Loading]:::data
        SamplingStrategy[Sampling Strategy]:::data
        TextData --> DatasetLoader
        DatasetLoader --> SamplingStrategy
    end

    %% Core Processing Layer
    subgraph CoreProcessing
        subgraph SetFitModel
            SentenceTransformer[Sentence Transformer]:::model
            ClassificationHead[Classification Head]:::model
            SentenceTransformer --> ClassificationHead
        end
    end

    %% Training Layer
    subgraph Training
        TrainerComponent[SetFit Trainer]:::training
        LossFunctions[Loss Functions]:::training
        KnowledgeDistillation[Knowledge Distillation]:::training
        TrainingConfig[Training Configuration]:::training
        
        TrainerComponent --> LossFunctions
        TrainerComponent --> KnowledgeDistillation
        TrainingConfig --> TrainerComponent
    end

    %% Export Layer
    subgraph Export
        ModelExport[Model Export System]:::export
        ONNXExport[ONNX Export]:::export
        OpenVINOExport[OpenVINO Export]:::export
        
        ModelExport --> ONNXExport
        ModelExport --> OpenVINOExport
    end

    %% Integration Layer
    subgraph Integration
        HFHub[HuggingFace Hub]:::integration
        ModelCard[Model Card Generation]:::integration
    end

    %% ABSA Components
    subgraph ABSA
        AspectExtractor[Aspect Extractor]:::absa
        ABSAModeling[ABSA Modeling]:::absa
        ABSATrainer[ABSA Trainer]:::absa
        
        AspectExtractor --> ABSAModeling
        ABSAModeling --> ABSATrainer
    end

    %% Main Flow
    SamplingStrategy --> SetFitModel
    SetFitModel --> TrainerComponent
    TrainerComponent --> ModelExport
    ModelExport --> HFHub
    HFHub --> ModelCard

    %% Styling
    classDef model fill:#a8d1ff,stroke:#333
    classDef data fill:#90EE90,stroke:#333
    classDef training fill:#FFB347,stroke:#333
    classDef export fill:#D3D3D3,stroke:#333
    classDef integration fill:#DDA0DD,stroke:#333
    classDef absa fill:#FFE4B5,stroke:#333

    %% Click Events
    click SentenceTransformer "https://github.com/huggingface/setfit/blob/main/src/setfit/modeling.py"
    click ClassificationHead "https://github.com/huggingface/setfit/blob/main/src/setfit/modeling.py"
    click TrainerComponent "https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py"
    click DatasetLoader "https://github.com/huggingface/setfit/blob/main/src/setfit/data.py"
    click ModelExport "https://github.com/huggingface/setfit/tree/main/src/setfit/exporters/"
    click ONNXExport "https://github.com/huggingface/setfit/blob/main/src/setfit/exporters/onnx.py"
    click OpenVINOExport "https://github.com/huggingface/setfit/blob/main/src/setfit/exporters/openvino.py"
    click HFHub "https://github.com/huggingface/setfit/blob/main/src/setfit/integrations.py"
    click ModelCard "https://github.com/huggingface/setfit/blob/main/src/setfit/model_card.py"
    click SamplingStrategy "https://github.com/huggingface/setfit/blob/main/src/setfit/sampler.py"
    click TrainingConfig "https://github.com/huggingface/setfit/blob/main/src/setfit/training_args.py"
    click LossFunctions "https://github.com/huggingface/setfit/blob/main/src/setfit/losses.py"
    click KnowledgeDistillation "https://github.com/huggingface/setfit/blob/main/src/setfit/trainer_distillation.py"
    click AspectExtractor "https://github.com/huggingface/setfit/blob/main/src/setfit/span/aspect_extractor.py"
    click ABSAModeling "https://github.com/huggingface/setfit/blob/main/src/setfit/span/modeling.py"
    click ABSATrainer "https://github.com/huggingface/setfit/blob/main/src/setfit/span/trainer.py"
```
