Skip to main content

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:

  • CAPA (Chance Adjusted Probabilistic Agreement), $\kappa_p$ (default)
  • CAPA (Chance Adjusted Probabilistic Agreement), $\kappa_p$ discrete
  • Error Consistency

Compute similarity based on CAPA, $\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 a
  • output_b: list[np.array], containing the softmax output probabilties of model b
  • gt: list[int], containing the index of the ground truth
from lmsim.metrics import CAPA

capa= CAPA()
capa.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 a
  • output_b: list[np.array], one-hot vector of model b
from lmsim.metrics import CAPA

capa = CAPA(prob=False)
capa.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lm_sim-0.1.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

lm_sim-0.1.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file lm_sim-0.1.1.tar.gz.

File metadata

  • Download URL: lm_sim-0.1.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for lm_sim-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7f35f94af7c8790fa0d60fa802d316cf06eebb6869b41d98e66f0d4460b7121c
MD5 437c88a6a7fbe99c21d5bab27f1dd4c2
BLAKE2b-256 9ef8f5aacb33a2744b2c372a36793e7719b1c1ed3211dbdbd5e4d03fa0072180

See more details on using hashes here.

File details

Details for the file lm_sim-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: lm_sim-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for lm_sim-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d60727545058579d31d2ae472cde51085efd0de09e98c93b3f359d912a096b4c
MD5 935d164b877b3f1fdf396c839aab4bb8
BLAKE2b-256 a2843193693b95233c6355c35ac75b9470760224858cc57361f37a9509579238

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