Prepare data for generation
mainThe TrustLLM datasets are structured as JSON files containing a collection of dictionaries. To prepare for evaluation:
- Input: Use the value associated with the
promptkey in each dictionary as the input for your LLM. - Output: After generating a response, store the LLM's output in a new key named
reswithin the same dictionary.
Warning: Ensure the LLM used for evaluation has sufficient utility/NLP capabilities; weak generation capabilities may bias results by producing invalid samples.
import json
filename = 'dataset_path.json'
# Load the data from the file
with open(filename, 'r') as file:
data = json.load(file)
# Process each dictionary and add the 'res' key with the generated output
for element in data:
# Replace 'generation' with your actual LLM calling function
element['res'] = generation(element['prompt'])
# Write the modified data back to the file
with open(filename, 'w') as file:
json.dump(data, file, indent=4)