I have two separate models that I have trained: one for one-hot encoded data, and one for text data. The models are defined below.
Model for one-hot encoded data:
training_data = TabularPandas(
df=training_dataframe,
procs=[Categorify],
cat_names=BINARY_COLS,
splits=splits,
y_names=TARGET_COL,
)
training_dataloaders = training_data.dataloaders(1024)
learner = tabular_learner(
training_dataloaders,
layers=[256,256],
loss_func=CrossEntropyLossFlat(),
metrics=[accuracy],
model_dir=MODELS_DIR,
)
test_dataloaders = learner.dls.test_dl(test_dataframe_one_hot)
probabilities, targets = learner.get_preds(dl=test_dataloaders)
Model for text data:
classifier_text_block = TextBlock.from_df(
text_cols=[SEQUENCE_COL],
vocab=language_model_dataloaders.vocab,
tok=bpe_tokenizer,
n_workers=8,
)
classifier_data_block = DataBlock(
blocks=(classifier_text_block, CategoryBlock),
get_x=ColReader("text"),
get_y=ColReader(TARGET_COL),
splitter=training_validation_split,
)
classifier_dataloaders = classifier_data_block.dataloaders(
training_data,
bs=128,
seq_len=80
)
classifier = text_classifier_learner(
dls=classifier_dataloaders,
arch=AWD_LSTM,
seq_len=80,
config=lstm_clas_configuration,
pretrained=False,
metrics=[accuracy],
model_dir=MODELS_DIR,
).to_fp16()
classifier = classifier.load_encoder("lstm_language_model_finetuned")
test_dataloaders = classifier.dls.test_dl(test_dataframe_text)
probabilities, targets = classifier.get_preds(dl=test_dataloaders)
I have already trained both models. Now, I want to take the output from both of those models and use those as inputs to a new model that effectively combines the binary and text models into a larger model. How do I do this?
(I read a few forum posts that seem to describe something similar, but I’m having trouble understanding them and how it applies to my situation.)
If anyone is able to help, I’d greatly appreciate it!