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:

  • $\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 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 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 a
  • output_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


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.0.6.tar.gz (3.0 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.0.6-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lm_sim-0.0.6.tar.gz
  • Upload date:
  • Size: 3.0 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.0.6.tar.gz
Algorithm Hash digest
SHA256 e1bea7a6b896fa403eddc1e9d86a9eaa8f9f67f9c36e884504c40f111d0f1dd7
MD5 bed84043c3fdcf86a5fd62c3a5d30820
BLAKE2b-256 69e088de30f6c6a4fa9baba2dd10f86df773cc41898d8acc6c1c03ee35f76651

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lm_sim-0.0.6-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

Hashes for lm_sim-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5589bb866aa7fb5adef4f5f94fe1644641d069326ec7f6d0a5a3a250e7aa2e3a
MD5 ab473528c7bd201ea730d3fdf7bcdf6f
BLAKE2b-256 9cd9f1b1d162a2e8ad87f86720cbc1e2d6455c9647c6d8c12c460d24755ab4bc

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