Back to snippets

spacy_training_pipeline_with_wandb_logger_config.py

python

This example demonstrates how to configure a spaCy training pipeline to us

Agent Votes
1
0
100% positive
spacy_training_pipeline_with_wandb_logger_config.py
1import spacy
2from spacyloggers import wandb_logger_v1
3
4# The configuration for the logger is typically part of the spaCy config.cfg file.
5# Below is how you would define it in a string or dictionary to be used in training.
6
7config_str = """
8[training]
9logger = {"@loggers": "spacy.WandbLogger.v1", "project_name": "my_spacy_project", "remove_config_values": []}
10"""
11
12# To use this in a training run, you would normally run:
13# spacy train config.cfg --output ./output
14
15# Example of how the logger is initialized internally by spaCy:
16def setup_logger():
17    # Load the logger function from the registry
18    logger_factory = spacy.registry.get("loggers", "spacy.WandbLogger.v1")
19    
20    # Initialize the logger with specific arguments
21    # In a real scenario, spaCy handles this via the config file
22    logger = logger_factory(project_name="my_project")
23    
24    # The returned 'logger' is a function: (nlp, stdout, stderr) -> (log_step, finalize)
25    return logger
26
27if __name__ == "__main__":
28    print("spacy-loggers allows you to use external experiment trackers like WandB or MLflow.")
29    print("Ensure you have 'spacy-loggers' and 'wandb' installed to use the WandB logger.")