def build_correct_evolutionary_setup():
    search_space = search_spaces.TextClassifierSearchSpace()
    search_strategy = search_strategies.EvolutionarySearch()
    search_space.add_budget(param.Budget.GENERATIONS, 10)
    search_space.add_evaluation_metric(param.EvaluationMetric.MICRO_F1_SCORE)
    search_space.add_optimization_value(param.OptimizationValue.DEV_SCORE)
    search_space.add_parameter(param.ModelTrainer.LEARNING_RATE,
                               options=[0.01, 0.05, 0.1])

    search_space.add_parameter(param.DocumentRNNEmbeddings.HIDDEN_SIZE,
                               options=[128, 256, 512])
    search_space.add_parameter(param.DocumentRNNEmbeddings.WORD_EMBEDDINGS,
                               options=[['glove'], ['en'], ['en', 'glove']])

    search_space.add_parameter(param.DocumentPoolEmbeddings.WORD_EMBEDDINGS,
                               options=[['glove'], ['en'], ['en', 'glove']])
    search_space.add_parameter(param.DocumentPoolEmbeddings.POOLING,
                               options=['mean', 'max', 'min'])
    return search_space, search_strategy
Пример #2
0
from FlairParamOptimizer import search_strategies, search_spaces, orchestrator
import FlairParamOptimizer.parameter_listings.parameters_for_user_input as param

from flair.datasets import UD_ENGLISH

corpus = UD_ENGLISH().downsample(0.5)

search_space = search_spaces.SequenceTaggerSearchSpace()
search_strategy = search_strategies.EvolutionarySearch()

search_space.add_tag_type("pos")

search_space.add_budget(param.Budget.TIME_IN_H, 24)
search_space.add_evaluation_metric(param.EvaluationMetric.MICRO_F1_SCORE)
search_space.add_optimization_value(param.OptimizationValue.DEV_SCORE)
search_space.add_max_epochs_per_training_run(50)

search_space.add_parameter(param.SequenceTagger.HIDDEN_SIZE,
                           options=[128, 256, 512])
search_space.add_parameter(param.SequenceTagger.DROPOUT,
                           options=[0, 0.1, 0.2, 0.3])
search_space.add_parameter(param.SequenceTagger.WORD_DROPOUT,
                           options=[0, 0.01, 0.05, 0.1])
search_space.add_parameter(param.SequenceTagger.RNN_LAYERS,
                           options=[2, 3, 4, 5, 6])
search_space.add_parameter(param.SequenceTagger.USE_RNN, options=[True, False])
search_space.add_parameter(param.SequenceTagger.USE_CRF, options=[True, False])
search_space.add_parameter(param.SequenceTagger.REPROJECT_EMBEDDINGS,
                           options=[True, False])
search_space.add_parameter(param.SequenceTagger.WORD_EMBEDDINGS,
                           options=[['glove'], ['en'], ['en', 'glove']])
from FlairParamOptimizer import search_strategies, search_spaces, orchestrator
import FlairParamOptimizer.parameter_listings.parameters_for_user_input as param
from flair.datasets import SENTEVAL_CR
from torch.optim import SGD, Adam

# 1.) Define your corpus
corpus = SENTEVAL_CR()

# 2.) create an search space
search_space = search_spaces.TextClassifierSearchSpace()
search_strategy = search_strategies.EvolutionarySearch(population_size=8)

# 3.) depending on your task add the respective parameters you want to optimize over
search_space.add_budget(param.Budget.TIME_IN_H, 24)
search_space.add_evaluation_metric(param.EvaluationMetric.MICRO_F1_SCORE)
search_space.add_optimization_value(param.OptimizationValue.DEV_SCORE)
search_space.add_max_epochs_per_training_run(15)

#Depending on your downstream task, add embeddings and specify these with the respective Parameters below
search_space.add_parameter(param.ModelTrainer.LEARNING_RATE,
                           options=[0.01, 0.05, 0.1])
search_space.add_parameter(param.ModelTrainer.MINI_BATCH_SIZE,
                           options=[16, 32, 64])
search_space.add_parameter(param.ModelTrainer.ANNEAL_FACTOR,
                           options=[0.25, 0.5])
search_space.add_parameter(param.ModelTrainer.OPTIMIZER, options=[SGD, Adam])
search_space.add_parameter(param.Optimizer.WEIGHT_DECAY, options=[1e-2, 0])

#Define parameters for document embeddings RNN
search_space.add_parameter(param.DocumentRNNEmbeddings.HIDDEN_SIZE,
                           options=[128, 256, 512])