Spaces:
Sleeping
Sleeping
Fix divide by zero error.
Browse files- .gitignore +2 -0
- database.sqlite +0 -0
- execution_accuracy.py +11 -1
- test.py +43 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.database.sqlite
|
| 2 |
+
.test.py
|
database.sqlite
ADDED
|
Binary file (8.19 kB). View file
|
|
|
execution_accuracy.py
CHANGED
|
@@ -80,6 +80,8 @@ class ExecutionAccuracy(evaluate.Metric):
|
|
| 80 |
features=datasets.Features({
|
| 81 |
'predictions': datasets.Value('string'),
|
| 82 |
'references': datasets.Value('string'),
|
|
|
|
|
|
|
| 83 |
}),
|
| 84 |
# Homepage of the module for documentation
|
| 85 |
homepage="http://module.homepage",
|
|
@@ -116,7 +118,15 @@ class ExecutionAccuracy(evaluate.Metric):
|
|
| 116 |
# If only the reference passes the filter, count it
|
| 117 |
elif pred_bool != ref_bool:
|
| 118 |
divider += 1
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
accuracy = sum(execute_func(i) == execute_func(j) for i, j in zip(filtered_predictions, filtered_references)) / divider
|
| 121 |
|
| 122 |
return {
|
|
|
|
| 80 |
features=datasets.Features({
|
| 81 |
'predictions': datasets.Value('string'),
|
| 82 |
'references': datasets.Value('string'),
|
| 83 |
+
'execute_func': datasets.Value(),
|
| 84 |
+
'filter_func': datasets.Value(),
|
| 85 |
}),
|
| 86 |
# Homepage of the module for documentation
|
| 87 |
homepage="http://module.homepage",
|
|
|
|
| 118 |
# If only the reference passes the filter, count it
|
| 119 |
elif pred_bool != ref_bool:
|
| 120 |
divider += 1
|
| 121 |
+
else:
|
| 122 |
+
filtered_predictions = predictions
|
| 123 |
+
filtered_references = references
|
| 124 |
+
divider = len(predictions)
|
| 125 |
+
|
| 126 |
+
# If all preds and refs are filtered, execution accuracy makes no sense
|
| 127 |
+
if divider == 0:
|
| 128 |
+
divider = -1
|
| 129 |
+
|
| 130 |
accuracy = sum(execute_func(i) == execute_func(j) for i, j in zip(filtered_predictions, filtered_references)) / divider
|
| 131 |
|
| 132 |
return {
|
test.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from evaluate import load
|
| 2 |
+
import sqlite3
|
| 3 |
+
|
| 4 |
+
module = load("LuckiestOne/valid_efficiency_score")
|
| 5 |
+
|
| 6 |
+
# Create connection to the database
|
| 7 |
+
database_path = "database.sqlite"
|
| 8 |
+
connection = sqlite3.connect(database_path)
|
| 9 |
+
# Cursor
|
| 10 |
+
cursor = connection.cursor()
|
| 11 |
+
|
| 12 |
+
# Create table
|
| 13 |
+
cursor.execute('''CREATE TABLE IF NOT EXISTS Player
|
| 14 |
+
(PlayerID INTEGER PRIMARY KEY,
|
| 15 |
+
PlayerName TEXT NOT NULL);''')
|
| 16 |
+
|
| 17 |
+
# Insert a row of data
|
| 18 |
+
cursor.execute("INSERT INTO Player VALUES (1, 'Cristiano Ronaldo')")
|
| 19 |
+
cursor.execute("INSERT INTO Player VALUES (2, 'Lionel Messi')")
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# Define the function that will execute the SQL queries
|
| 23 |
+
def execute(sql_query):
|
| 24 |
+
# Execute the SQL queries
|
| 25 |
+
|
| 26 |
+
cursor.execute(sql_query)
|
| 27 |
+
result = cursor.fetchall()
|
| 28 |
+
return result
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
sql_queries_pred = [
|
| 32 |
+
"SELECT COUNT(*) FROM Player WHERE PlayerName = 'Cristiano Ronaldo'",
|
| 33 |
+
"SELECT COUNT(*) FROM Player WHERE PlayerName = 'Lionel Messi'"
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
+
sql_queries_ref = [
|
| 37 |
+
"SELECT COUNT(*) FROM Player WHERE PlayerName = 'Cristiano Ronaldo'",
|
| 38 |
+
"SELECT COUNT(*) FROM Player WHERE PlayerName = 'Lionel Messi'"
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
# Compute the score
|
| 42 |
+
results = module.compute(predictions=sql_queries_pred, references=sql_queries_ref, execute=execute)
|
| 43 |
+
print(results)
|