malek-messaoudii commited on
Commit
1d14fcd
·
1 Parent(s): 492be8b

Update label.py

Browse files
Files changed (1) hide show
  1. models/label.py +124 -12
models/label.py CHANGED
@@ -32,19 +32,19 @@ class PredictionResponse(BaseModel):
32
  "example": {
33
  "prediction": 1,
34
  "confidence": 0.874,
35
- "label": "MATCH",
36
  "probabilities": {
37
- "match": 0.874,
38
- "no_match": 0.126
39
  }
40
  }
41
  }
42
  )
43
 
44
- prediction: int = Field(..., description="1 = match, 0 = no match")
45
  confidence: float = Field(..., ge=0.0, le=1.0,
46
  description="Confidence score of the prediction")
47
- label: str = Field(..., description="MATCH or NO_MATCH")
48
  probabilities: Dict[str, float] = Field(
49
  ..., description="Dictionary of class probabilities"
50
  )
@@ -57,12 +57,24 @@ class BatchPredictionRequest(BaseModel):
57
  "example": {
58
  "pairs": [
59
  {
60
- "argument": "Schools should implement AI tools to support learning.",
61
- "key_point": "AI can improve student engagement."
62
  },
63
  {
64
- "argument": "Governments must reduce plastic usage.",
65
- "key_point": "Plastic waste harms the environment."
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
67
  ]
68
  }
@@ -77,8 +89,72 @@ class BatchPredictionRequest(BaseModel):
77
 
78
  class BatchPredictionResponse(BaseModel):
79
  """Response model for batch key-point predictions"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  predictions: List[PredictionResponse]
81
  total_processed: int = Field(..., description="Number of processed items")
 
 
 
 
82
 
83
 
84
  class HealthResponse(BaseModel):
@@ -86,13 +162,49 @@ class HealthResponse(BaseModel):
86
  model_config = ConfigDict(
87
  json_schema_extra={
88
  "example": {
89
- "status": "ok",
90
  "model_loaded": True,
91
- "device": "cuda"
 
 
92
  }
93
  }
94
  )
95
 
96
  status: str = Field(..., description="API health status")
97
  model_loaded: bool = Field(..., description="Whether the model is loaded")
98
- device: str = Field(..., description="Device used for inference (cpu/cuda)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  "example": {
33
  "prediction": 1,
34
  "confidence": 0.874,
35
+ "label": "apparie",
36
  "probabilities": {
37
+ "non_apparie": 0.126,
38
+ "apparie": 0.874
39
  }
40
  }
41
  }
42
  )
43
 
44
+ prediction: int = Field(..., description="1 = apparie, 0 = non_apparie")
45
  confidence: float = Field(..., ge=0.0, le=1.0,
46
  description="Confidence score of the prediction")
47
+ label: str = Field(..., description="apparie or non_apparie")
48
  probabilities: Dict[str, float] = Field(
49
  ..., description="Dictionary of class probabilities"
50
  )
 
57
  "example": {
58
  "pairs": [
59
  {
60
+ "argument": "School uniforms limit students' self-expression and creativity",
61
+ "key_point": "Uniforms restrict personal freedom and individuality"
62
  },
63
  {
64
+ "argument": "Renewable energy creates more jobs than fossil fuel industries",
65
+ "key_point": "Green energy generates employment opportunities"
66
+ },
67
+ {
68
+ "argument": "We should invest more in renewable energy to combat climate change",
69
+ "key_point": "Capital punishment violates human rights"
70
+ },
71
+ {
72
+ "argument": "Online education provides flexibility and accessibility for all students",
73
+ "key_point": "Digital learning offers convenient and inclusive education"
74
+ },
75
+ {
76
+ "argument": "Vaccinations are essential for public health and disease prevention",
77
+ "key_point": "Space exploration leads to scientific discoveries"
78
  }
79
  ]
80
  }
 
89
 
90
  class BatchPredictionResponse(BaseModel):
91
  """Response model for batch key-point predictions"""
92
+ model_config = ConfigDict(
93
+ json_schema_extra={
94
+ "example": {
95
+ "predictions": [
96
+ {
97
+ "prediction": 1,
98
+ "confidence": 0.956,
99
+ "label": "apparie",
100
+ "probabilities": {
101
+ "non_apparie": 0.044,
102
+ "apparie": 0.956
103
+ }
104
+ },
105
+ {
106
+ "prediction": 1,
107
+ "confidence": 0.892,
108
+ "label": "apparie",
109
+ "probabilities": {
110
+ "non_apparie": 0.108,
111
+ "apparie": 0.892
112
+ }
113
+ },
114
+ {
115
+ "prediction": 0,
116
+ "confidence": 0.934,
117
+ "label": "non_apparie",
118
+ "probabilities": {
119
+ "non_apparie": 0.934,
120
+ "apparie": 0.066
121
+ }
122
+ },
123
+ {
124
+ "prediction": 1,
125
+ "confidence": 0.878,
126
+ "label": "apparie",
127
+ "probabilities": {
128
+ "non_apparie": 0.122,
129
+ "apparie": 0.878
130
+ }
131
+ },
132
+ {
133
+ "prediction": 0,
134
+ "confidence": 0.967,
135
+ "label": "non_apparie",
136
+ "probabilities": {
137
+ "non_apparie": 0.967,
138
+ "apparie": 0.033
139
+ }
140
+ }
141
+ ],
142
+ "total_processed": 5,
143
+ "summary": {
144
+ "total_apparie": 3,
145
+ "total_non_apparie": 2,
146
+ "average_confidence": 0.9254
147
+ }
148
+ }
149
+ }
150
+ )
151
+
152
  predictions: List[PredictionResponse]
153
  total_processed: int = Field(..., description="Number of processed items")
154
+ summary: Dict[str, float] = Field(
155
+ ...,
156
+ description="Summary statistics of the batch prediction"
157
+ )
158
 
159
 
160
  class HealthResponse(BaseModel):
 
162
  model_config = ConfigDict(
163
  json_schema_extra={
164
  "example": {
165
+ "status": "healthy",
166
  "model_loaded": True,
167
+ "device": "cpu",
168
+ "model_name": "NLP-Debater-Project/destlibert-keypoint-matching",
169
+ "timestamp": "2024-01-01T12:00:00Z"
170
  }
171
  }
172
  )
173
 
174
  status: str = Field(..., description="API health status")
175
  model_loaded: bool = Field(..., description="Whether the model is loaded")
176
+ device: str = Field(..., description="Device used for inference (cpu/cuda)")
177
+ model_name: Optional[str] = Field(None, description="Name of the loaded model")
178
+ timestamp: str = Field(..., description="Timestamp of the health check")
179
+
180
+
181
+ class ModelInfoResponse(BaseModel):
182
+ """Detailed model information response"""
183
+ model_config = ConfigDict(
184
+ json_schema_extra={
185
+ "example": {
186
+ "model_name": "NLP-Debater-Project/destlibert-keypoint-matching",
187
+ "device": "cpu",
188
+ "max_length": 256,
189
+ "num_labels": 2,
190
+ "loaded": True,
191
+ "performance": {
192
+ "accuracy": 0.9285,
193
+ "f1_score": 0.8836,
194
+ "f1_apparie": 0.8113,
195
+ "f1_non_apparie": 0.9559
196
+ },
197
+ "description": "DistilBERT model for key point - argument semantic matching"
198
+ }
199
+ }
200
+ )
201
+
202
+ model_name: str
203
+ device: str
204
+ max_length: int
205
+ num_labels: int
206
+ loaded: bool
207
+ performance: Dict[str, float] = Field(
208
+ ..., description="Model performance metrics"
209
+ )
210
+ description: str = Field(..., description="Model description")