File size: 5,363 Bytes
740c7d4
c58b005
6aa3612
735107c
 
2338f58
740c7d4
735107c
a161891
 
ba723ea
0c2e739
 
 
 
 
6aa3612
0f3b529
0c2e739
2325efa
a161891
c58b005
735107c
 
2338f58
6aa3612
 
 
735107c
 
2338f58
735107c
 
 
 
 
 
 
 
6aa3612
 
735107c
 
 
2338f58
c58b005
735107c
17ddf40
726b567
c26f589
 
735107c
 
2338f58
17ddf40
735107c
17ddf40
735107c
17ddf40
2338f58
735107c
17ddf40
 
 
 
 
 
 
 
 
735107c
2338f58
17ddf40
 
 
2338f58
735107c
17ddf40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
735107c
 
 
 
 
6aa3612
 
 
 
 
 
 
 
 
 
 
 
735107c
 
2338f58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
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. }
}

```