Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c2a2116
added length_calculator
Apr 14, 2023
529edce
re-upload the implementation for llama, alpaca, santacoder
yilunzhao Apr 25, 2023
7caf0ea
Merge branch 'main' into yilunzhao/llm_implementation
yilunzhao Apr 25, 2023
9dbc8cd
try to pass CI check
yilunzhao Apr 26, 2023
06c7858
Merge branch 'main' into yilunzhao/llm_implementation
niansong1996 Apr 27, 2023
ce36f13
modify process_output function in exectutor.py to handle the case tha…
yilunzhao Apr 27, 2023
60fd89b
fix error related to llama eos_token
yilunzhao May 5, 2023
83546d9
add starcoder, gpt-neox-20b; test gpt-j-6b
yilunzhao May 6, 2023
86d3bd5
archieve code for NeurIPS exps; add gpt-4, pythia, replit, dolly, sta…
yilunzhao May 19, 2023
d10a59a
added dataset and executor for DS1000
Jun 28, 2023
a9df68b
Merge branch 'main' into rui/ds-1000
Jun 28, 2023
40c02b5
removed all .DS_Store
Jun 28, 2023
af3ffa2
added ds1000 prompt file
Jun 29, 2023
2bfee22
fixed missing file and added ds1000 prompt file
Jun 29, 2023
9e8b571
zipped ds1000_data and removed irrelevant files
Jun 29, 2023
fb089c0
class variable ds_data now initialize in init
rays1024 Jul 5, 2023
cfb10c7
Merge remote-tracking branch 'origin/yilunzhao/llm_implementation' in…
rays1024 Jul 5, 2023
adb4c79
fixed ds1000 gpt-neo-125M evaluation bugs
rays1024 Jul 5, 2023
39a4fd4
some code clean up
rays1024 Jul 5, 2023
0ecdb5f
included reference code in prompt
rays1024 Jul 5, 2023
5666a22
updated ds1000.yaml
rays1024 Jul 14, 2023
27e0e70
fixed evaluation error at 158/159th problem
rays1024 Jul 16, 2023
4ba669d
fixed evaluation bug
rays1024 Jul 16, 2023
dc4fc0c
fixed torch tensor bug
rays1024 Jul 21, 2023
62250c5
undo changes caused by wrong jsonargparse version
rays1024 Jul 25, 2023
f7e930b
fixed ds1000 saving issue
rays1024 Jul 27, 2023
1ed0607
Revert "fixed ds1000 saving issue"
rays1024 Jul 27, 2023
90cba4f
fixed result saving issue
rays1024 Jul 27, 2023
4229001
evaluating raw output without cutting off at keywords
rays1024 Jul 31, 2023
b787508
No custom instruction and using only DS1000 prompt
rays1024 Jul 31, 2023
73b9676
reverted raw output and uses keyword cutoff in execution
rays1024 Aug 1, 2023
d41eb3b
no cutoff at execution to check raw output
rays1024 Aug 1, 2023
5fad2f3
updated gitignore
rays1024 Aug 2, 2023
b3aa6ba
execution now preprocess model output
rays1024 Aug 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Comment thread
rays1024 marked this conversation as resolved.
Outdated
Binary file not shown.
88 changes: 88 additions & 0 deletions length_calculator.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably put this file in analysis or utils or preprocessing

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import json
import argparse
import numpy as np
from transformers import GPT2Tokenizer
# from execution.executors import sql_program_len, python_program_len
from ds1000.ds1000 import DS1000Dataset

def sql_program_len(code: str) -> int:
""" return the length of the sql query """
return len(list(filter(lambda x: not len(x.strip()) == 0, code.split())))

def python_program_len(code: str) -> int:
""" return the length of the python program """
return len(list(filter(lambda x: not x.startswith("#") and not len(x.strip()) == 0, code.split("\n"))))


TOKENIZER = GPT2Tokenizer.from_pretrained('gpt2')

def load_ds1000():
ds_data = DS1000Dataset("ds1000/ds1000_data") # loads all questions into RAM
return ds_data


def parse_arg() -> tuple[str, str]:
parser = argparse.ArgumentParser(description='Process a file at the specified path')

parser.add_argument('path', type=str, help='the path of the file to process')

choices = ['mbpp', 'gsmath', 'spider', 'ds1000']
parser.add_argument('--dataset', type=str, default='mbpp', choices=choices, help='the name of the dataset to use')

args = parser.parse_args()

path = args.path
dataset = args.dataset

return path, dataset

def generate_length(lines, dataset):
NL_lengths = []

program_lengths = []

extra_info_lengths = []

if dataset == "ds1000":
ds_data = load_ds1000()
for key in ds_data.data.keys():
for data in ds_data[key]:
program_lengths.append(python_program_len(data['reference_code']))
extra_info_lengths.append(python_program_len(data['prompt']))
print(data['ans'])

for line in lines:
data = json.loads(line)

if dataset == "mbpp":
NL_lengths.append(len(TOKENIZER.encode(data['text'])))
program_lengths.append(python_program_len(data['code']))

elif dataset == "gsmath":
question_length = len(TOKENIZER.encode(data['question']))
NL_lengths.append(question_length)

elif dataset == "spider":
NL_lengths.append(len(TOKENIZER.encode(data['question'])))
program_lengths.append(sql_program_len(data['query']))
extra_info_lengths.append(len(TOKENIZER.encode(str(data['db_table_headers']))))


if NL_lengths:
print("Average length of natural language input: {:.2f}".format(np.mean(NL_lengths)))
print("90% percentile of length of natural language input: {:.2f}".format(np.percentile(NL_lengths, 90)))
print("99% percentile of length of natural language input: {:.2f}".format(np.percentile(NL_lengths, 99)))
if program_lengths:
print("Average length of reference program: {:.2f}".format(np.mean(program_lengths)))
if extra_info_lengths:
print("Average length of extra information: {:.2f}".format(np.mean(extra_info_lengths)))

def main():
path, dataset = parse_arg()

with open(path, 'r') as f:
lines = f.readlines()

generate_length(lines, dataset)

main()