NAS-Bench-NLP
Bases: Graph
Represents the search space for NAS (Neural Architecture Search) in the context of NLP (Natural Language Processing).
Note
Currently, building a NASLib object for nas-bench-nlp architectures is not supported.
Attributes:
Name | Type | Description |
---|---|---|
QUERYABLE |
bool
|
Specifies whether this class supports querying architectures. |
__init__()
Initialize a new instance of the search space.
encode(encoding_type=EncodingType.ADJACENCY_ONE_HOT)
Encodes the architecture into a specific format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoding_type |
EncodingType
|
The type of encoding to use. Defaults to |
EncodingType.ADJACENCY_ONE_HOT
|
Returns:
Type | Description |
---|---|
The encoded representation of the architecture. |
get_arch_iterator(dataset_api=None)
Get an iterator for iterating over the architectures in the dataset API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_api |
dict
|
The dataset API containing information about architectures. |
None
|
Returns:
Type | Description |
---|---|
np.array: An array of architecture representations to be iterated over. |
get_compact()
Get the compact representation of the architecture.
Returns:
Type | Description |
---|---|
Compact representation of the architecture. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the compact representation is not set. |
get_hash()
Get the hash based on the architecture's compact representation.
Returns:
Type | Description |
---|---|
Hash representation of the architecture. |
get_max_epochs()
Gets the maximum number of epochs for training.
Returns:
Name | Type | Description |
---|---|---|
int |
The maximum number of epochs (49). |
get_nbhd(dataset_api=None)
Gets the neighborhood architectures based on the current architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_api |
object
|
The dataset API for querying architectures. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
list |
List of neighborhood architectures. |
Currently has the same todo's as in mutate()
get_type()
Gets the type of the search space.
Returns:
Name | Type | Description |
---|---|---|
str |
The type of the search space ("nlp"). |
load_labeled_architecture(dataset_api=None, max_nodes=12)
Load a labeled architecture into the search space.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_api |
Dataset API containing information about available architectures. |
None
|
|
max_nodes |
int
|
Maximum number of nodes for the architecture. |
12
|
Returns:
Name | Type | Description |
---|---|---|
None |
The architecture is loaded into the instance. |
mutate(parent, mutation_rate=1, dataset_api=None)
Mutates the architecture by altering edges or operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent |
object
|
Parent architecture. |
required |
mutation_rate |
int
|
Number of mutations to perform. Defaults to 1. |
1
|
dataset_api |
object
|
The dataset API for querying architectures. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
None |
Modifies the architecture in place. |
Todo: mutate by adding/removing nodes. Todo: mutate the list of hidden nodes. Todo: edges between initial hidden nodes are not mutated.
query(metric=None, dataset=None, path=None, epoch=-1, full_lc=False, dataset_api=None)
Query the architecture's performance metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric |
Metric
|
Metric to query. |
None
|
dataset |
str
|
The dataset to query against. |
None
|
path |
str
|
File path for the saved architecture. |
None
|
epoch |
int
|
The epoch at which to query the metric. |
-1
|
full_lc |
bool
|
Whether to query the full learning curve. |
False
|
dataset_api |
The dataset API to be used for the query. |
None
|
Returns:
Type | Description |
---|---|
Union[int, float, dict, list]: Query results. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If querying metrics for extra training epochs is attempted. |
sample_random_architecture(dataset_api)
Samples a random architecture that satisfies the constraints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_api |
The dataset API for querying architectures. |
required |
Returns:
Type | Description |
---|---|
The compact representation of the sampled architecture. |
set_compact(compact)
Set the compact representation of the architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compact |
The compact representation of the architecture. |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
The architecture is updated in-place. |
set_spec(compact, dataset_api=None)
Set the architecture specification. This function exists to unify the interface across search spaces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compact |
The compact representation of the architecture. |
required | |
dataset_api |
The dataset API. |
None
|
Returns:
Name | Type | Description |
---|---|---|
None |
The architecture specification is set. |