| """Generate json file for webpage.""" |
| import json |
| import os |
| import re |
|
|
| |
| models = ['vicuna'] |
|
|
|
|
| def read_jsonl(path: str, key: str=None): |
| data = [] |
| with open(os.path.expanduser(path)) as f: |
| for line in f: |
| if not line: |
| continue |
| data.append(json.loads(line)) |
| if key is not None: |
| data.sort(key=lambda x: x[key]) |
| data = {item[key]: item for item in data} |
| return data |
|
|
|
|
| def trim_hanging_lines(s: str, n: int) -> str: |
| s = s.strip() |
| for _ in range(n): |
| s = s.split('\n', 1)[1].strip() |
| return s |
|
|
|
|
| if __name__ == '__main__': |
| questions = read_jsonl('table/question.jsonl', key='question_id') |
|
|
| |
| |
| |
| |
| vicuna_answers = read_jsonl('table/answer/answer_vicuna-13b.jsonl', key='question_id') |
| ours_answers = read_jsonl('table/results/llama-13b-hf-alpaca.jsonl', key='question_id') |
|
|
| review_vicuna = read_jsonl('table/review/review_vicuna-13b_llama-13b-hf-alpaca.jsonl', key='question_id') |
| |
| |
| |
| |
|
|
| records = [] |
| for qid in questions.keys(): |
| r = { |
| 'id': qid, |
| 'category': questions[qid]['category'], |
| 'question': questions[qid]['text'], |
| 'answers': { |
| |
| |
| |
| |
| 'vicuna': vicuna_answers[qid]['text'], |
| 'ours': ours_answers[qid]['text'], |
| }, |
| 'evaluations': { |
| |
| |
| |
| 'vicuna': review_vicuna[qid]['content'], |
| |
| }, |
| 'scores': { |
| 'vicuna': review_vicuna[qid]['tuple'], |
| |
| |
| |
| |
| }, |
| } |
|
|
| |
| cleaned_evals = {} |
| for k, v in r['evaluations'].items(): |
| v = v.strip() |
| lines = v.split('\n') |
| |
| if re.match(r'\d+[, ]+\d+', lines[0]): |
| lines = lines[1:] |
| v = '\n'.join(lines) |
| cleaned_evals[k] = v.replace('Assistant 1', "**Assistant 1**").replace('Assistant 2', '**Assistant 2**') |
|
|
| r['evaluations'] = cleaned_evals |
| records.append(r) |
|
|
| |
| for r in records: |
| if r['id'] <= 20: |
| r['id'] += 60 |
| else: |
| r['id'] -= 20 |
| for r in records: |
| if r['id'] <= 50: |
| r['id'] += 10 |
| elif 50 < r['id'] <= 60: |
| r['id'] -= 50 |
| for r in records: |
| if r['id'] == 7: |
| r['id'] = 1 |
| elif r['id'] < 7: |
| r['id'] += 1 |
|
|
| records.sort(key=lambda x: x['id']) |
|
|
| |
| with open('webpage/data.json', 'w') as f: |
| json.dump({'questions': records, 'models': models}, f, indent=2) |
|
|