Skip to main content

Statistical Knowledge Assessment for Large Language Models

A minimal implementation of KaRR knowledge assessment method from the following paper:

Statistical Knowledge Assessment for Large Language Models,
Qingxiu Dong, Jingjing Xu, Lingpeng Kong, Zhifang Sui, Lei Li
arXiv preprint (arxiv_version)

This is a fork of the official implementation released by the authors.

How to use?

First, create a new virtual environment, then install Pytorch-CUDA, and finally install minkarr using the command:

pip install minkarr

Here is a simple example of how to quantify the knowledge of a fact by an LLM using KaRR

from minkarr import KaRR
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "gpt2"
device = "cuda"
model = AutoModelForCausalLM.from_pretrained(model_name).cuda()
tokenizer = AutoTokenizer.from_pretrained(model_name)

karr = KaRR(model, tokenizer, device)

# Testing the fact: (France, capital, Paris)
# You can find other facts by looking into Wikidata
fact = ("Q142", "P36", "Q90")

karr, does_know = karr.compute(fact)
print("Fact %s" % str(fact))
print("KaRR = %s" % karr)
ans = "Yes" if does_know else "No"
print("According to KaRR, does the model knows this fact? Answer: %s" % ans)
# Output:
# KaRR = 3.338972442145268
# According to KaRR, does the model knows this fact? Answer: No

Difference with original repo

  • Easy-to-use
  • Cleaner code
  • Minimalistic implementation: I kept only the portion of the code needed to compute KaRR and removed the rest
  • This implementation can compute KaRR on a single fact (the original implementation went through all facts)

Change storage location

Set the environment variable STORAGE_FOLDER to choose where to store the data that MinKaRR downloads.

Citation

Cite the original authors using:

@misc{dong2023statistical,
      title={Statistical Knowledge Assessment for Large Language Models}, 
      author={Qingxiu Dong and Jingjing Xu and Lingpeng Kong and Zhifang Sui and Lei Li},
      year={2023},
      journal = {Proceedings of NeurIPS},
}

Metadata

Release files for minkarr 0.1.7

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

Source distribution (sdist)

Source distribution for minkarr 0.1.7
File Size Uploaded Provenance Actions
minkarr-0.1.7.tar.gz 96.4 kB Without provenance Details for minkarr-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for minkarr 0.1.7
File Interpreter ABI Platform Actions
minkarr-0.1.7-py3-none-any.whl Python 3 none any Details for minkarr-0.1.7-py3-none-any.whl

Total release size: 107.6 kB

Release files / minkarr-0.1.7.tar.gz

Download URL minkarr-0.1.7.tar.gz
Size 96.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2da22cbf8531151b82d7fef8418153ecc6b611c88180dd15506265a9792064c2
BLAKE2b-256 checksum
How to use checksums
9c29ae3942dd1c9ca599805371fec3b97bf4695746052d5e4291520d834af805
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.10

Release files / minkarr-0.1.7-py3-none-any.whl

Download URL minkarr-0.1.7-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b6c34aadf801dee638833c70e17ddec9c015279e4dca320b44fe79e549d6e48
BLAKE2b-256 checksum
How to use checksums
38ef9cb051e8d4ab01aef70ca491600e1b748463108ba41c4e31bf6bb923c934
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.10

Security for minkarr 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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