Factories
bocoel.factories.IndexName
Bases: StrEnum
The names of the indices.
FAISS class-attribute
instance-attribute
FAISS = 'FAISS'
Corresponds to FaissIndex
.
HNSWLIB class-attribute
instance-attribute
HNSWLIB = 'HNSWLIB'
Corresponds to HnswlibIndex
.
POLAR class-attribute
instance-attribute
POLAR = 'POLAR'
Corresponds to PolarIndex
.
WHITENING class-attribute
instance-attribute
WHITENING = 'WHITENING'
Corresponds to WhiteningIndex
.
bocoel.factories.index_class
Get the index class for the given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | IndexName | The name of the index. | required |
Source code in src/bocoel/factories/indices.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
bocoel.factories.StorageName
Bases: StrEnum
The storage names.
PANDAS class-attribute
instance-attribute
PANDAS = 'PANDAS'
Corresponds to PandasStorage
.
DATASETS class-attribute
instance-attribute
DATASETS = 'DATASETS'
Corresponds to DatasetsStorage
.
bocoel.factories.storage
storage(
storage: str | StorageName,
/,
*,
path: str = "",
name: str = "",
split: str = "",
) -> Storage
Create a single storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
storage | str | StorageName | The name of the storage. | required |
path | str | The path to the storage. | '' |
name | str | The name of the storage. | '' |
split | str | The split to use. | '' |
Returns:
Type | Description |
---|---|
Storage | The storage instance. |
Raises:
Type | Description |
---|---|
ValueError | If the storage is unknown. |
Source code in src/bocoel/factories/storages.py
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 |
|
bocoel.factories.EmbedderName
Bases: StrEnum
The names of the embedders.
SBERT class-attribute
instance-attribute
SBERT = 'SBERT'
Corresponds to SbertEmbedder
.
HUGGINGFACE class-attribute
instance-attribute
HUGGINGFACE = 'HUGGINGFACE'
Corresponds to HuggingfaceEmbedder
.
HUGGINGFACE_ENSEMBLE class-attribute
instance-attribute
HUGGINGFACE_ENSEMBLE = 'HUGGINGFACE_ENSEMBLE'
Corresponds to EnsembleEmbedder
concatenating HuggingfaceEmbedder
.
bocoel.factories.embedder
embedder(
name: str | EmbedderName,
/,
*,
model_name: str | list[str],
device: str = "auto",
batch_size: int,
) -> Embedder
Create an embedder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | EmbedderName | The name of the embedder. | required |
model_name | str | list[str] | The model name to use. | required |
device | str | The device to use. | 'auto' |
batch_size | int | The batch size to use. | required |
Returns:
Type | Description |
---|---|
Embedder | The embedder instance. |
Raises:
Type | Description |
---|---|
ValueError | If the name is unknown. |
TypeError | If the model name is not a string for SBERT or Huggingface, or not a list of strings for HuggingfaceEnsemble. |
Source code in src/bocoel/factories/embedders.py
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 |
|
bocoel.factories.CorpusName
Bases: StrEnum
The names of the corpus.
COMPOSED class-attribute
instance-attribute
COMPOSED = 'COMPOSED'
Corresponds to ComposedCorpus
.
bocoel.factories.corpus
corpus(
name: str | CorpusName = CorpusName.COMPOSED,
/,
*,
storage: Storage,
embedder: Embedder,
keys: Sequence[str],
index_name: str | IndexName,
**index_kwargs: Any,
) -> Corpus
Create a corpus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | CorpusName | The name of the corpus. | COMPOSED |
storage | Storage | The storage to use. | required |
embedder | Embedder | The embedder to use. | required |
keys | Sequence[str] | The key to use for the index. | required |
index_name | str | IndexName | The name of the index backend to use. | required |
**index_kwargs | Any | The keyword arguments to pass to the index backend. | {} |
Returns:
Type | Description |
---|---|
Corpus | The corpus instance. |
Raises:
Type | Description |
---|---|
ValueError | If the name is unknown. |
Source code in src/bocoel/factories/corpora.py
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 |
|
bocoel.factories.adaptor
adaptor(name: str | AdaptorName, /, **kwargs: Any) -> Adaptor
Create an adaptor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | AdaptorName | The name of the adaptor. | required |
**kwargs | Any | The keyword arguments to pass to the adaptor. See the documentation of the corresponding adaptor for details. | {} |
Returns:
Type | Description |
---|---|
Adaptor | The adaptor instance. |
Raises:
Type | Description |
---|---|
ValueError | If the name is unknown. |
Source code in src/bocoel/factories/adaptors.py
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 |
|
bocoel.factories.AdaptorName
Bases: StrEnum
The names of the adaptors.
BIGBENCH_MC class-attribute
instance-attribute
BIGBENCH_MC = 'BIGBENCH_MULTIPLE_CHOICE'
Corresponds to BigBenchMultipleChoice
.
BIGBENCH_QA class-attribute
instance-attribute
BIGBENCH_QA = 'BIGBENCH_QUESTION_ANSWER'
Corresponds to BigBenchQuestionAnswer
.
SST2 class-attribute
instance-attribute
SST2 = 'SST2'
Corresponds to Sst2QuestionAnswer
.
GLUE class-attribute
instance-attribute
GLUE = 'GLUE'
Corresponds to GlueAdaptor
.
bocoel.factories.GeneratorName
Bases: StrEnum
The generator names.
HUGGINGFACE_GENERATIVE class-attribute
instance-attribute
HUGGINGFACE_GENERATIVE = 'HUGGINGFACE_GENERATIVE'
Corresponds to HuggingfaceGenerativeLM
.
bocoel.factories.generative
generative(
name: str | GeneratorName,
/,
*,
model_path: str,
batch_size: int,
device: str = "auto",
add_sep_token: bool = False,
) -> GenerativeModel
Create a generative model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | GeneratorName | The name of the model. | required |
model_path | str | The path to the model. | required |
batch_size | int | The batch size to use. | required |
device | str | The device to use. | 'auto' |
add_sep_token | bool | Whether to add the sep token. | False |
Returns:
Type | Description |
---|---|
GenerativeModel | The generative model instance. |
Raises:
Type | Description |
---|---|
ValueError | If the name is unknown. |
Source code in src/bocoel/factories/lms.py
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 |
|
bocoel.factories.ClassifierName
Bases: StrEnum
The classifier names.
HUGGINGFACE_LOGITS class-attribute
instance-attribute
HUGGINGFACE_LOGITS = 'HUGGINGFACE_LOGITS'
Corresponds to HuggingfaceLogitsLM
.
HUGGINGFACE_SEQUENCE class-attribute
instance-attribute
HUGGINGFACE_SEQUENCE = 'HUGGINGFACE_SEQUENCE'
Corresponds to HuggingfaceSequenceLM
.
bocoel.factories.classifier
classifier(
name: str | ClassifierName,
/,
*,
model_path: str,
batch_size: int,
choices: Sequence[str],
device: str = "auto",
add_sep_token: bool = False,
) -> ClassifierModel
Source code in src/bocoel/factories/lms.py
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 |
|
bocoel.factories.OptimizerName
Bases: StrEnum
The names of the optimizers.
BAYESIAN class-attribute
instance-attribute
BAYESIAN = 'BAYESIAN'
Corresponds to AxServiceOptimizer
.
KMEANS class-attribute
instance-attribute
KMEANS = 'KMEANS'
Corresponds to KMeansOptimizer
.
KMEDOIDS class-attribute
instance-attribute
KMEDOIDS = 'KMEDOIDS'
Corresponds to KMedoidsOptimizer
.
RANDOM class-attribute
instance-attribute
RANDOM = 'RANDOM'
Corresponds to RandomOptimizer
.
BRUTE class-attribute
instance-attribute
BRUTE = 'BRUTE'
Corresponds to BruteForceOptimizer
.
UNIFORM class-attribute
instance-attribute
UNIFORM = 'UNIFORM'
Corresponds to UniformOptimizer
.
bocoel.factories.optimizer
optimizer(
name: str | OptimizerName,
/,
*,
corpus: Corpus,
adaptor: Adaptor,
**kwargs: Any,
) -> Optimizer
Create an optimizer instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | OptimizerName | The name of the optimizer. | required |
corpus | Corpus | The corpus to optimize. | required |
adaptor | Adaptor | The adaptor to use. | required |
**kwargs | Any | Additional keyword arguments to pass to the optimizer. See the documentation for the specific optimizer for details. | {} |
Returns:
Type | Description |
---|---|
Optimizer | The optimizer instance. |
Raises:
Type | Description |
---|---|
ValueError | If the name is unknown. |
Source code in src/bocoel/factories/optim.py
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 |
|