-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval.html
More file actions
527 lines (448 loc) · 24.6 KB
/
eval.html
File metadata and controls
527 lines (448 loc) · 24.6 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GraphRAG Evaluation</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.6.5/flowbite.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/apexcharts@3.46.0/dist/apexcharts.min.js"></script>
</head>
<body class="bg-gray-100 font-sans">
<div class="container max-w-6xl mx-auto px-4 py-8">
<h1 class="text-3xl font-bold mb-6 text-gray-800"> GraphRAG Evaluation</h1>
<div class="mb-6">
<label for="domainSelect" class="block mb-2 text-sm font-medium text-gray-700">Domain:</label>
<select id="domainSelect" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5">
<option value="finance" selected>finance</option>
<option value="medical">medical</option>
</select>
</div>
<div class="mb-6">
<button id="loadQuestionsBtn" class="px-5 py-3 bg-blue-600 text-white font-medium rounded-lg hover:bg-blue-700 transition-colors flex items-center gap-2 shadow-sm">
Load questions
</button>
<div id="questionsLoader" class="hidden mt-4">
<div class="flex items-center">
<div class="animate-spin rounded-full h-6 w-6 border-b-2 border-blue-700"></div>
<span class="ml-3 text-gray-700">Loading questions ...</span>
</div>
</div>
</div>
<div id="questionsList" class="mb-8 hidden bg-white rounded-lg shadow-md overflow-hidden">
<h2 class="px-6 py-3 bg-gray-50 text-lg font-semibold text-gray-700">Questions</h2>
<ul id="questionsContainer" class="divide-y divide-gray-200">
<!-- Les questions seront ajoutées ici dynamiquement -->
</ul>
</div>
<!-- Panneau de résultats -->
<div id="resultsPanel" class="hidden">
<h2 class="text-2xl font-semibold mb-4 text-gray-800" id="selectedQuestionTitle"></h2>
<!-- Tableau des résultats pour différentes valeurs de nChunks -->
<div class="bg-white rounded-lg shadow-md mb-8 overflow-hidden">
<div class="px-6 py-4 bg-gray-50">
<h3 class="text-lg font-semibold text-gray-700"></h3>
</div>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">nChunks</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">METEOR</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">BLEU</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">BERT</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ROUGEL</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">OVERLAP</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">OVERLAPE</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"></th>
</tr>
</thead>
<tbody id="metricsTableBody" class="divide-y divide-gray-200">
<!-- Les résultats seront ajoutés ici dynamiquement -->
</tbody>
</table>
</div>
</div>
<!-- graphique-->
<div class="bg-white rounded-lg shadow-md mb-8 overflow-hidden">
<div class="px-6 py-4 bg-gray-50">
<h3 class="text-lg font-semibold text-gray-700"></h3>
</div>
<div class="p-4">
<div id="metricsChart" style="height: 400px;"></div>
</div>
</div>
<!-- Question et réponse complètes -->
<div id="detailsPanel" class="bg-white rounded-lg shadow-md mb-8 overflow-hidden hidden">
<div class="px-6 py-4 bg-gray-50">
<h3 class="text-lg font-semibold text-gray-700">details</h3>
</div>
<div class="p-6">
<div class="mb-4">
<h4 class="text-sm font-semibold text-gray-600 mb-2">Question:</h4>
<p id="detailQuestion" class="text-gray-800 bg-gray-50 p-3 rounded"></p>
</div>
<div class="mb-4">
<h4 class="text-sm font-semibold text-gray-600 mb-2">True answer :</h4>
<p id="detailTrueAnswer" class="text-gray-800 bg-gray-50 p-3 rounded"></p>
</div>
<div class="mb-4">
<h4 class="text-sm font-semibold text-gray-600 mb-2">Generated answer (nChunks: <span id="detailNChunks"></span>):</h4>
<p id="detailPredictedAnswer" class="text-gray-800 bg-gray-50 p-3 rounded"></p>
</div>
</div>
</div>
</div>
<!-- Section pour les moyennes par nChunks -->
<div class="mb-8">
<button id="calculateAveragesBtn" class="px-5 py-3 bg-green-600 text-white font-medium rounded-lg hover:bg-green-700 transition-colors flex items-center gap-2 shadow-sm hidden">
Average metrics for all questions
</button>
<div id="averagesLoader" class="hidden mt-4">
<div class="flex items-center">
<div class="animate-spin rounded-full h-6 w-6 border-b-2 border-green-700"></div>
<span class="ml-3 text-gray-700">Loading ...</span>
</div>
</div>
</div>
<!-- Tableau des moyennes -->
<div id="averagesPanel" class="bg-white rounded-lg shadow-md mb-8 overflow-hidden hidden">
<div class="px-6 py-4 bg-gray-50">
<h3 class="text-lg font-semibold text-gray-700">Averages by nbChunks</h3>
</div>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">nChunks</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">METEOR</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">BLEU</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">BERT</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ROUGE</th>
</tr>
</thead>
<tbody id="averagesTableBody" class="divide-y divide-gray-200">
<!-- Les moyennes seront ajoutées ici dynamiquement -->
</tbody>
</table>
</div>
</div>
<div class="mt-8 flex justify-end">
<a href="javascript:history.back()" class="px-4 py-2 text-gray-700 bg-gray-200 rounded-lg hover:bg-gray-300 transition-colors flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18" />
</svg>
Retour
</a>
</div>
</div>
<script>
let allQuestions = [];
let allAnswers = [];
let metricsData = {};
let metricsChart = null;
function initializeChart() {
const options = {
series: [
{ name: 'METEOR', data: [] },
{ name: 'BLEU', data: [] },
{ name: 'BERT', data: [] },
{ name: 'ROUGEL', data: [] },
{ name: 'OVERLAP', data: [] },
{ name: 'OVERLAPE', data: [] }
],
chart: {
height: 350,
type: 'line',
toolbar: {
show: true
},
zoom: {
enabled: true
},
animations: {
enabled: true,
easing: 'easeinout',
speed: 800
}
},
dataLabels: {
enabled: false
},
stroke: {
width: [3, 3, 3, 3],
curve: 'smooth'
},
colors: ['#4F46E5', '#2563EB', '#059669', '#D97706'],
xaxis: {
categories: [],
title: {
text: 'Number of Chunks'
}
},
yaxis: {
title: {
text: 'Score'
},
min: 0,
max: 1
},
tooltip: {
y: {
formatter: function(value) {
console.log("value", value);
return value !== null && value !== undefined ? value.toFixed(4) : '0';
}
}
},
legend: {
position: 'top'
},
markers: {
size: 5
}
};
metricsChart = new ApexCharts(document.getElementById('metricsChart'), options);
metricsChart.render();
}
function updateChart() {
const nChunksValues = Object.keys(metricsData).map(Number).sort((a, b) => a - b);
const meteorData = nChunksValues.map(nChunks => metricsData[nChunks]?.meteor || 0);
const bleuData = nChunksValues.map(nChunks => metricsData[nChunks]?.bleu || 0);
const bertData = nChunksValues.map(nChunks => metricsData[nChunks]?.bert || 0);
const rougeData = nChunksValues.map(nChunks => metricsData[nChunks]?.rouge || 0);
const overlapData = nChunksValues.map(nChunks => metricsData[nChunks]?.overlap || 0);
const overlapEData = nChunksValues.map(nChunks => metricsData[nChunks]?.overlapE || 0);
metricsChart.updateOptions({
xaxis: {
categories: nChunksValues
}
});
metricsChart.updateSeries([
{ name: 'METEOR', data: meteorData },
{ name: 'BLEU', data: bleuData },
{ name: 'BERT', data: bertData },
{ name: 'ROUGE', data: rougeData },
{ name: 'OVERLAP', data: overlapData },
{ name: 'OVERLAPE', data: overlapEData }
]);
}
// Récupérer le domaine sélectionné
function getSelectedDomain() {
return document.getElementById('domainSelect').value;
}
// Fonction pour charger toutes les questions
async function loadQuestions() {
const domain = getSelectedDomain();
document.getElementById('questionsLoader').classList.remove('hidden');
document.getElementById('questionsList').classList.add('hidden');
try {
const response = await fetch(`http://localhost:5000/getAllQA?domain=${domain}`);
const data = await response.json();
console.log('Données reçues:', data);
allQuestions = data.questions;
allAnswers = data.answers;
console.log('Questions:', allQuestions);
console.log('Réponses:', allAnswers);
// Afficher les questions dans la liste
const container = document.getElementById('questionsContainer');
container.innerHTML = '';
allQuestions.forEach((question, index) => {
const li = document.createElement('li');
li.className = 'px-6 py-4 hover:bg-blue-50 cursor-pointer transition-colors';
li.innerHTML = `<div class="font-medium text-blue-600">${question}</div>`;
li.addEventListener('click', () => selectQuestion(index));
container.appendChild(li);
});
document.getElementById('questionsLoader').classList.add('hidden');
document.getElementById('questionsList').classList.remove('hidden');
document.getElementById('calculateAveragesBtn').classList.remove('hidden');
} catch (error) {
console.error('Erreur lors du chargement des questions:', error);
document.getElementById('questionsLoader').classList.add('hidden');
showNotification('Une erreur est survenue lors du chargement des questions.', 'error');
}
}
// Fonction pour sélectionner une question
async function selectQuestion(index) {
const domain = getSelectedDomain();
const question = allQuestions[index];
const trueAnswer = allAnswers[index];
// Afficher le titre de la question sélectionnée
document.getElementById('selectedQuestionTitle').textContent = question;
document.getElementById('resultsPanel').classList.remove('hidden');
// Effacer les données précédentes
document.getElementById('metricsTableBody').innerHTML = '';
metricsData = {};
// Initialiser ou réinitialiser le graphique
if (metricsChart) {
metricsChart.destroy();
}
initializeChart();
// Évaluer la question pour différentes valeurs de nChunks
for (let nChunks = 0; nChunks <= 10; nChunks++) {
await evaluateWithNChunks(question, trueAnswer, domain, nChunks);
}
}
// Fonction pour évaluer avec un nombre spécifique de chunks
async function evaluateWithNChunks(question, trueAnswer, domain, nChunks) {
// Ajouter une ligne de chargement temporaire
const tbody = document.getElementById('metricsTableBody');
const tempRow = document.createElement('tr');
tempRow.id = `temp-row-${nChunks}`;
tempRow.className = 'bg-gray-50';
tempRow.innerHTML = `
<td class="px-4 py-3 whitespace-nowrap text-sm font-medium text-gray-900">${nChunks}</td>
<td colspan="5" class="px-4 py-3 text-sm text-gray-500">
<div class="flex items-center">
<div class="animate-spin rounded-full h-4 w-4 border-b-2 border-blue-700 mr-2"></div>
Loading ...
</div>
</td>
`;
tbody.appendChild(tempRow);
try {
// Appeler l'API d'évaluation
const params = new URLSearchParams({
domain: domain,
nChunks: nChunks,
question: question,
true_answer: trueAnswer
});
const response = await fetch(`http://localhost:5000/evaluate?${params.toString()}`);
const data = await response.json();
// Extraire les valeurs numériques des métriques
const meteorValue = parseFloat(data.meteor.split(': ')[1]) || 0;
const bleuValue = parseFloat(data.bleu.split(': ')[1]) || 0;
const bertValue = parseFloat(data.bert.split(': ')[1]) || 0;
const rougeValue = parseFloat(data.rouge.split('=')[7]) || 0;
const overlapValue = parseFloat(data.overlap.split(': ')[1]) || 0;
const overlapEValue = parseFloat(data.overlapE.split(': ')[1]) || 0;
// Stocker les métriques pour le graphique
metricsData[nChunks] = {
meteor: meteorValue,
bleu: bleuValue,
bert: bertValue,
rouge: rougeValue,
overlap: overlapValue,
overlapE: overlapEValue,
question: question,
trueAnswer: trueAnswer,
predictedAnswer: data.predicted_answer
};
// Mettre à jour le graphique avec les nouvelles données
updateChart();
// Remplacer la ligne de chargement par les résultats
const newRow = document.createElement('tr');
newRow.className = 'bg-white';
console.log("meteorValue", meteorValue);
console.log("bleuValue", bleuValue);
console.log("bertValue", bertValue);
console.log("rougeValue", rougeValue);
console.log("overlapValue", overlapValue);
console.log("overlapEValue", overlapEValue);
newRow.innerHTML = `
<td class="px-4 py-3 whitespace-nowrap text-sm font-medium text-gray-900">${nChunks}</td>
<td class="px-4 py-3 text-sm text-blue-700">${meteorValue.toFixed(4)}</td>
<td class="px-4 py-3 text-sm text-blue-700">${bleuValue.toFixed(4)}</td>
<td class="px-4 py-3 text-sm text-blue-700">${bertValue.toFixed(4)}</td>
<td class="px-4 py-3 text-sm text-blue-700">${rougeValue.toFixed(4)}</td>
<td class="px-4 py-3 text-sm text-blue-700">${overlapValue.toFixed(4)}</td>
<td class="px-4 py-3 text-sm text-blue-700">${overlapEValue.toFixed(4)}</td>
<td class="px-4 py-3 text-sm">
<button class="text-blue-600 hover:text-blue-800 font-medium"
onclick="showDetails(${nChunks})">
See more
</button>
</td>
`;
// Remplacer la ligne temporaire
document.getElementById(`temp-row-${nChunks}`).replaceWith(newRow);
} catch (error) {
console.error(`Erreur lors de l'évaluation avec nChunks=${nChunks}:`, error);
document.getElementById(`temp-row-${nChunks}`).innerHTML = `
<td class="px-4 py-3 whitespace-nowrap text-sm font-medium text-gray-900">${nChunks}</td>
<td colspan="5" class="px-4 py-3 text-sm text-red-500">Erreur lors de l'évaluation</td>
`;
}
}
// Fonction pour afficher les détails d'une évaluation
function showDetails(nChunks) {
const data = metricsData[nChunks];
if (!data) return;
document.getElementById('detailQuestion').textContent = data.question;
document.getElementById('detailTrueAnswer').textContent = data.trueAnswer;
document.getElementById('detailPredictedAnswer').textContent = data.predictedAnswer;
document.getElementById('detailNChunks').textContent = nChunks;
document.getElementById('detailsPanel').classList.remove('hidden');
}
async function calculateAverages() {
const domain = getSelectedDomain();
document.getElementById('averagesLoader').classList.remove('hidden');
document.getElementById('averagesPanel').classList.add('hidden');
try {
const response = await fetch(`${domain}/evaluation.csv`);
const csvText = await response.text();
const rows = csvText.trim().split('\n');
const headers = rows[0].split(',');
const data = {};
for (let i = 1; i < rows.length; i++) {
const values = rows[i].split(',');
const nChunks = parseInt(values[0]);
data[nChunks] = {
meteor: parseFloat(values[1]),
bleu: parseFloat(values[2]),
bert: parseFloat(values[3]),
rouge: parseFloat(values[4])
};
}
const tbody = document.getElementById('averagesTableBody');
tbody.innerHTML = '';
const nChunksValues = Object.keys(data).map(Number).sort((a, b) => a - b);
nChunksValues.forEach(nChunks => {
const row = document.createElement('tr');
row.className = 'bg-white';
const metrics = data[nChunks];
row.innerHTML = `
<td class="px-4 py-3 whitespace-nowrap text-sm font-medium text-gray-900">${nChunks}</td>
<td class="px-4 py-3 text-sm text-green-700">${metrics.meteor.toFixed(4)}</td>
<td class="px-4 py-3 text-sm text-green-700">${metrics.bleu.toFixed(4)}</td>
<td class="px-4 py-3 text-sm text-green-700">${metrics.bert.toFixed(4)}</td>
<td class="px-4 py-3 text-sm text-green-700">${metrics.rouge.toFixed(4)}</td>
`;
tbody.appendChild(row);
});
document.getElementById('averagesLoader').classList.add('hidden');
document.getElementById('averagesPanel').classList.remove('hidden');
} catch (error) {
console.error('Erreur lors du chargement du CSV:', error);
document.getElementById('averagesLoader').classList.add('hidden');
showNotification(`Une erreur est survenue lors du chargement du fichier ${domain}/evaluation.csv`, 'error');
}
}
// Fonction pour afficher les notifications
function showNotification(message, type = 'info') {
const notificationDiv = document.createElement('div');
notificationDiv.className = type === 'error'
? 'fixed top-4 right-4 bg-red-100 border-l-4 border-red-500 text-red-700 p-4 rounded shadow-md z-50'
: 'fixed top-4 right-4 bg-blue-100 border-l-4 border-blue-500 text-blue-700 p-4 rounded shadow-md z-50';
notificationDiv.innerHTML = `
<div class="flex items-center">
<svg class="h-5 w-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zm-1 9a1 1 0 01-1-1v-4a1 1 0 112 0v4a1 1 0 01-1 1z" clip-rule="evenodd"></path>
</svg>
<p>${message}</p>
</div>
`;
document.body.appendChild(notificationDiv);
setTimeout(() => {
notificationDiv.remove();
}, 5000);
}
// Événements
document.getElementById('loadQuestionsBtn').addEventListener('click', loadQuestions);
document.getElementById('calculateAveragesBtn').addEventListener('click', calculateAverages);
window.showDetails = showDetails;
</script>
</body>
</html>