Get Started

RUPsycho: A Python Package for Social Science Research Using Large Language Models (LLMs)

RUPsycho is a Python package designed to facilitate the application of large language models (LLMs) in social science research. It offers tools to explore human-like behaviors through LLMs, providing a novel approach in the field of natural language processing (NLP).

This module within RUPsycho provides functions to load and validate experimental data from JSON dictionaries and files. It supports both single and multiple experiment loading, making it easy to manage and analyze experiments in various formats.

Functions

  • experiment_from_dict(json_data: dict) -> ExperimentDocument:

    Load a single experiment from a JSON dictionary.

  • experiment_from_file(path: str) -> ExperimentDocument:

    Load a single experiment from a JSON file.

  • experiments_from_dicts(json_data_list: List[dict]) -> Iterator[ExperimentDocument]:

    Load multiple experiments from a list of JSON dictionaries.

  • experiments_from_files(paths: List[str]) -> Iterator[ExperimentDocument]:

    Load multiple experiments from a list of JSON files.

Usage

  • Single Experiment Loading:
    • Use experiment_from_dict for loading an experiment from an in-memory JSON dictionary.

    • Use experiment_from_file for loading an experiment from a JSON file.

  • Multiple Experiments Loading:
    • Use experiments_from_dicts to load multiple experiments from a list of JSON dictionaries.

    • Use experiments_from_files to load multiple experiments from a list of JSON files.

Example

After importing RUPsycho, you can start using it in your Python script or Jupyter notebook:

import rupsycho as rup

# Load experiment data experiment = rup.experiment_from_file(“bfi.json”)

# Run the experiment experiment.run()

# Save the results experiment.export_to_file(“results.json”)

For more detailed examples and usage, refer to the official RUPsycho documentation.

rupsycho.experiment_from_dict(json_data)[source]

Create a new experiment from a JSON dictionary.

Parameters:

json_data (dict)

Return type:

ExperimentDocument

rupsycho.experiment_from_file(path)[source]

Create a new experiment from a JSON file.

Parameters:

path (str)

Return type:

ExperimentDocument

rupsycho.experiments_from_dicts(json_data_list)[source]

Create multiple experiments from a list of JSON dictionaries.

Parameters:

json_data_list (List[dict])

Return type:

Iterator[ExperimentDocument]

rupsycho.experiments_from_files(path_pattern)[source]

Create multiple experiments from a list of JSON files.

Parameters:

path_pattern (str)

Return type:

Iterator[ExperimentDocument]

rupsycho.example_experiment_bfi(model_name='google/flan-t5-small', pipeline_type='text2text-generation', temperature=0.7, max_new_tokens=128, api_key=None)[source]

Create an example experiment with a specified model, pipeline type, and generative parameters.

Parameters:
  • model_name (str) – Name of the Hugging Face model to use.

  • pipeline_type (str) – Type of pipeline to use (e.g., ‘text2text-generation’).

  • temperature (float) – Temperature setting for the generative model.

  • max_new_tokens (int) – Maximum number of new tokens to generate.

  • api_key (str | None) – Optional Hugging Face API key for accessing gated models.

Returns:

Configured ExperimentDocument.

Return type:

ExperimentDocument