From e77a49792850375cf4dcd6e2d56a70fb6e545a69 Mon Sep 17 00:00:00 2001 From: Donald Lam Date: Tue, 9 Jan 2024 20:52:24 +0800 Subject: [PATCH] add main README --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- server.py | 48 +++++++++++++++++++++++++----------------- 2 files changed, 90 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index a09ade3..a0c7e1a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,66 @@ # Reliability of Psychological Scales on LLMs: -## To-Do -Write the README. +## Execution Process + +### Create Utils File +An example `utils.py`: +```py +api_key = "" +temperature = +delay_time = +model = "" +``` + + +### Specify Test Cases +In `main.py`, specify the server parameters: +1. `template`: a list of prompt templates. +2. `version`: a list of question versions. +3. `language`: a list of language versions. +4. `label`: a list of level option labels. +5. `order`: a list of level orders. +6. `questionnaire_name`: the selected questionnaire. +7. `name_exp`: name of the save file. + +Start a `Server` class, all pre-testing cases are created and stored in `save/.json` +```py +test = Server(questionnaire_name, template, version, language, label, order, name_exp) +``` + +Load the saved file as a new save, a protection mechanism for test interruption +```py +test = load("", "") +``` + +Run for all pre-testing cases +```py +test.run() +``` + + +### An Example Run +```py +from server import * + +template = ['t1','t2','t3','t4','t5'] +version = ['v1','v2','v3','v4','v5'] +language = ['En', 'Zh', 'Ko', 'Es', 'Fr', 'De', 'It', 'Ar', 'Ru', 'Ja'] +label = ['n', 'al', 'au', 'rl', 'ru'] +order = ['r', 'f'] +questionnaire_name = 'BFI' +name_exp = 'bfi-save' + +bfi_test = Server(questionnaire_name, template, version, language, label, order, name_exp) +bfi_test.run() +``` + + +## Rephrase the Statements +In `main.py`, execute: +```py +rephrase("", "") +``` + ## References For more details, please refer to [this paper](https://arxiv.org/abs/2305.19926). Please remember to cite us if you find our work helpful in your work! diff --git a/server.py b/server.py index f21cfc0..c3839f9 100644 --- a/server.py +++ b/server.py @@ -75,7 +75,7 @@ def rephrase(questionnaire_name, language, savename=None): class Server: - def __init__(self, questionnaire_name, template, version, language, label, order, name_exp='save', basis=None, pending_tests=None, data=[]): + def __init__(self, questionnaire_name, template, version, language, label, order, name_exp='save', pending_tests=None, data=[]): self.name_exp = name_exp self.questionnaire_name = questionnaire_name self.template = template @@ -97,7 +97,7 @@ def __init__(self, questionnaire_name, template, version, language, label, order self.data = data self.questionnaire = get_questionnaire(questionnaire_name) self.model = model - self.basis = basis + self.initial_save() """ get_scales(): Extract the required scale level information and level description. @@ -215,9 +215,31 @@ def compute(self, mapped_responses): return result_dict """ - save(): Save the results in JSON format. + initial_save(): Save all pre-testing cases. """ - def save(self, test_info, raw_data, data): + def initial_save(self): + save_data = { + "meta": { + "name_exp": self.name_exp, + "questionnaire_name": self.questionnaire_name, + "template": self.template, + "version": self.version, + "language": self.language, + "label": self.label, + "order": self.order, + "pending_tests": self.pending_tests + }, + "data": [] + } + save_file_path = f'save/{self.name_exp}.json' + os.makedirs("save", exist_ok=True) + with open(save_file_path, 'w') as json_file: + json.dump(save_data, json_file, indent=2) + + """ + save_a_case(): Save a test result in JSON format. + """ + def save_a_case(self, test_info, raw_data, data): data = { "info": {**test_info}, "raw": raw_data, @@ -232,20 +254,8 @@ def save(self, test_info, raw_data, data): save_data["data"] += [data] save_data["meta"]["pending_tests"] = self.pending_tests except: - save_data = { - "meta": { - "name_exp": self.name_exp, - "questionnaire_name": self.questionnaire_name, - "template": self.template, - "version": self.version, - "language": self.language, - "label": self.label, - "order": self.order, - "pending_tests": self.pending_tests - }, - "data": [data] - } - + pass + with open(save_file_path, 'w') as json_file: json.dump(save_data, json_file, indent=2) if self.data: @@ -264,5 +274,5 @@ def run(self): data = self.start(test_info) compute_data = self.compute(data) self.pending_tests.remove(test_info) - self.save(test_info, data, compute_data) + self.save_a_case(test_info, data, compute_data) pbar.update(1)