API¶
General¶
General function for dealing with tasks and models implemented in SEB.
seb.get_task(name)
¶
Fetches a task by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the task. |
required |
Returns:
Type | Description |
---|---|
Task
|
A task. |
Source code in src/seb/registries.py
23 24 25 26 27 28 29 30 31 32 33 |
|
seb.get_all_tasks()
¶
Returns all tasks implemented in SEB.
Returns:
Type | Description |
---|---|
list[Task]
|
A list of all tasks in SEB. |
Source code in src/seb/registries.py
36 37 38 39 40 41 42 43 |
|
seb.get_model(name)
¶
Fetches a model by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the model. |
required |
Returns:
Type | Description |
---|---|
SebModel
|
A model including metadata. |
Source code in src/seb/registries.py
10 11 12 13 14 15 16 17 18 19 20 |
|
seb.get_all_models()
¶
Get all the models implemented in SEB.
Returns:
Type | Description |
---|---|
list[SebModel]
|
A list of all models in SEB. |
Source code in src/seb/registries.py
46 47 48 49 50 51 52 53 |
|
Benchmark¶
seb.Benchmark
¶
Benchmark is the main orchestrator of the SEB benchmark.
Source code in src/seb/benchmark.py
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 |
|
__init__(languages=None, tasks=None)
¶
Initialize the benchmark.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
languages |
Optional[list[str]]
|
A list of languages to run the benchmark on. If None, all languages are used. |
None
|
tasks |
Optional[Union[Iterable[str], Iterable[Task]]]
|
The tasks to run the benchmark on. If None, all tasks are used. Can either be specified as strings or as Task objects. |
None
|
Source code in src/seb/benchmark.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
evaluate_model(model, use_cache=True, run_model=True, raise_errors=True, cache_dir=None, verbose=True)
¶
Evaluate a model on the benchmark.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
SebModel
|
The model to evaluate. |
required |
use_cache |
bool
|
Whether to use the cache. |
True
|
run_model |
bool
|
Whether to run the model if the cache is not present. |
True
|
raise_errors |
bool
|
Whether to raise errors. |
True
|
cache_dir |
Optional[Path]
|
The cache directory to use. If None, the default cache directory is used. |
None
|
verbose |
bool
|
Whether to show a progress bar. |
True
|
Returns:
Type | Description |
---|---|
BenchmarkResults
|
The results of the benchmark. |
Source code in src/seb/benchmark.py
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 |
|
evaluate_models(models, use_cache=True, run_model=True, raise_errors=True, cache_dir=None, verbose=True)
¶
Evaluate a list of models on the benchmark.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
models |
list[SebModel]
|
The models to evaluate. |
required |
use_cache |
bool
|
Whether to use the cache. |
True
|
run_model |
bool
|
Whether to run the model if the cache is not present. |
True
|
raise_errors |
bool
|
Whether to raise errors. |
True
|
cache_dir |
Optional[Path]
|
The cache directory to use. If None, the default cache directory is used. |
None
|
verbose |
bool
|
Whether to show a progress bar. |
True
|
Returns:
Type | Description |
---|---|
list[BenchmarkResults]
|
The results of the benchmark, once for each model. |
Source code in src/seb/benchmark.py
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 |
|
get_tasks(tasks, languages)
staticmethod
¶
Get the tasks for the benchmark.
Returns:
Type | Description |
---|---|
list[Task]
|
A list of tasks. |
Source code in src/seb/benchmark.py
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 |
|
Interfaces¶
SEB implements to main interfaces. A task interface which is a tasks within the Benchmark and a model interface which is a model applied to the tasks.
Model Interface¶
seb.Encoder
¶
Bases: Protocol
Interface which all models must implement.
Source code in src/seb/interfaces/model.py
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 |
|
encode(sentences, *, task=None, batch_size=32, **kwargs)
¶
Returns a list of embeddings for the given sentences.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sentences |
list[str]
|
List of sentences to encode |
required |
task |
Optional[Task]
|
The task to encode for. This allows the model to encode differently for different tasks. Will always be given but does not need to be used. |
None
|
batch_size |
int
|
Batch size for the encoding |
32
|
kwargs |
Any
|
arguments to pass to the models encode method |
{}
|
Returns:
Type | Description |
---|---|
ndarray
|
Embeddings for the given documents |
Source code in src/seb/interfaces/model.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
seb.LazyLoadEncoder
dataclass
¶
Bases: Encoder
Encoder object, which lazy loads the model on the first call to encode()
Source code in src/seb/interfaces/model.py
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 |
|
model: Encoder
property
¶
Dynimically load the model.
encode(sentences, *, task=None, **kwargs)
¶
Returns a list of embeddings for the given sentences. Args: sentences: List of sentences to encode task: The task to encode for. This allows the model to encode differently for different tasks. Will always be given but does not need to be used. batch_size: Batch size for the encoding kwargs: arguments to pass to the models encode method
Returns:
Type | Description |
---|---|
ndarray
|
Embeddings for the given documents |
Source code in src/seb/interfaces/model.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
load_model()
¶
Load the model.
Source code in src/seb/interfaces/model.py
107 108 109 110 111 112 |
|
seb.SebModel
dataclass
¶
An embedding model as implemented in SEB. It notably dynamically loads models (such that models are not loaded when a cache is hit) and includes metadata pertaining to the specific model.
Source code in src/seb/interfaces/model.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
number_of_parameters: Optional[int]
property
¶
Returns the number of parameters in the model.
Task Interface¶
seb.Task
¶
Bases: Protocol
A task is a specific evaluation task for a sentence embedding model.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the task. |
main_score |
str
|
The main score of the task. |
reference |
str
|
A reference to the task. |
version |
str
|
The version of the task. |
languages |
list[Language]
|
The languages of the task. |
domain |
list[Domain]
|
The domains of the task. Should be one of the categories listed on https://universaldependencies.org |
task_type |
TaskType
|
A list of task types, determines how the task is being evaluated. E.g. Classification. |
task_subtypes |
list[str]
|
a list of subtypes e.g. Sentiment Classification. |
description |
str
|
A description of the task. |
Source code in src/seb/interfaces/task.py
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 |
|
evaluate(model)
¶
Evaluates a Sentence Embedding Model on the task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Encoder
|
A model with the encode method implemented. |
required |
Returns:
Type | Description |
---|---|
TaskResult
|
A TaskResult object. |
Source code in src/seb/interfaces/task.py
64 65 66 67 68 69 70 71 72 73 74 |
|
get_documents()
¶
Get the documents for the task.
Returns:
Type | Description |
---|---|
list[str]
|
A list of strings. |
Source code in src/seb/interfaces/task.py
76 77 78 79 80 81 82 83 |
|
name_to_path()
¶
Convert a name to a path.
Source code in src/seb/interfaces/task.py
97 98 99 100 101 102 |
|
Data Classes¶
SEB uses data classes to store the results of a benchmark. The following classes are available:
seb.BenchmarkResults
¶
Bases: BaseModel
Dataclass for storing benchmark results.
Attributes:
Name | Type | Description |
---|---|---|
meta |
ModelMeta
|
ModelMeta object. |
task_results |
list[Union[TaskResult, TaskError]]
|
List of TaskResult objects. |
Source code in src/seb/result_dataclasses.py
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 |
|
from_disk(path)
classmethod
¶
Load task results from a path.
Source code in src/seb/result_dataclasses.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
to_disk(path)
¶
Write task results to a path.
Source code in src/seb/result_dataclasses.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
seb.TaskResult
¶
Bases: BaseModel
Dataclass for storing task results.
Attributes:
Name | Type | Description |
---|---|---|
task_name |
str
|
Name of the task. |
task_description |
str
|
Description of the task. |
task_version |
str
|
Version of the task. |
time_of_run |
datetime
|
Time of the run. |
scores |
dict[Language, dict[str, Union[float, str]]]
|
Dictionary of scores on the form {language: {"metric": value}}. |
main_score |
str
|
Name of the main score. |
Source code in src/seb/result_dataclasses.py
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 |
|
languages: list[Language]
property
¶
Returns the languages of the task.
from_disk(path)
classmethod
¶
Load task results from a path.
Source code in src/seb/result_dataclasses.py
60 61 62 63 64 65 66 67 |
|
get_main_score(lang=None)
¶
Returns the main score for a given set of languages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lang |
Optional[Iterable[str]]
|
List of languages to get the main score for. |
None
|
Returns:
Type | Description |
---|---|
float
|
The main score. |
Source code in src/seb/result_dataclasses.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
name_to_path()
¶
Convert a name to a path.
Source code in src/seb/result_dataclasses.py
79 80 81 82 83 84 |
|
to_disk(path)
¶
Write task results to a path.
Source code in src/seb/result_dataclasses.py
69 70 71 72 73 74 75 76 77 |
|
seb.TaskError
¶
Bases: BaseModel
Source code in src/seb/result_dataclasses.py
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 |
|
from_disk(path)
classmethod
¶
Load task results from a path.
Source code in src/seb/result_dataclasses.py
103 104 105 106 107 108 109 110 |
|
name_to_path()
¶
Convert a name to a path.
Source code in src/seb/result_dataclasses.py
116 117 118 119 120 121 |
|
to_disk(path)
¶
Write task results to a path.
Source code in src/seb/result_dataclasses.py
93 94 95 96 97 98 99 100 101 |
|