Vipitis commited on
Commit
0d59e36
·
1 Parent(s): 681b67d

fix several errors

Browse files
Files changed (2) hide show
  1. ShaderEval.py +6 -5
  2. app.py +8 -6
ShaderEval.py CHANGED
@@ -158,7 +158,7 @@ class ReturnGenerationEvaluator(evaluate.TextGenerationEvaluator):
158
  class Suite(evaluate.EvaluationSuite):
159
 
160
 
161
- def __init__(self, name, snippet: int = ""):
162
  super().__init__(name)
163
  self.preprocessor = lambda x: {"return_statement": x["return_statement"].split(";")[0]} #like this? refactored to RetrunGenerationEvaluator
164
  self.suite = [
@@ -167,7 +167,7 @@ class Suite(evaluate.EvaluationSuite):
167
  task_type="text-generation", #this call an evaluator, but can you specify your own custom evaluator instead?
168
  data="Vipitis/Shadertoys-fine",
169
  subset="return_completion",
170
- split=f"test[:{snippet}]", # use this to select a subset of the data during testing, perhaps remove later?
171
  args_for_task={
172
  # "metric": "exact_match",
173
  "input_column": "body",
@@ -178,7 +178,8 @@ class Suite(evaluate.EvaluationSuite):
178
 
179
  # from: https://github.com/huggingface/evaluate/blob/v0.4.0/src/evaluate/evaluation_suite/__init__.py#LL103C5-L129C27
180
  def run(
181
- self, model_or_pipeline: Union[str, "Pipeline", Callable, "PreTrainedModel", "TFPreTrainedModel"] = "Vipitis/CodeGPT-small-java-adaptedGPT2-transfer-shadertoys" # noqa: F821 not so useful default model?
 
182
  ) -> Dict[str, float]:
183
 
184
  self.assert_suite_nonempty()
@@ -189,7 +190,7 @@ class Suite(evaluate.EvaluationSuite):
189
  task_name = task.data
190
 
191
  if task.data_preprocessor: # task requires extra preprocessing is all done inside the Evaluator
192
- ds = load_dataset(task.data, name=task.subset, split=task.split)
193
  task.data = ds.map(task.data_preprocessor)
194
 
195
  task_evaluator = ReturnGenerationEvaluator() #this is the change we make: specify our custom evaluator from above.
@@ -197,7 +198,7 @@ class Suite(evaluate.EvaluationSuite):
197
  args_for_task["model_or_pipeline"] = model_or_pipeline
198
  args_for_task["data"] = task.data
199
  args_for_task["subset"] = task.subset
200
- args_for_task["split"] = task.split
201
  results = task_evaluator.compute(**args_for_task)
202
 
203
  results["task_name"] = task_name + "/" + task.subset if task.subset else task_name
 
158
  class Suite(evaluate.EvaluationSuite):
159
 
160
 
161
+ def __init__(self, name):
162
  super().__init__(name)
163
  self.preprocessor = lambda x: {"return_statement": x["return_statement"].split(";")[0]} #like this? refactored to RetrunGenerationEvaluator
164
  self.suite = [
 
167
  task_type="text-generation", #this call an evaluator, but can you specify your own custom evaluator instead?
168
  data="Vipitis/Shadertoys-fine",
169
  subset="return_completion",
170
+ split="test", # use this to select a subset of the data during testing, perhaps remove later?
171
  args_for_task={
172
  # "metric": "exact_match",
173
  "input_column": "body",
 
178
 
179
  # from: https://github.com/huggingface/evaluate/blob/v0.4.0/src/evaluate/evaluation_suite/__init__.py#LL103C5-L129C27
180
  def run(
181
+ self, model_or_pipeline: Union[str, "Pipeline", Callable, "PreTrainedModel", "TFPreTrainedModel"] = "Vipitis/CodeGPT-small-java-adaptedGPT2-transfer-shadertoys", #not so useful default model?
182
+ snippet: int = "" # noqa: F821
183
  ) -> Dict[str, float]:
184
 
185
  self.assert_suite_nonempty()
 
190
  task_name = task.data
191
 
192
  if task.data_preprocessor: # task requires extra preprocessing is all done inside the Evaluator
193
+ ds = load_dataset(task.data, name=task.subset, split=(task.split + f"[:{snippet}]"))
194
  task.data = ds.map(task.data_preprocessor)
195
 
196
  task_evaluator = ReturnGenerationEvaluator() #this is the change we make: specify our custom evaluator from above.
 
198
  args_for_task["model_or_pipeline"] = model_or_pipeline
199
  args_for_task["data"] = task.data
200
  args_for_task["subset"] = task.subset
201
+ args_for_task["split"] = (task.split + f"[:{snippet}]") #make a downselection of the split via keywordarg in the .run() call?
202
  results = task_evaluator.compute(**args_for_task)
203
 
204
  results["task_name"] = task_name + "/" + task.subset if task.subset else task_name
app.py CHANGED
@@ -1,13 +1,15 @@
1
  import gradio as gr
2
  import evaluate
3
- from ShaderEval import Suite
4
 
5
- # suite = evaluate.EvaluationSuite.load("Vipitis/ShaderEval") #downloads it
6
- suite = Suite("Vipitis/ShaderEval") #local to the space?
 
 
 
7
 
8
  def run_suite(model_cp, snippet):
9
- suite = Suite("Vipitis/ShaderEval", snippet)
10
- results = suite.run(model_cp)
11
  return results[0]["exact_match"]
12
 
13
  with gr.Blocks() as site:
@@ -30,7 +32,7 @@ with gr.Blocks() as site:
30
  - Click **Run** to run the suite
31
  - The results will be displayed in the **Output** box
32
  """)
33
- model_cp = gr.Textbox(label="Model Checkpoint")
34
  first_n = gr.Slider(minimum=1, maximum=100, default=10, label="num_samples", step=1.0)
35
  output = gr.Textbox(label="Output")
36
  run_button = gr.Button(label="Run")
 
1
  import gradio as gr
2
  import evaluate
 
3
 
4
+ suite = evaluate.EvaluationSuite.load("Vipitis/ShaderEval") #downloads it
5
+
6
+ #TODO: can you import it locally instead?
7
+ # from ShaderEval import Suite
8
+ # suite = Suite("Vipitis/ShaderEval")
9
 
10
  def run_suite(model_cp, snippet):
11
+ # print(model_cp, snippet)
12
+ results = suite.run(model_cp, snippet)
13
  return results[0]["exact_match"]
14
 
15
  with gr.Blocks() as site:
 
32
  - Click **Run** to run the suite
33
  - The results will be displayed in the **Output** box
34
  """)
35
+ model_cp = gr.Textbox(value="gpt2", label="Model Checkpoint", interactive=True)
36
  first_n = gr.Slider(minimum=1, maximum=100, default=10, label="num_samples", step=1.0)
37
  output = gr.Textbox(label="Output")
38
  run_button = gr.Button(label="Run")