Skip to main content

Build Status codecov.io

py-irt

Bayesian IRT models in Python

Overview

This repository includes code for fitting Item Response Theory (IRT) models using variational inference.

At present, the one parameter logistic (1PL) model, aka Rasch model, two parameter logistic model (2PL) and four parameter logistic model (4PL) have been implemented. The user can specify whether vague or hierarchical priors are used. The three-parameter logistic model is in the pipeline and will be added when available.

License

py-irt is licensed under the MIT license.

Installation

py-irt is now available on PyPi!

Pre-reqs

  1. Install PyTorch.
  2. Install Pyro
  3. Install py-irt:
pip install py-irt

OR

Install Poetry

git clone https://github.com/nd-ball/py-irt.git
cd py-irt
poetry install

Usage

Once you install from PyPI, you can use the following command to fit an IRT model on the scored predictions of a dataset. For example, if you were to run py-irt with the 4PL model on the scored predictions of different transformer models on the SQuAD dataset, you'd do this: py-irt train 4pl ~/path/to/dataset/eg/squad.jsonlines /path/to/output/eg/test-4pl/

Please see the EACL 2024 IRT4NLP tutorial which showcases py-irt usage from within Python and not from CLI.

FAQ

  1. What kind of output should I expect on running the command to train an IRT model?

You should see something like this when you run the command given above: image

  1. I tried installing py-irt using pip from PyPI. But when I try to run the command py-irt train 4pl ~/path/to/dataset/eg/squad.jsonlines /path/to/output/eg/test-4pl/, I get an error that says bash: py-irt: command not found. How do I fix this?

The CLI interface was implemented in PyPi version 0.2.1. If you are getting this error try updating py-irt:

pip install --upgrade py-irt

Alternatively, you can install the latest version from github:

git clone https://github.com/nd-ball/py-irt.git
cd py-irt
mv ~/py-irt/py_irt/cli.py ~/py-irt/
python cli.py train 4pl ~/path/to/dataset/eg/squad.jsonlines /path/to/output/eg/test-4pl/
  1. How do I evaluate a trained IRT model?

If you have already trained an IRT model you can use the following command:

py-irt evaluate 4pl ~/path/to/data/best_parameters.json ~/path/to/data/test_pairs.jsonlines /path/to/output/eg/test-4pl/

Where test_pairs.jsonlines is a jsonlines file with the following format:

{"subject_id": "ken", "item_id": "q1"}
{"subject_id": "ken", "item_id": "q2"}
{"subject_id": "burt", "item_id": "q1"}
{"subject_id": "burt", "item_id": "q3"}

If you would like to both train and evaluate a model you can use the following command:

py-irt train-and-evaluate 4pl ~/path/to/data/squad.jsonlines /path/to/output/eg/test-4pl/

By default this will train a model with 90% of the provided data and evaluate with the remaining 10%. To change this behavior you can add --evaluation all to the command above. The model will train and evaluate against all of the data.

Citations

If you use this code, please consider citing the following papers:

@inproceedings{lalor2019emnlp,
  author    = {Lalor, John P and Wu, Hao and Yu, Hong},
  title     = {Learning Latent Parameters without Human Response Patterns: Item Response Theory with Artificial Crowds},
  year      = {2019},
  booktitle = {Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing},
}
@inproceedings{rodriguez2021evaluation,
  title={Evaluation Examples Are Not Equally Informative: How Should That Change NLP Leaderboards?},
  author={Rodriguez, Pedro and Barrow, Joe and Hoyle, Alexander Miserlis and Lalor, John P and Jia, Robin and Boyd-Graber, Jordan},
  booktitle={Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers)},
  pages={4486--4503},
  year={2021}
}

Implementation is based on the following paper:

@article{natesan2016bayesian,
  title={Bayesian prior choice in IRT estimation using MCMC and variational Bayes},
  author={Natesan, Prathiba and Nandakumar, Ratna and Minka, Tom and Rubright, Jonathan D},
  journal={Frontiers in psychology},
  volume={7},
  pages={1422},
  year={2016},
  publisher={Frontiers}
}

Contributing

This is research code. Pull requests and issues are welcome!

Questions?

Let me know if you have any requests, bugs, etc.

Email: john.lalor@nd.edu

Release files for py-irt 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-irt 0.7.1
File Size Uploaded
py_irt-0.7.1.tar.gz 26.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-irt 0.7.1
File Interpreter ABI Platform
py_irt-0.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 73.4 kB

Release files / py_irt-0.7.1.tar.gz

Download URL py_irt-0.7.1.tar.gz
Size 26.6 kB
Tags Source
SHA-256 checksum
How to use checksums
915cf896064f54293bd76c2b4477ebe587fef7a4e0316718d9f687e5adf9651d
BLAKE2b-256 checksum
How to use checksums
2158fa85d0764863ac4ade8c9ef4ce28430fac0e57617c14cfaf1244f88ab7cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

Release files / py_irt-0.7.1-py3-none-any.whl

Download URL py_irt-0.7.1-py3-none-any.whl
Size 46.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d73c356d0dbacfcd6f022500bbc076f59c4bd924bba34ef676171d726cc86b00
BLAKE2b-256 checksum
How to use checksums
dd00a7dd74bf3539c04f66ab744a6a0023cb4de94bbea6e73a0e80960f0b7975
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

Release history Release notifications | RSS feed

This release

0.7.1 This release

2 release files

0.7.0

2 release files

0.6.6

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.13

2 release files

0.4.12

2 release files

0.4.11

2 release files

0.4.10

2 release files

0.4.9

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.1.1

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page