Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

server.php 2.6 KB

You have to be logged in to leave a comment. Sign In
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
  1. <?php
  2. /*
  3. Code for submission server, live at:
  4. http://www.goren4u.com/nlp_ner
  5. */
  6. function cmp_lines($a, $b) {
  7. $lcmp = array_combine($a, $b); // zip(a, b)
  8. $ret = 0;
  9. $n = 0;
  10. foreach($lcmp as $x => $y) {
  11. $n+=1;
  12. $ret+=(trim($x) == trim($y)) ? 1 : 0;
  13. }
  14. return $ret/$n;
  15. }
  16. if (array_key_exists("submission", $_REQUEST) && array_key_exists("name", $_REQUEST)) //Record submission
  17. {
  18. $user=preg_replace("/[^a-zA-Z0-9_]+/", "", $_REQUEST["name"]);
  19. $submission=json_decode($_REQUEST["submission"], true);
  20. $truth=json_decode(file_get_contents("holdout.data"), true);
  21. // Calculate the accuracy of the submission
  22. $n=0;$score=0;
  23. foreach($truth as $x => $y) {
  24. $n +=1;
  25. $score += array_key_exists($x, $submission) ? cmp_lines($submission[$x], $y) : 0;
  26. }
  27. $score /= $n;
  28. $submission["score"] = $score;
  29. $submission["user"] = $user;
  30. // Save submission as json file
  31. file_put_contents("$user.json",json_encode($submission));
  32. echo $score;
  33. }
  34. else // Show leaderboard
  35. {
  36. // flat files to "user"=>"score" array
  37. $scores = array();
  38. $files = scandir('.');
  39. foreach ($files as $index=>$fname) {
  40. if (substr($fname,-5)=='.json') {
  41. $json= json_decode(file_get_contents($fname), true);
  42. $scores[$json["user"]] = $json["score"];
  43. }
  44. }
  45. arsort($scores);
  46. // Format the leaderboard
  47. ?>
  48. <!DOCTYPE html>
  49. <html lang="en">
  50. <head>
  51. <title>NLP Named-Entity-Recognition Workshop</title>
  52. <meta charset="utf-8">
  53. <meta name="viewport" content="width=device-width, initial-scale=1">
  54. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
  55. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  56. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
  57. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
  58. <meta http-equiv="refresh" content="30" />
  59. </head>
  60. <body><div class="container" align="center">
  61. <h1>Leader board</h1>
  62. <table class="table table-striped">
  63. <thead>
  64. <tr>
  65. <th>Submission_id</th>
  66. <th>Accuracy</th>
  67. </tr>
  68. </thead>
  69. <tbody>
  70. <?php
  71. foreach($scores as $user => $score) {
  72. echo "<tr><th>$user</th><td>$score</td></tr>";
  73. }
  74. ?>
  75. </tbody></table>
  76. <br />
  77. Made by <a href="http://www.goren4u.com">Uri Goren</a>.
  78. </div></body></html>
  79. <?php
  80. }
  81. ?>
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...