lm-scorer
📃 Language Model based sentences scoring library
Synopsis
This package provides a simple programming interface to score sentences using different ML language models.
A simple CLI is also available for quick prototyping.
Install
pip install lm-scorer
Usage
from lm_scorer.models.auto import AutoLMScorer as LMScorer
LMScorer.supported_model_names()
# => ["gpt2", "gpt2-medium", "gpt2-large", "gpt2-xl", distilgpt2"]
scorer = LMScorer.from_pretrained("gpt2")
scorer.score("I like this package.")
# => -25.835
scorer.score("I like this package.", return_tokens=True)
# => -25.835, {
# "I": -3.9997,
# "Ġlike": -5.0142,
# "Ġthis": -2.5178,
# "Ġpackage": -7.4062,
# ".": -1.2812,
# "<|endoftext|>": -5.6163,
# }
scorer.score("I like this package.", return_log_prob=False)
# => 6.0231e-12
scorer.score("I like this package.", return_log_prob=False, return_tokens=True)
# => 6.0231e-12, {
# "I": 0.018321,
# "Ġlike": 0.0066431,
# "Ġthis": 0.080633,
# "Ġpackage": 0.00060745,
# ".": 0.27772,
# "<|endoftext|>": 0.0036381,
# }
CLI
The pip package includes a CLI that you can use to score sentences.
usage: lm-scorer [-h] [--model-name MODEL_NAME] [--tokens] [--log-prob]
[--debug]
sentences-file-path
Get sentences probability using a language model.
positional arguments:
sentences-file-path A file containing sentences to score, one per line. If
- is given as filename it reads from stdin instead.
optional arguments:
-h, --help show this help message and exit
--model-name MODEL_NAME, -m MODEL_NAME
The pretrained language model to use. Can be one of:
gpt2, gpt2-medium, gpt2-large, gpt2-xl, distilgpt2.
--tokens, -t If provided it provides the probability of each token
of each sentence.
--log-prob, -lp If provided log probabilities are returned instead.
--debug If provided it provides additional logging in case of
errors.
Authors
- Simone Primarosa - simonepri
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the license file for details.
Release files for lm-scorer 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lm-scorer-0.1.0.tar.gz | 8.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lm_scorer-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.0 kB
Release files / lm-scorer-0.1.0.tar.gz
| Download URL | lm-scorer-0.1.0.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27ae5b805b072010d0f81d6294d1fc42ae9f6257821cc5b2d9aee8ba4192356b
|
|
BLAKE2b-256 checksum How to use checksums |
3fc670801e35754723c215feb7eeb4eacd68689196032aeea9493de6a001bdd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.7.7 Darwin/19.4.0
|
Release files / lm_scorer-0.1.0-py3-none-any.whl
| Download URL | lm_scorer-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
80af612b2f6fc1e49380c0a371a83a9d8b8d6f684b2b04e5e5a0a24fc9210ef1
|
|
BLAKE2b-256 checksum How to use checksums |
c4bd24e165c523e19f2161d639b283606c25f9cd715882ef3bc3950e06e06485
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.7.7 Darwin/19.4.0
|