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:

  • Goels $k$ (discrete)
  • Goels $k_p$ (probabilistic)
  • Error Consistency

Goels $k$ and Goels $k_p$

Below is a simple example on how to compute Goels $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 Goels_k

goels_k = Goels_k()
goels_k.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 Goels_k

goels_k = Goels_k(prob=False)
goels_k.compute_k(output_a, output_b, gt)

Error Consistency

from lmsim.metrics import EC

ec = EC(prob=False)
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.4.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.4-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lm_sim-0.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 11ad5e67b190118534bbc08323defef66ce36ebbc6d0ec22ef2aa7b6a5b73a41
MD5 e0970e91e07d59bb45a95c50abd098ae
BLAKE2b-256 4a66a247ffb1a09f0622beaf2d8a590254f39cba51f82b0e355a8d978448d4a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lm_sim-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 3.2 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c81d3c2191f68a1a715abb16294fd38b0ea7e25d525ae845881957a0be7fe408
MD5 a5c038cbda5e18d80140c22a80fefce7
BLAKE2b-256 dfe1808444fb538031c4494ac5abeeeb6c89eaf03a1c3054a9fce2e6d7a9ae16

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