File size: 7,304 Bytes
54b5a2a
 
 
 
 
 
 
 
 
 
 
32ba92c
 
54b5a2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32ba92c
 
 
54b5a2a
32ba92c
 
54b5a2a
 
 
 
 
1d14fcd
54b5a2a
 
1d14fcd
54b5a2a
 
 
 
 
 
 
 
 
 
 
 
ad2dc28
 
54b5a2a
 
ad2dc28
 
1d14fcd
 
ad2dc28
 
1d14fcd
32ba92c
 
 
 
1d14fcd
ad2dc28
 
54b5a2a
 
 
 
 
 
 
 
 
 
 
 
 
 
1d14fcd
 
 
 
 
32ba92c
 
 
1d14fcd
32ba92c
 
1d14fcd
 
 
 
32ba92c
1d14fcd
 
32ba92c
 
1d14fcd
 
 
32ba92c
 
 
1d14fcd
32ba92c
 
1d14fcd
 
 
32ba92c
 
 
1d14fcd
32ba92c
 
1d14fcd
 
 
 
32ba92c
1d14fcd
 
32ba92c
 
1d14fcd
 
 
 
 
32ba92c
 
 
 
 
1d14fcd
 
 
 
 
54b5a2a
 
1d14fcd
8a40c79
1d14fcd
 
54b5a2a
 
 
 
 
 
 
1d14fcd
54b5a2a
1d14fcd
32ba92c
1d14fcd
54b5a2a
 
 
 
 
 
1d14fcd
 
 
 
 
 
 
 
 
 
32ba92c
1d14fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
"""Pydantic schemas for key-point matching prediction endpoints"""

from pydantic import BaseModel, Field, ConfigDict
from typing import List, Optional, Dict


class PredictionRequest(BaseModel):
    """Request model for single key-point/argument prediction"""
    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "argument": "Students should wear school uniforms",
                "key_point": "School uniforms are good for students"
            }
        }
    )

    argument: str = Field(
        ..., min_length=5, max_length=1000,
        description="The argument text to evaluate"
    )
    key_point: str = Field(
        ..., min_length=5, max_length=500,
        description="The key point used for comparison"
    )


class PredictionResponse(BaseModel):
    """Response model for single prediction"""
    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "prediction": 0,
                "confidence": 0.9992,
                "label": "non_apparie",
                "probabilities": {
                    "non_apparie": 0.9992,
                    "apparie": 0.0008
                }
            }
        }
    )

    prediction: int = Field(..., description="1 = apparie, 0 = non_apparie")
    confidence: float = Field(..., ge=0.0, le=1.0,
                              description="Confidence score of the prediction")
    label: str = Field(..., description="apparie or non_apparie")
    probabilities: Dict[str, float] = Field(
        ..., description="Dictionary of class probabilities"
    )


class BatchPredictionRequest(BaseModel):
    """Request model for batch predictions"""
    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "pairs": [
                    {
                        "argument": "Students should wear school uniforms",
                        "key_point": "School uniforms are good for students"
                    },
                    {
                        "argument": "We need more renewable energy",
                        "key_point": "Solar and wind power are important"
                    },
                    {
                        "argument": "Exercise improves health",
                        "key_point": "Physical activity is good for the body"
                    },
                    {
                        "argument": "Education should be free for everyone",
                        "key_point": "Cars should be electric"
                    },
                    {
                        "argument": "Reading books helps learning",
                        "key_point": "We should build more parks"
                    }
                ]
            }
        }
    )

    pairs: List[PredictionRequest] = Field(
        ..., max_length=100,
        description="List of argument-keypoint pairs (max 100)"
    )


class BatchPredictionResponse(BaseModel):
    """Response model for batch key-point predictions"""
    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "predictions": [
                    {
                        "prediction": 0,
                        "confidence": 0.9992,
                        "label": "non_apparie",
                        "probabilities": {
                            "non_apparie": 0.9992,
                            "apparie": 0.0008
                        }
                    },
                    {
                        "prediction": 1,
                        "confidence": 0.5279,
                        "label": "apparie",
                        "probabilities": {
                            "non_apparie": 0.4721,
                            "apparie": 0.5279
                        }
                    },
                    {
                        "prediction": 1,
                        "confidence": 0.8836,
                        "label": "apparie",
                        "probabilities": {
                            "non_apparie": 0.1164,
                            "apparie": 0.8836
                        }
                    },
                    {
                        "prediction": 0,
                        "confidence": 0.5157,
                        "label": "non_apparie",
                        "probabilities": {
                            "non_apparie": 0.5157,
                            "apparie": 0.4843
                        }
                    },
                    {
                        "prediction": 0,
                        "confidence": 0.9958,
                        "label": "non_apparie",
                        "probabilities": {
                            "non_apparie": 0.9958,
                            "apparie": 0.0042
                        }
                    }
                ],
                "total_processed": 5,
                "summary": {
                    "total_apparie": 2,
                    "total_non_apparie": 3,
                    "average_confidence": 0.7844,
                    "successful_predictions": 5,
                    "failed_predictions": 0
                }
            }
        }
    )

    predictions: List[PredictionResponse]
    total_processed: int = Field(..., description="Number of processed items")
    summary: Dict[str, float] = Field(
        default_factory=dict,
        description="Summary statistics of the batch prediction"
    )


class HealthResponse(BaseModel):
    """Health check model for the API"""
    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "status": "healthy",
                "model_loaded": True,
                "device": "cpu",
                "model_name": "NLP-Debater-Project/distilBert-keypoint-matching",
                "timestamp": "2024-01-01T12:00:00Z"
            }
        }
    )
    
    status: str = Field(..., description="API health status")
    model_loaded: bool = Field(..., description="Whether the model is loaded")
    device: str = Field(..., description="Device used for inference (cpu/cuda)")
    model_name: Optional[str] = Field(None, description="Name of the loaded model")
    timestamp: str = Field(..., description="Timestamp of the health check")


class ModelInfoResponse(BaseModel):
    """Detailed model information response"""
    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "model_name": "NLP-Debater-Project/distilBert-keypoint-matching",
                "device": "cpu",
                "max_length": 256,
                "num_labels": 2,
                "loaded": True,
                "performance": {
                    "accuracy": 0.9285,
                    "f1_score": 0.8836,
                    "f1_apparie": 0.8113,
                    "f1_non_apparie": 0.9559
                },
                "description": "DistilBERT model for key point - argument semantic matching"
            }
        }
    )

    model_name: str
    device: str
    max_length: int
    num_labels: int
    loaded: bool
    performance: Dict[str, float] = Field(
        ..., description="Model performance metrics"
    )
    description: str = Field(..., description="Model description")