--- title: BLiMP emoji: 🎈 colorFrom: blue colorTo: red sdk: static pinned: false tags: - evaluate - metric description: >- BLiMP is a challenge set for evaluating what language models (LMs) know about major grammatical phenomena in English. BLiMP consists of 67 sub-datasets, each containing 1000 minimal pairs isolating specific contrasts in syntax, morphology, or semantics. The data is automatically generated according to expert-crafted grammars. For more information on BLiMP, see the [dataset card](https://huggingface.co/datasets/nyu-mll/blimp). --- # Metric Card for BLiMP ## Metric Description BLiMP is a challenge set for evaluating what language models (LMs) know about major grammatical phenomena in English. BLiMP consists of 67 sub-datasets, each containing 1000 minimal pairs isolating specific contrasts in syntax, morphology, or semantics. The data is automatically generated according to expert-crafted grammars. ## Intended Uses Any language generation task. ## How to Use The metric takes a list of text as input, as well as the name of the model used to compute the metric: ```python from evaluate import load blimp = load("pico-lm/blimp", module_type="metric") results = blimp.compute(model_id='pico-lm/pico-decoder') ``` ### Inputs - **model_id** (str): model used for calculating BLiMP. - **batch_size** (int): the batch size to run texts through the model. Defaults to 16. - **predictions** (list[str]): names of metrics to run. pass empty list or `["*"]` to run all of them - **device** (str): device to run on, defaults to `cuda` when available - **samples_per_set** (Optional[int]): the number of samples per metric. Maximum 1_000 (enforced with a `min` call). If None, defaults to 1000. - **trust_remote_code** (bool): whether to trust datasets code , default False. ### Output Values This metric outputs a dictionary containing the blimp scores for each of the 67 sub-datasets, as well as the overall accuracy. An LM’s overall accuracy on BLiMP is simply the proportion of the 67,000 minimal pairs in which the model assigns a higher probability to the acceptable sentence. Each score is in `[0,1]`. A **higher** score is better. ```python { "accuracy": 0.621288127211, "by_uid": { "adjunct_island": 0.12761212512, # rest of sub-datasets... }, "by_phenomenon": { "anaphor_agreement": 0.71287512125, # rest of phenomena... }, } ``` ### Examples Calculating BLiMP on predictions defined here: ```python def check_blimp(): # Load the metric blimp = load("pico-lm/blimp") # example with a small language model results = blimp.compute( model_id="distilgpt2", batch_size=16, predictions=["*"], ) # Print results print("Overall accuracy:", results["accuracy"]) >>> Overall accuracy: 0.5035074626865672 print("Top 5 best performing uids:") sorted_results = sorted(results["by_uid"].items(), key=lambda x: x[1], reverse=True) for phenomenon, accuracy in sorted_results[:5]: print(f"{phenomenon}: {accuracy:.3f}") >>> Top 5 best performing uids: >>> anaphor_number_agreement: 0.919 >>> anaphor_gender_agreement: 0.868 >>> matrix_question_npi_licensor_present: 0.840 >>> wh_vs_that_no_gap: 0.787 >>> sentential_negation_npi_licensor_present: 0.729 print("Top 5 best performing phenomena:") sorted_results = sorted( results["by_phenomenon"].items(), key=lambda x: x[1], reverse=True ) for phenomenon, accuracy in sorted_results[:5]: print(f"{phenomenon}: {accuracy:.3f}") >>> Top 5 best performing phenomena: >>> anaphor_agreement: 0.893 >>> argument_structure: 0.597 >>> npi_licensing: 0.579 >>> filler_gap_dependency: 0.561 >>> control_raising: 0.533 ``` ## Citation ```bibtex @article{warstadt2020blimp, author = {Warstadt, Alex and Parrish, Alicia and Liu, Haokun and Mohananey, Anhad and Peng, Wei and Wang, Sheng-Fu and Bowman, Samuel R.}, title = {BLiMP: The Benchmark of Linguistic Minimal Pairs for English}, journal = {Transactions of the Association for Computational Linguistics}, volume = {8}, number = {}, pages = {377-392}, year = {2020}, doi = {10.1162/tacl\_a\_00321}, URL = {https://doi.org/10.1162/tacl_a_00321}, eprint = {https://doi.org/10.1162/tacl_a_00321}, abstract = { We introduce The Benchmark of Linguistic Minimal Pairs (BLiMP),1 a challenge set for evaluating the linguistic knowledge of language models (LMs) on major grammatical phenomena in English. BLiMP consists of 67 individual datasets, each containing 1,000 minimal pairs—that is, pairs of minimally different sentences that contrast in grammatical acceptability and isolate specific phenomenon in syntax, morphology, or semantics. We generate the data according to linguist-crafted grammar templates, and human aggregate agreement with the labels is 96.4\%. We evaluate n-gram, LSTM, and Transformer (GPT-2 and Transformer-XL) LMs by observing whether they assign a higher probability to the acceptable sentence in each minimal pair. We find that state-of-the-art models identify morphological contrasts related to agreement reliably, but they struggle with some subtle semantic and syntactic phenomena, such as negative polarity items and extraction islands. } } ```