Skip to main content

Insert a Lie in a Haystack and evaluate the model's ability to detect it.

Project description

🤥 LIAH - a Lie-in-haystack

LIAH

With longer context lengths for LLMs. It is increasingly difficult to test if fine tuned models attend to all depths of the context.

The needle in haystack is a popular approach. However since the LLMs can also answer about the needle instead of the needle. Tests have shown that a "Lie" works well in this context 😊

Lost in the Middle - Paper

lie: "Picasso painted the Mona Lisa"

retrieve: "Who painted the Mona Lisa?"

Installation

pip install liah

Example Usage

# update OPENAI_API_KEY in the env with your token.
# If you need Open AI models for the final evaluation
from liah import Liah
from vllm import LLM, SamplingParams

# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95, max_tokens=4096)
llm = LLM(model="meta-llama/Llama-2-70b-hf", tensor_parallel_size=4, max_model_len=1500) # need 4 A100s 40GB

#Create Liah
liah = Liah(max_context_length=2000)

#Get a sample from different depths and context_lengths
for i, sample in enumerate(liah.getSample()):
    # test the sample text with your model
    output = llm.generate([sample["prompt"]], sampling_params)[0]
    #Update liah with the response
    liah.update(sample, output.outputs[0].text)

#Contains the plot file from Liah
plotFilePath = liah.evaluate()

Sample plot

sample-plot

Contribute

bash
pip install pre-commit

then (in the repository, just once)

bash
pre-commit install

before commit (optional)

bash
pre-commit run --all-files

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

liah-0.1.6.tar.gz (251.0 kB view details)

Uploaded Source

Built Distribution

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

liah-0.1.6-py3-none-any.whl (253.6 kB view details)

Uploaded Python 3

File details

Details for the file liah-0.1.6.tar.gz.

File metadata

  • Download URL: liah-0.1.6.tar.gz
  • Upload date:
  • Size: 251.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.8

File hashes

Hashes for liah-0.1.6.tar.gz
Algorithm Hash digest
SHA256 d337c5c9c050aabca0da1473afede741de5fccc6f4a7ccba81e730205f2ca488
MD5 891459d07f94f86f704f9db494a1b58e
BLAKE2b-256 311518a7d169bb62d8614c554157ba8a180f2bafe9aa05a576b5a88eb76a4f23

See more details on using hashes here.

File details

Details for the file liah-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: liah-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 253.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.8

File hashes

Hashes for liah-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 80b87022b4d4f0ee8f254909dbf9bd17fc9fcf33b66ab41b46572f2e61b49d84
MD5 c80cb8d8e82addec4e0f856be4c0e4e6
BLAKE2b-256 990162b60bafd08cdd256453c82820a37617481011a820f82aad5479a32ba01a

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