Filter
Specifies criteria for experiments or attributes when using a fetching method.
Examples of filters:
- Name or attribute value matches regular expression.
- Attribute value passes a condition, like "greater than 0.9".
- Attribute of a given name must exist.
You can negate a filter or join multiple filters with logical operators.
Methods for attributes
The following functions create a criterion based on the value of an attribute:
Method | Description | Example |
---|---|---|
name() | Run or experiment name matches a regex or a list of names | Filter.name(["kittiwake_week12"]) |
eq() | Attribute value equals | Filter.eq("lr", 0.001) |
ne() | Attribute value doesn't equal | Filter.ne("sys/owner", "bot@my-workspace") |
gt() | Attribute value is greater than | Filter.gt("acc", 0.9) |
ge() | Attribute value is greater than or equal to | Filter.ge("acc", 0.93) |
lt() | Attribute value is less than | Filter.lt("loss", 0.1) |
le() | Attribute value is less than or equal to | Filter.le("loss", 0.11) |
matches() | String attribute value matches a regular expression | Filter.matches("optimizer", r"^Ada | grad") |
contains_all() | Filter.contains_all("sys/tags", ["best", "v2.1"]) | |
contains_none() | Filter.contains_none("tokenizer", "bpe") | |
exists() | Attribute exists | Filter.exists("metric7") |
For details, see the source on GitHub: src/neptune_query/filters.py
Methods for filters
Negation
To negate a filter, use negate()
or prepend ~
to the filter:
from neptune_query.filters import Filter
owned_by_me = Filter.eq("sys/owner", "vidar")
owned_by_someone_else = negate(owned_by_me)
# equivalent to
owned_by_someone_else = ~owned_by_me
Conjunction (logical AND)
Conjoin filters with &
:
loss_filter = Filter.lt("validation/loss", 0.1)
owned_by_me_and_small_loss = owned_by_me & loss_filter
Alternation (logical OR)
Alternate filters with |
:
owned_by_me_or_small_loss = owned_by_me | loss_filter
Examples
Fetch loss values from experiments with specific tags:
import neptune_query as nq
from neptune_query.filters import Filter
specific_tags = Filter.contains_all("sys/tags", ["fly", "swim", "nest"])
nq.fetch_metrics(experiments=specific_tags, attributes=r"^metrics/loss/")
List my experiments that have a "dataset_version" attribute and "validation/loss" less than 0.1:
owned_by_me = Filter.eq("sys/owner", "sigurd")
dataset_check = Filter.exists("dataset_version")
loss_filter = Filter.lt("validation/loss", 0.1)
interesting = owned_by_me & dataset_check & loss_filter
nq.list_experiments(experiments=interesting)
Fetch configs from the interesting experiments:
nq.fetch_experiments_table(experiments=interesting, attributes=r"config/")