Skip to content

Commit

Permalink
#67 work-in-progress for code concepts (still not working)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtran421 committed Dec 18, 2022
1 parent 172a1f6 commit cf64609
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 64 deletions.
5 changes: 2 additions & 3 deletions codewit_semeru/backend/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def query_model(self):
"POST", self.api_url, headers=headers, data=data)
return json.loads(response.content.decode("utf-8"))

# TODO: Update so output doesn't contain input sequence!

def run(self) -> None:
res = self.query_model()
Expand Down Expand Up @@ -127,8 +126,8 @@ def convert_to_python_code(self, output_sequence: str) -> str:


def parse_code_concepts(self):
print(self.dataset[1] + self.output_seqs[1])
tree = ast.parse(self.convert_to_python_code(self.dataset[1] + self.output_seqs[1]))
print(self.output_seqs[1])
tree = ast.parse(self.convert_to_python_code(self.output_seqs[1]))

# Initialize counters for each type of node or expression
function_body_types = {
Expand Down
1 change: 0 additions & 1 deletion codewit_semeru/frontend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def update_data_and_chart(self, selected_model: str, selected_dataset: List[str]
return fig

def run(self) -> None:
# TODO: update so bar chart doesn't include input sequence in analyzed tokens! Only predicted tokens.
# TODO: update so string representations of tokens are shown rather than tokens themselves
@self.app.callback(Output("graph1", "figure"), Input("dataset_dropdown_1", "value"), Input("model_dropdown_1", "value"), Input("desc_stats_1", "value"))
def update_bar_graph1(selected_dataset: List[str] = self.dataset_1, selected_model: str = self.model_1, selected_stat: str = "mean"):
Expand Down
65 changes: 5 additions & 60 deletions test_display.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -13,24 +13,9 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Found cached dataset code_x_glue_cc_code_completion_line (/Users/dtran/.cache/huggingface/datasets/code_x_glue_cc_code_completion_line/python/0.0.0/4ce8a216b87c5b130aad675f2bbf3612cc1f7fa5dbdc2fcb9c412765cf7830a7)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"<s> from __future__ import absolute_import <EOL> import httpretty <EOL> import pygerduty <EOL> import textwrap <EOL> @ httpretty . activate <EOL> def test_get_user ( ) : <EOL> httpretty . register_uri ( <EOL> httpretty . GET , \"\" , <EOL> body = textwrap . dedent ( ) , status = 200 ) <EOL> p = pygerduty . PagerDuty ( \"contosso\" , \"password\" ) <EOL> user = p . users . show ( \"PIJ90N7\" ) <EOL> assert user .\n"
]
}
],
"outputs": [],
"source": [
"from datasets.load import load_dataset\n",
"import pandas as pd\n",
Expand All @@ -52,49 +37,9 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Querying HF Inference API, this will take a moment...\n",
"Pipeline completed for pipe gpt2<>4b21447d-eaea-4a1a-889a-2b6aa8547654\n",
"<s> from __future__ import absolute_import <EOL> import httpretty <EOL> import pygerduty <EOL> import textwrap <EOL> @ httpretty . activate <EOL> def test_get_user ( ) : <EOL> httpretty . register_uri ( <EOL> httpretty . GET , \"\" , <EOL> body = textwrap . dedent ( ) , status = 200 ) <EOL> p = pygerduty . PagerDuty ( \"contosso\" , \"password\" ) <EOL> user = p . users . show ( \"PIJ90N7\" ) <EOL> assert user . user == status { 'error' : user,'reply' : user } print ( 'PJ90N7' ) print ( p. status == 200 ) body. print ( 'PJ90N7'. count ( ) )\n",
"from __future__ import absolute_import \n",
"import httpretty \n",
"import pygerduty \n",
"import textwrap \n",
"@httpretty .activate \n",
"def test_get_user ():\n",
" httpretty .register_uri (\n",
" httpretty .GET , \"\" ,\n",
" body =textwrap .dedent (),status =200 )\n",
" p =pygerduty .PagerDuty ( \"contosso\" , \"password\" )\n",
" user =p .users .show ( \"PIJ90N7\" )\n",
" assert user .user ==status { 'error' :user,'reply' :user }print ( 'PJ90N7' )print (p.status ==200 )body.print ( 'PJ90N7'.count ())\n",
"\n"
]
},
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<unknown>, line 12)",
"output_type": "error",
"traceback": [
"Traceback \u001b[0;36m(most recent call last)\u001b[0m:\n",
" File \u001b[1;32m~/opt/anaconda3/envs/wit-env/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3398\u001b[0m in \u001b[1;35mrun_code\u001b[0m\n exec(code_obj, self.user_global_ns, self.user_ns)\n",
" Input \u001b[1;32mIn [17]\u001b[0m in \u001b[1;35m<cell line: 1>\u001b[0m\n WITCode(\"gpt2\", pruned_dataset)\n",
" File \u001b[1;32m~/Documents/College 22-23/Software Engineering/csci-435_what_if_tool/codewit_semeru/__init__.py:17\u001b[0m in \u001b[1;35mWITCode\u001b[0m\n server = CodeWITServer(model, dataset, dataset_id)\n",
" File \u001b[1;32m~/Documents/College 22-23/Software Engineering/csci-435_what_if_tool/codewit_semeru/frontend/server.py:41\u001b[0m in \u001b[1;35m__init__\u001b[0m\n pipes.run_pipelines()\n",
" File \u001b[1;32m~/Documents/College 22-23/Software Engineering/csci-435_what_if_tool/codewit_semeru/backend/pipeline_store.py:30\u001b[0m in \u001b[1;35mrun_pipelines\u001b[0m\n pipe.run()\n",
" File \u001b[1;32m~/Documents/College 22-23/Software Engineering/csci-435_what_if_tool/codewit_semeru/backend/pipeline.py:84\u001b[0m in \u001b[1;35mrun\u001b[0m\n self.parse_code_concepts()\n",
" File \u001b[1;32m~/Documents/College 22-23/Software Engineering/csci-435_what_if_tool/codewit_semeru/backend/pipeline.py:131\u001b[0m in \u001b[1;35mparse_code_concepts\u001b[0m\n tree = ast.parse(self.convert_to_python_code(self.dataset[1] + self.output_seqs[1]))\n",
"\u001b[0;36m File \u001b[0;32m~/opt/anaconda3/envs/wit-env/lib/python3.9/ast.py:50\u001b[0;36m in \u001b[0;35mparse\u001b[0;36m\u001b[0m\n\u001b[0;31m return compile(source, filename, mode, flags,\u001b[0m\n",
"\u001b[0;36m File \u001b[0;32m<unknown>:12\u001b[0;36m\u001b[0m\n\u001b[0;31m assert user .user ==status { 'error' :user,'reply' :user }print ( 'PJ90N7' )print (p.status ==200 )body.print ( 'PJ90N7'.count ())\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"outputs": [],
"source": [
"WITCode(\"gpt2\", pruned_dataset)"
]
Expand Down

0 comments on commit cf64609

Please sign in to comment.