Skip to main content

Logo

CC BY-NC-SA 4.0 Static Badge Dynamic TOML Badge Static Badge Static Badge

Latent-Explorer is the Python implementation of the framework proposed in the paper Unveiling LLMs: The Evolution of Latent Representations in a Dynamic Knowledge Graph to appear in the 1st Conference of Language Modeling (COLM).

Overview

This framework decodes factual knowledge embedded in token representations from a vector space into a set of ground predicates, exhibiting its layer-wise evolution through a dynamic knowledge graph. It employs separate model inferences, with the technique of activation patching, to interpret the semantics embedded within the latent representations of the original inference. This framework can be employed to study the vector space of LLMs to address several research questions, including: (i) which factual knowledge LLMs use in claim verification, (ii) how this knowledge evolves throughout the model's inference, and (iii) whether any distinctive patterns exist in this evolution.

Framework

Contribution

Installation

Use the package manager pip to install the Python package

pip install latent-explorer

or download the repository and install the package with pip install -e .

Demo

The folder tutorial includes a script showcasing the pipeline tutorial/script.py

Usage

Import the package

import latent_explorer

Initialize the application with the LLM and the inputs

explorer = latent_explorer.LatentExplorer(
  model_name = "meta-llama/llama-2-7b-chat-hf", 
  inputs = ["The capital of France is Paris"]
)

Prepare the textual prompts

explorer.generate_prompts(verbose = True)

Perform the inference and get the hidden states

explorer.inference(parse_output = True, output_hidden_states = True)

Probe each hidden states

results = explorer.probe_hidden_states()

Save the textual results

latent_explorer.utils.save_results(results, folder_path = "outputs")

Generate the dynamic knowledge graphs

tg = latent_explorer.TempoGrapher(results)

Get the graphs

graphs = tg.get_graphs()

Generate and save the graphical figures

tg.save_graphs(folder_path = "outputs")

Language models available

This package inherits all of the LLMs supported by the LitGPT package. This framework works with instruction-tuned language models, such as those named with the suffixes "inst", "instruct", or "chat".

models = latent_explorer.utils.all_supported_models()

Computational resources

Since this framework performs multiple language model inferences, using a GPU is recommended (see CUDA). This framework has been tested with using two GPU-based configurations: (1x) NVIDIA® A100-40GB, and (4x) NVIDIA® T4 Tensor Core - 16GB.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Acknowledgements

This implementation is powered by LitGPT, conceptualised, designed and developed by Marco Bronzini. This work has been funded by Ipazia S.p.A.

Citation

If you use this package or its code in your research, please cite the following work:

@inproceedings{bronzini2024unveiling,
  title     = {Unveiling LLMs: The evolution of latent representations in a dynamic knowledge graph},
  author    = {Bronzini, Marco and Nicolini, Carlo and Lepri, Bruno and Staiano, Jacopo and Passerini, Andrea},
  booktitle = {First Conference on Language Modeling},
  year      = {2024},
  url       = {https://openreview.net/forum?id=dWYRjT501w}
}

License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

CC BY-NC-SA 4.0

Metadata

Release files for latent-explorer 0.1.5

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

Source distribution (sdist)

Source distribution for latent-explorer 0.1.5
File Size Uploaded Provenance Actions
latent_explorer-0.1.5.tar.gz 2.0 MB Without provenance Details for latent_explorer-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for latent-explorer 0.1.5
File Interpreter ABI Platform Actions
latent_explorer-0.1.5-py3-none-any.whl Python 3 none any Details for latent_explorer-0.1.5-py3-none-any.whl

Total release size: 2.1 MB

Release files / latent_explorer-0.1.5.tar.gz

Download URL latent_explorer-0.1.5.tar.gz
Size 2.0 MB
Tags Source
SHA-256 checksum
How to use checksums
e84ebce808b655b37f35e21fc1a1bbb0386e4f37c991ced7025af88f104ce54d
BLAKE2b-256 checksum
How to use checksums
14a0c9e55dae5041644f34fb862c053893a613190752ba3dff9a6ea027faec27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / latent_explorer-0.1.5-py3-none-any.whl

Download URL latent_explorer-0.1.5-py3-none-any.whl
Size 34.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b40a101322709c5b1280ca519f4723636bedc1aab6f04b6848c87474a0f8778
BLAKE2b-256 checksum
How to use checksums
8c70ef5c537f23b06d49d38dc837530aa1b616e1b4e53ca5e41b762de0aac5ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Security for latent-explorer 0.1.5

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