-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentiment_model_trainer_factory.py
23 lines (18 loc) · 1.09 KB
/
sentiment_model_trainer_factory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from sentiment_model_trainer_mira import SentimentModelTrainerMIRA
from sentiment_model_trainer_swvm import SentimentModelTrainerSWVM
from sentiment_model_trainer_base import Corpus, CorpusFeaturesExtractor, SentimentModelConfiguration
from utils import Singleton
class SentimentModelTrainerFactory(Singleton):
trainer_algorithms_dict = {
'mira': SentimentModelTrainerMIRA,
'SWVM': SentimentModelTrainerSWVM
}
def create_trainer(self, train_corpus: Corpus, features_extractor: CorpusFeaturesExtractor,
model_config: SentimentModelConfiguration, *args, **kwargs):
if model_config.trainer_alg not in self.trainer_algorithms_dict:
raise ValueError('`{}` is not a valid training algorithm type. Supported types are: {}'.format(
model_config.trainer_alg,
list(self.trainer_algorithms_dict.keys())
))
trainer_alg_type_constructor = self.trainer_algorithms_dict[model_config.trainer_alg]
return trainer_alg_type_constructor(train_corpus, features_extractor, model_config, *args, **kwargs)