Skip to main content

Making Transformers Obvious

Project description

obvs: A Python Library for Analyzing and Interpreting Language Models

The obvs library is a powerful Python package that provides a comprehensive set of tools and utilities for analyzing and interpreting language models using the patchscope framework. It offers a range of functionalities to probe and understand the internal representations and behaviors of language models at different layers and positions.

With obvs, you can easily investigate how language models process and generate text, gain insights into their inner workings, and visualize the results using various techniques such as heatmaps and plots. Whether you are a researcher, data scientist, or language model enthusiast, obvs empowers you to conduct interpretability experiments and reproduce standard results with ease.

Installation

To install the obvs library, you can use pip:

pip install obvs

Make sure you have Python >=3.10 installed on your system.

Entity Resolution Example.

Here's a simple example demonstrating how to use the TokenIdentity lens from the obvs library:

from obvs.lenses import TokenIdentity

token_identity = TokenIdentity(source_prompt="The quick brown fox", model_name="gpt2", source_phrase="quick brown")
token_identity.run().compute_surprisal("fox").visualize()

This code snippet creates an instance of the TokenIdentity lens, specifying the source prompt, model name, and source phrase. It then runs the lens analysis, computes the surprisal for the word "fox", and visualizes the results.

Activation Patching Example.

"The Collosseum is in the city of Paris" activation patching example.

from obvs.patchscope import Patchscope, SourceContext, TargetContext

MODEL="gpt2"
source=SourceContext(
    model_name=MODEL,
    prompt="The Eiffel Tower is in the city of",
    layer=10,
    position=9,
)

target=TargetContext(
    model_name=MODEL,
    prompt="The Colosseum is in the city of",
    layer=10,
    position=9,
    max_new_tokens=1
)

patchscope=Patchscope(source, target)
patchscope.run()

print(patchscope.full_output())

For more examples and usage, please refer to the tutorials, documentation, and PyPI.

Development setup

To set up the development environment for obvs, follow these steps:

  1. Clone the repository:

    git clone https://github.com/yourname/obvs.git
    
  2. Install the development dependencies:

    poetry install --no-root --sync
    
  3. Run the test suite:

    pytest tests/
    

Make sure you have Python 3.10 or above and the required dependencies installed.

Release History

  • 0.1.1
    • Initial release of the obvs library
    • Includes patchscope, patchscope_base, lenses, logging, and metrics modules
    • Provides a collection of scripts for reproducing standard results

Meta

For assistance, reach out to Jamie Coombes – www.linkedin.com/in/ jamiecoombes – obvslib@protonmail.com

Distributed under the MIT license. See LICENSE for more information.

Contributing

We welcome contributions to the obvs library! See CONTRIBUTING for more information.

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

obvs-0.1.2.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

obvs-0.1.2-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: obvs-0.1.2.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Darwin/22.6.0

File hashes

Hashes for obvs-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e54767341a2653deb11efa7fb15e9f9a94a84d70a98647233b9838f00b796dd5
MD5 748fd96aec0d345437ae6c10712089a4
BLAKE2b-256 a332a14f654adadb996f73ff3348e976ec737d14a921b484cffa94b7f9007022

See more details on using hashes here.

File details

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

File metadata

  • Download URL: obvs-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Darwin/22.6.0

File hashes

Hashes for obvs-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c746dca5112e9c8b018031ddc82a6bb7a7bfa9fed477fa4f284a939820bbd257
MD5 ff646b298699b0de3fcc994640f0853c
BLAKE2b-256 d357f67f989d293780b60a2445abd4fe14020d781e83305c316a35f9e2aff78a

See more details on using hashes here.

Supported by

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