Python package to compute similarity between LMs
Project description
LM-Similarity
lm-sim is a Python module for computing similarity between Language Models and is distributed under the MIT license.
Installation
Dependencies
lm-sim requries:
- Python (>=3.9)
- Numpy (>= 1.19.5)
User installation
If you already have a working installation of NumPy, the easiest way to install lm-sim is using pip:
pip install lm-sim
Example Usage
Currently we support the calcualtion of 3 similarity metrics in the context of MCQ datasets:
- $\kappa_p$ probabilistic (default)
- $\kappa_p$ discrete
- Error Consistency
Compute similarity based on $\kappa_p$
Below is a simple example on how to compute similarity between 2 models based on $k_p$. The input has be to formatted as follows:
output_a: list[np.array], containing the softmax output probabilties of model aoutput_b: list[np.array], containing the softmax output probabilties of model bgt: list[int], containing the index of the ground truth
from lmsim.metrics import Kappa_p
kappa_p= Kappa_p()
kappa_p.compute_k(output_a, output_b, gt)
For a discrete computation (when output probabilities are not availble) set the flag prob=False and the input must be formatted as one-hot vectors:
output_a: list[np.array], one-hot vector of model aoutput_b: list[np.array], one-hot vector of model b
from lmsim.metrics import Kappa_p
kappa_p = Kappa_p(prob=False)
kappa_p.compute_k(output_a, output_b, gt)
Compute similarity based on Error Consistency
from lmsim.metrics import EC
ec = EC()
ec.compute_k(output_a, output_b, gt)
Implementation supports both softmax output probabilties or one-hot vector as input.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lm_sim-0.0.7.tar.gz.
File metadata
- Download URL: lm_sim-0.0.7.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e00c56616cdcda229c3fc97cfdc0739a4fe3f70a00c5f0e23516e428d5e4f27
|
|
| MD5 |
57e08ce13f2e5976862f5b1e3aa0fe97
|
|
| BLAKE2b-256 |
3a970bd9fa1da676de5bb703917997a0c761c775a18f433245781e1c6f767a23
|
File details
Details for the file lm_sim-0.0.7-py3-none-any.whl.
File metadata
- Download URL: lm_sim-0.0.7-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7e28c8810b80d6e21aac28d489134325c02c2d48ba863db59e122cb76ee7f22
|
|
| MD5 |
2c5939be796b0b2fd997ed1374dd1582
|
|
| BLAKE2b-256 |
68bb7ad06de4276bae1127c51cef6373d6ea02c47b5a2ede4eeab4f90528fdb5
|