Skip to content

Commit

Permalink
add main README
Browse files Browse the repository at this point in the history
  • Loading branch information
DonaldLamNL committed Jan 9, 2024
1 parent 501ed3a commit e77a497
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 21 deletions.
63 changes: 61 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 = "<API key>"
temperature = <model temperature>
delay_time = <the seconds between each request>
model = "<the name of the 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/<name_exp>.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("<save_path>", "<new_save_name>")
```

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("<questionnaire_name>", "<specified_language>")
```


## 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!
Expand Down
48 changes: 29 additions & 19 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand All @@ -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)

0 comments on commit e77a497

Please sign in to comment.