-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
182 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Contributing to `obvs` | ||
|
||
Welcome to the `obvs` library! We appreciate your interest in contributing to the project. This document provides guidelines and information to help you contribute effectively. | ||
|
||
## Table of Contents | ||
|
||
- [Welcome Note](#welcome-note) | ||
- [Links to Resources](#links-to-resources) | ||
- [Templates](#templates) | ||
- [Test Location](#test-location) | ||
- [Submit Changes](#submit-changes) | ||
- [Development Environment Details](#development-environment-details) | ||
- [How To Contribute](#how-to-contribute) | ||
- [How to Make a Bug Report](#how-to-make-a-bug-report) | ||
- [How to Fix a Bug](#how-to-fix-a-bug) | ||
- [How to Suggest Enhancements](#how-to-suggest-enhancements) | ||
- [Coding Conventions and Style Guide](#coding-conventions-and-style-guide) | ||
- [Code of Conduct](#code-of-conduct) | ||
- [Acknowledgements](#acknowledgements) | ||
- [Project Owner and Contributors Information](#project-owner-and-contributors-information) | ||
- [Where to Get Help](#where-to-get-help) | ||
|
||
## Welcome Note | ||
|
||
Thank you for considering contributing to the `obvs` library! Your contributions, whether they are bug reports, feature suggestions, or code improvements, are greatly appreciated. By contributing, you help make `obvs` a better tool for analyzing and interpreting language models. | ||
|
||
## Links to Resources | ||
|
||
### Templates | ||
|
||
- [Bug Report Template](link-to-bug-report-template) | ||
- [Feature Request Template](link-to-feature-request-template) | ||
- [Pull Request Template](link-to-pull-request-template) | ||
|
||
### Test Location | ||
|
||
Please place your tests in the `tests/` directory and ensure they follow the naming convention `test_*.py`. | ||
|
||
### Submit Changes | ||
|
||
To submit your changes, please follow the steps outlined in the [How To Contribute](#how-to-contribute) section. | ||
|
||
### Development Environment Details | ||
|
||
To set up the development environment for `obvs`, please refer to the [Development Setup](https://github.com/obvslib/obvs?tab=readme-ov-file#development-setup) section in the README. | ||
|
||
## How To Contribute | ||
|
||
### How to Make a Bug Report | ||
|
||
If you encounter a bug while using `obvs`, please [open an issue](https://github.com/obvslib/obvs/issues) on the GitHub repository. Provide a clear and descriptive title, along with a detailed description of the problem, steps to reproduce it, and any relevant code snippets or error messages. | ||
|
||
### How to Fix a Bug | ||
|
||
If you would like to fix a bug, follow these steps: | ||
|
||
1. Check the [issue tracker](https://github.com/obvslib/obvs/issues) to see if the bug has already been reported. If not, [open a new issue](https://github.com/obvslib/obvs/issues/new) describing the bug. | ||
2. Fork the repository and create a new branch for your bug fix. | ||
3. Make the necessary changes to fix the bug. | ||
4. Write tests to verify the bug fix and ensure it doesn't introduce new issues. | ||
5. Commit your changes and push them to your forked repository. | ||
6. [Submit a pull request](https://github.com/obvslib/obvs/compare) to the main repository, referencing the related issue. | ||
|
||
### How to Suggest Enhancements | ||
|
||
If you have an idea for an enhancement or a new feature for `obvs`, please [open an issue](https://github.com/obvslib/obvs/issues/new) on the GitHub repository. Provide a clear and descriptive title, along with a detailed description of the enhancement, its benefits, and any relevant examples or use cases. | ||
|
||
## Coding Conventions and Style Guide | ||
|
||
When contributing code to `obvs`, please adhere to the following coding conventions and style guide: | ||
|
||
- Use meaningful variable and function names. | ||
- Follow the [PEP 8](https://www.python.org/dev/peps/pep-0008/) style guide for Python code. | ||
- Write docstrings for functions and classes following the [NumPy docstring format](https://numpydoc.readthedocs.io/en/latest/format.html). | ||
- Use type hints to improve code readability and maintainability. | ||
- Keep lines of code under 80 characters in length. | ||
|
||
## Code of Conduct | ||
|
||
Please note that the `obvs` project follows a `CODE_OF_CONDUCT`. By participating in this project, you are expected to uphold this code. Please report any unacceptable behavior to the project maintainers. | ||
|
||
## Acknowledgements | ||
|
||
We would like to express our gratitude to all the contributors who have helped improve the `obvs` library. Your contributions are greatly appreciated! | ||
|
||
## Where to Get Help | ||
|
||
If you have any questions or need assistance with contributing to `obvs`, please [open an issue](https://github.com/obvslib/obvs/issues/new) on the GitHub repository. You can also reach out to the project maintainers or join our [github discussions](https://github.com/obvslib/obvs/discussions) for further help and discussion. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,100 @@ | ||
# obvs | ||
# obvs: A Python Library for Analyzing and Interpreting Language Models | ||
|
||
[![CI](https://github.com/obvslib/obvs/actions/workflows/main.yaml/badge.svg)](https://github.com/obvslib/obvs/actions/workflows/main.yaml) | ||
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. | ||
|
||
Making Transformers Obvious | ||
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. | ||
|
||
## Project cheatsheet | ||
## Installation | ||
|
||
- **pre-commit:** `pre-commit run --all-files` | ||
- **pytest:** `pytest` or `pytest -s` | ||
- **coverage:** `coverage run -m pytest` or `coverage html` | ||
- **poetry sync:** `poetry install --no-root --sync` | ||
- **updating requirements:** see [docs/updating_requirements.md](docs/updating_requirements.md) | ||
To install the `obvs` library, you can use pip: | ||
|
||
## Initial project setup | ||
``` | ||
pip install obvs | ||
``` | ||
|
||
1. See [docs/getting_started.md](docs/getting_started.md) or [docs/quickstart.md](docs/quickstart.md) | ||
for how to get up & running. | ||
2. Check [docs/project_specific_setup.md](docs/project_specific_setup.md) for project specific setup. | ||
3. See [docs/using_poetry.md](docs/using_poetry.md) for how to update Python requirements using | ||
[Poetry](https://python-poetry.org/). | ||
4. See [docs/detect_secrets.md](docs/detect_secrets.md) for more on creating a `.secrets.baseline` | ||
file using [detect-secrets](https://github.com/Yelp/detect-secrets). | ||
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: | ||
|
||
```python | ||
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. | ||
|
||
```python | ||
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 [documentation](https://obvs.rtfd.io/) and [PyPI](https://pypi.org/project/obvs/). | ||
|
||
## 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 – [email protected] | ||
|
||
Distributed under the MIT license. See `LICENSE` for more information. | ||
|
||
## Contributing | ||
|
||
We welcome contributions to the `obvs` library! See `CONTRIBUTING` for more information. |