Skip to main content

A package for sampling from intractable distributions with LLMs.

Project description

QUEST: Quality-Aware Metropolis-Hastings Sampling for Machine Translation

Gonçalo Faria, Sweta Agrawal, António Farinhas, Ricardo Rei, José G. C. de Souza, Andre Martins

Paper: arxiv link goes here

TL;DR: This paper presents a method to generate diverse and high-quality machine translations by sampling from a Gibbs distribution using the Metropolis-Hastings algorithm.

Abstract:

An important challenge in machine translation (MT) is to generate high-quality and diverse translations. Prior work has shown that the estimated likelihood from the MT model correlates poorly with translation quality. In contrast, quality evaluation metrics (such as COMET or BLEURT) exhibit high correlations with human judgments, which has motivated their use as rerankers (such as quality-aware and minimum Bayes risk decoding). However, relying on a single translation with high estimated quality increases the chances of "gaming the metric''. In this paper, we address the problem of sampling a set of high-quality and diverse translations. We provide a simple and effective way to avoid over-reliance on noisy quality estimates by using them as the energy function of a Gibbs distribution. Instead of looking for a mode in the distribution, we generate multiple samples from high-density areas through the Metropolis-Hastings algorithm, a simple Markov chain Monte Carlo approach. The results show that our proposed method leads to high-quality and diverse outputs across multiple language pairs (English$\leftrightarrow${German, Russian}) with two strong decoder-only LLMs (Alma-7b, Tower-7b).


Documentation

TBD


Quick Start Examples

Install

Install using pip (recommended):

pip install quest-decoding

Install using pip (from github):

pip install git+https://github.com/deep-spin/quest-decoding.git
Sentiment Steering
    from langchain.prompts import PromptTemplate
    from quest import RewardModel
    from quest import VLLM


    template =  PromptTemplate.from_template(
        "I received the following comment on a X: {tweet}. How should I respond?:\n"
    ) # a prompt template you define - usefull for tasks like translation. 
    
    test_input_data = [{
        "tweet": "You should refrain from commenting on this matter."
    }]

    model = VLLM(
        model_path="haoranxu/ALMA-7B",
        prompt_template=template,
    )

    reward = RewardModel("lvwerra/distilbert-imdb")  # sentiment model from HF. 
    
    chain = Quest(
        input_data=test_input_data,
        model=model,
        reward=reward,
    )
    
    chain_outputs = chain.run(
        steps=10,
        use_tqdm=True,
    )
    
    print(chain_outputs.samples)
        

Contact

For bugs and feature requests please visit GitHub Issues. For business inquiries or professional support requests please send an e-mail.


Citation

@inproceedings{
    questdecoding,
    title={QUEST: Quality-Aware Metropolis-Hastings Sampling for Machine Translation},
    author={Gonçalo Faria, Sweta Agrawal, António Farinhas, Ricardo Rei, José G. C. de Souza, Andre Martins},
    booktitle={},
    year={2024},
    url={arxiv link goes here}
}

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

quest-decoding-1.0.6.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

quest_decoding-1.0.6-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file quest-decoding-1.0.6.tar.gz.

File metadata

  • Download URL: quest-decoding-1.0.6.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.13

File hashes

Hashes for quest-decoding-1.0.6.tar.gz
Algorithm Hash digest
SHA256 6f31db019c298f9a94dddbb5ab98b8b6908f31760eb78158e0391a9d4a3f8cd7
MD5 11c6a7c01f6b5236292d4502fb2f2dde
BLAKE2b-256 be6d485e5966514ceb1322fda0a0872bc3cfc88e0ea90c4f7d63a78d310c4521

See more details on using hashes here.

File details

Details for the file quest_decoding-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for quest_decoding-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0c4ca9b1e45057ba5bc6aaa26e00f828bc948cf8424801e3876b78fa49bb952a
MD5 14b8bb426ad3069dca9753357b18ef08
BLAKE2b-256 5f16c0828fe1923982bdb43031ffb068ab53cc1d5e38bca69ee9fc95daa99e8b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page