Skip to main content

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: https://arxiv.org/abs/2406.00049

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, RLHFSuffixProposal


    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. 
    # also really important to have the chatformat for the majority of models in use now. 
    
    test_input_data = [{
        "tweet": "You should refrain from commenting on this matter."
    }]

 
    model = VLLM(
        model_path="meta-llama/Llama-3.2-1B",
    )


    def toformat(data):

        return {
            "prompt": model.tokenizer.apply_chat_template(
                [
                    {
                        "role": "user",
                        "content": template.format(**data),
                    }
                ],
                tokenize=False,
                add_generation_prompt=True,
            ),
        }

    test_input_data=map(toformat,test_input_data)

    reward = RewardModel("lvwerra/distilbert-imdb")  # sentiment model from HF. 
    
    chain = Quest(
        input_data=test_input_data,
        proposal=RLHFSuffixProposal(
            model=model,
        ),
        beta=0.1,
        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

@misc{faria2024quest,
      title={QUEST: Quality-Aware Metropolis-Hastings Sampling for Machine Translation}, 
      author={Gonçalo R. A. Faria and Sweta Agrawal and António Farinhas and Ricardo Rei and José G. C. de Souza and André F. T. Martins},
      year={2024},
      eprint={2406.00049},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

Metadata

Release files for quest-decoding 1.0.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for quest-decoding 1.0.16
File Interpreter ABI Platform
quest_decoding-1.0.16-py3-none-any.whl Python 3 none any Details

Release files / quest_decoding-1.0.16-py3-none-any.whl

Download URL quest_decoding-1.0.16-py3-none-any.whl
Size 62.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fcee902975ce70a73af25c50554e2a6eadd2f984998179b0ba929f7d518985a9
BLAKE2b-256 checksum
How to use checksums
a6aa8942057762679b8f00f00068580cc969517609f66671538ffa3ce319d271
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.8.19

Release history Release notifications | RSS feed

This release

1.0.16 This release

1 release file

1.0.14

2 release files

1.0.13

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page