Skip to main content

A minimal implementation of KaRR knowledge assessment method for Large Language Models (LLMs)

Project description

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 minkarr using the command:

pip install minkarr --extra-index-url https://download.pytorch.org/whl/cu121

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

from karr import KaRR
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = 'gpt2'
device = 'cuda'
model = AutoModelForCausalLM.from_pretrained(model_name, device_map = device)
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)

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},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

minkarr-0.1.2.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

minkarr-0.1.2-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file minkarr-0.1.2.tar.gz.

File metadata

  • Download URL: minkarr-0.1.2.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for minkarr-0.1.2.tar.gz
Algorithm Hash digest
SHA256 585aaf345aae83ff6ac9b9c2a28083d6fa0ecf96bda842e0da73ba6e19790f15
MD5 2e3193c408bc2c18691690e7738b65dd
BLAKE2b-256 3a2ada198069d5b2695eef991c08f609d9a141812d206844a34bf93243dc4ec3

See more details on using hashes here.

File details

Details for the file minkarr-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: minkarr-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for minkarr-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3c0331fad453a1d6f95ef407a33a8360fcf639fe8f93df4440c06dfa41f7ea62
MD5 4adaf3b5da7ea9800c2f08b96121022a
BLAKE2b-256 0958ef8fcc601b1a7662471d12ee2acfc96a0e77237e5f7d3a3a0c676b9adc0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page