File size: 10,690 Bytes
dfd45d6
 
 
 
 
 
 
 
 
 
80b302f
c963b80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfd45d6
80b302f
dfd45d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c963b80
80b302f
 
dfd45d6
 
 
 
80b302f
 
 
 
dfd45d6
 
 
 
 
 
c963b80
dfd45d6
 
 
 
 
 
80b302f
 
dfd45d6
 
 
 
 
 
 
80b302f
 
 
 
dfd45d6
 
 
 
 
c963b80
dfd45d6
 
 
 
 
80b302f
 
dfd45d6
 
 
 
 
 
 
 
80b302f
dfd45d6
 
 
 
 
 
 
 
 
 
 
80b302f
 
5a5767f
 
80b302f
 
 
 
dfd45d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80b302f
0bc79d9
dfd45d6
 
 
 
c963b80
 
80b302f
0bc79d9
dfd45d6
 
 
 
 
80b302f
0bc79d9
80b302f
dfd45d6
 
 
 
 
 
 
80b302f
0bc79d9
80b302f
dfd45d6
 
 
 
 
 
80b302f
0bc79d9
80b302f
dfd45d6
 
 
 
 
 
 
 
0bc79d9
80b302f
dfd45d6
 
 
 
 
 
 
80b302f
 
 
 
 
 
 
 
 
 
 
 
0bc79d9
80b302f
dfd45d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0bc79d9
80b302f
dfd45d6
 
 
 
 
 
 
80b302f
 
 
 
 
 
 
 
 
 
 
 
0bc79d9
80b302f
dfd45d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80b302f
dfd45d6
 
 
 
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
"""
handle multi_header options
"""
from st_aggrid import JsCode
from streamlit_theme import st_theme

HEADER_STYLE = {'fontSize': '18px'}
CELL_STYLE = {'fontSize': '18px'}
LINK = ' https://huggingface.co/datasets/embedding-benchmark/'


def get_dataset_url_name(field_name):
    """Convert field name to proper URL format for closed datasets"""
    # Handle field names like "ClosedDataset 2 (German Legal Sentences)"
    if field_name.startswith("ClosedDataset "):
        # Extract the number and format it as ClosedDataset_X
        if "(" in field_name:
            # Extract number from "ClosedDataset 2 (description)" -> "2"
            number_part = field_name.split("ClosedDataset ")[1].split(" ")[0]
            return f"ClosedDataset_{number_part}"
        else:
            # Handle cases where it might already be in the right format or no parentheses
            return field_name.replace(" ", "_")

    # Return original field_name for open datasets
    return field_name


def mutil_header_options(column_list: list, avg_column: str, is_section: bool):
    """
    get mutil_header_options - 优化版本,减少组件实例化
    :param column_list:
    :param avg_column:
    :param is_section:
    :return:
    """
    if is_section:
        column_def_list = [
            {'headerName': column if "Average" not in column else column.replace("Average", "").strip().capitalize(),
             'field': column,
             'headerClass': 'custom-header-style',
             'cellClass': 'custom-cell-style',
             'headerTooltip': column if "Average" not in column else column.replace("Average",
                                                                                    "").strip().capitalize()
             # 'suppressSizeToFit': True
             } for column in column_list if
            column not in (avg_column, "Closed average", "Open average")]

        return column_def_list

    mutil_column_list = [column for column in column_list if
                         column not in (avg_column, "Closed average", "Open average")]
    close_group_list = list(filter(lambda x: x.startswith('_') or x.startswith("ClosedDataset "), mutil_column_list))
    open_group_list = list(
        filter(lambda x: not x.startswith('_') and not x.startswith("ClosedDataset "), mutil_column_list))


    close_group_def = {
        'headerName': 'CLOSED DATASETS',
        'width': 'fit-content',
        'headerClass': 'custom-header-style',
        'cellClass': 'custom-cell-style',
        'autoHeaderHeight': True,
        'children': [
            {'headerName': column.replace('_', ''),
             'field': column,

             "headerComponentParams": {
                 "innerHeaderComponent": "linkHeaderComponent",
                 "url": LINK + get_dataset_url_name(column),
                 "headerName": column
             },

             'headerClass': 'custom-header-style',
             'cellClass': 'custom-cell-style',
             'sortable': True,
             # 'width': 150,
             "suppressColumnVirtualisation": True,

             } for column in close_group_list
        ],

    }
    open_group_def = {
        'headerName': 'OPEN DATASETS',
        'width': 'fit-content',
        'headerClass': 'custom-header-style',
        'cellClass': 'custom-cell-style',
        'autoHeaderHeight': True,
        'children': [
            {'headerName': column,
             'field': column,
             "headerComponentParams": {
                 "innerHeaderComponent": "linkHeaderComponent",
                 "url": LINK + get_dataset_url_name(column),
                 "headerName": column
             },
             'headerClass': 'custom-header-style',
             'cellClass': 'custom-cell-style',
             'sortable': True,
             # 'width': 150,
             "suppressColumnVirtualisation": True,

             } for column in open_group_list
        ],

    }
    return [close_group_def, open_group_def]


def get_header_options(column_list: list, avg_column: str, is_section: bool):
    grid_options = {
        'columnDefs': [
            {
                'headerName': 'Model Name',
                'field': 'model_name',
                'pinned': 'left',
                'sortable': False,
                'headerClass': 'custom-header-style',
                'cellClass': 'custom-cell-style',
                'autoHeaderHeight': True,
                "tooltipValueGetter": JsCode(
                    """
                    function(p) {
                    console.log(p);
                    const value = p.data && p.data.tooltip ? p.data.tooltip : "";
                    const link = p.data && p.data.reference ? p.data.reference : "";
                    return link ? `${value} (${link})` : value;
    }
                    """
                ),
                "width": 250,
                'cellRenderer': JsCode("""class CustomHTML {
                            init(params) {
                                const link = params.data.reference;
                                this.eGui = document.createElement('div');
                                this.eGui.innerHTML = link ? 
                                    `<a href="${link}" class="a-cell" target="_blank">${params.value} </a>` : 
                                    params.value;
                            }

                            getGui() {
                                return this.eGui;
                            }
                        }"""),
                'suppressSizeToFit': True,
                'headerTooltip': 'Name of the embedding model being evaluated for retrieval tasks',

            },
            {'headerName': "Vendor",
             'field': 'vendor',
             'headerClass': 'custom-header-style',
             'cellClass': 'custom-cell-style',
             # 'suppressSizeToFit': True,
             'headerTooltip': 'Company or organization that developed and maintains the model',
             },
            {'headerName': "Overall Score",
             'field': avg_column,
             'headerClass': 'custom-header-style',
             'cellClass': 'custom-cell-style',
             # 'suppressSizeToFit': True,
             'headerTooltip': 'Overall average performance score across all evaluated datasets',

             },

            # Add Open average column definition
            {'headerName': 'Open Average',
             'field': 'Open average',
             'headerClass': 'custom-header-style',
             'cellClass': 'custom-cell-style',
             # 'suppressSizeToFit': True,
             'headerTooltip': 'Average NDCG@10 performance score across publicly available datasets',

             },

            {'headerName': 'Closed Average',
             'field': 'Closed average',
             'headerClass': 'custom-header-style',
             'cellClass': 'custom-cell-style',
             # 'suppressSizeToFit': True,
             'headerTooltip': 'Average NDCG@10 performance score across proprietary/restricted datasets',

             },

            {
                'headerName': 'Embd Dtype',
                'field': 'embd_dtype',
                'headerClass': 'custom-header-style',
                'cellClass': 'custom-cell-style',
                # 'suppressSizeToFit': True,
                'headerTooltip': 'Data type format of the embedding vectors (e.g., float32, int8, binary)',

            },
            {
                'headerName': 'Embd Dim',
                'field': 'embd_dim',
                'headerClass': 'custom-header-style',
                'cellClass': 'custom-cell-style',
                # 'suppressSizeToFit': True,
                'valueFormatter': JsCode(
                    """
                    function(params) {
                            const num = params.value;
                            if (typeof num !== "number") return num;
                            if (Math.abs(num) >= 10000) {
                                return num.toLocaleString("en-US");
                            }
                            return num;
                        }
                    """
                ),
                'headerTooltip': 'Number of dimensions in the embedding vector representation',

            },
            {
                'headerName': 'Number of Parameters',
                'field': 'num_params',
                'cellDataType': 'number',
                "colId": "num_params",
                'headerClass': 'custom-header-style',
                'cellClass': 'custom-cell-style',
                'valueFormatter': JsCode(
                    """function(params) {
                    const num = params.value;
                    if (num >= 1e9) return (num / 1e9).toFixed(2) + "B";
                    if (num >= 1e6) return (num / 1e6).toFixed(2) + "M";
                    if (num >= 1e3) return (num / 1e3).toFixed(2) + "K";
                    return num;
                    }"""
                ),
                "width": 120,
                # 'suppressSizeToFit': True,
                'headerTooltip': 'Total number of trainable parameters in the embedding model',

            },
            {
                'headerName': 'Context Length',
                'field': 'max_tokens',
                'headerClass': 'custom-header-style',
                'cellClass': 'custom-cell-style',
                # 'suppressSizeToFit': True,
                'valueFormatter': JsCode(
                    """
                    function(params) {
                            const num = params.value;
                            if (typeof num !== "number") return num;
                            if (Math.abs(num) >= 10000) {
                                return num.toLocaleString("en-US");
                            }
                            return num;
                        }
                    """
                ),
                'headerTooltip': 'Maximum number of tokens the model can process in a single input',

            },

            *mutil_header_options(column_list, avg_column, is_section)
        ],
        'defaultColDef': {
            'filter': True,
            'sortable': True,
            'resizable': True,
            'headerClass': "multi-line-header",
            'autoHeaderHeight': True,
            'width': 105
        },

        "autoSizeStrategy": {
            "type": 'fitCellContents',
            "colIds": [column for column in column_list if column not in (avg_column, "Closed average", "Open average")]
        },
        "tooltipShowDelay": 500,
        "suppressColumnVirtualisation": True

    }

    return grid_options