Giter Club home page Giter Club logo

better-mlm-scoring's Introduction

A Better Way to Do Masked Language Model Scoring

Code accompanying the ACL paper A Better Way to Do Masked Language Model Scoring by Carina Kauf & Anna Ivanova.

Code adapts the minicons implementation of Salazar et al. (2020)'s PLL metric.

Paper abstract

Estimating the log-likelihood of a given sentence under an autoregressive language model is straightforward: one can simply apply the chain rule and sum the log-likelihood values for each successive token. However, for masked language models, there is no direct way to estimate the log-likelihood of a sentence. To ad- dress this issue, Salazar et al. (2020) propose to estimate sentence pseudo-log-likelihood (PLL) scores, computed by successively masking each sentence token, retrieving its score using the rest of the sentence as context, and summing the resulting values. Here, we demonstrate that the original PLL method yields inflated scores for out-of-vocabulary words and propose an adapted metric, in which we mask not only the target token, but also all within-word tokens to the right of the target. We show that our adapted metric (PLL-word-l2r) outperforms both the original PLL metric and a PLL metric in which all within-word tokens are masked. In particular, it better satisfies theoretical desiderata and better correlates with scores from autoregressive models. Finally, we show that the choice of metric affects even tightly controlled, minimal pair evaluation benchmarks (such as BLiMP), underscoring the importance of selecting an appropriate scoring metric for evaluating MLM properties

We improve on the widely used pseudo-log-likelihood sentence score estimation method for masked language models from Salazar et al. (2020) by solving the score inflation problem for multi-token words the original PLL metric introduces, without overly penalizing multi-token words. The new metric also fulfills several theoretical desiderata of sentence/word scoring methods better than alternative PLL metrics and is more cognitively plausible:

Installation

git clone --recursive https://github.com/carina-kauf/better-mlm-scoring.git
cd better-mlm-scoring
pip install -r requirements.txt 

Run

Scoring the bert-base-cased model on the EventsAdapt dataset using the PLL-word-l2r metric:

cd better-mlm-scoring-analyses
python dataset_scoring.py --dataset EventsAdapt \
                          --model bert-base-cased \
                          --which_masking within_word_l2r

Masking options are original, within_word_l2r, within_word_mlm, global_l2r

Citation

If you use this work, please cite:

@misc{kauf2023better,
      title={A Better Way to Do Masked Language Model Scoring}, 
      author={Carina Kauf and Anna Ivanova},
      year={2023},
      eprint={2305.10588},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

Repo structure

Master branch

  • adapted_minicons : A stripped version of the minicons package in which we adapt the MaskedLMScorer class in the scorer module.
  • better-mlm-scoring-analyses : Data and scripts used to analyze the novel masked language model scoring metrics

Branches

  • master : Code accompanying the paper A Better Way to Do Masked Language Model Scoring by Carina Kauf & Anna Ivanova
  • pr-branch-into-minicons : Code used to add the optimized masked-language modeling metric (PLL-word-l2r) to the minicons library maintained by Kanishka Misra. This repo is a wrapper around the transformers library from HuggingFace ๐Ÿค— and supports functionalities for (i) extracting word representations from contextualized word embeddings and (ii) scoring sequences using language model scoring techniques.

better-mlm-scoring's People

Contributors

aaronmueller avatar carina-kauf avatar dependabot[bot] avatar itsmehemant123 avatar kanishkamisra avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.