This is an implementation created by Ignacio Oguiza based on fastai's TabularModel - oguiza@gmail.com. I build it so that it's easy to change the head of the model, something that is particularly interesting when building hybrid models.
from tsai.data.tabular import *
from tsai.models.utils import *

class TabModel[source]

TabModel(emb_szs, n_cont, c_out, layers=None, fc_dropout=None, embed_p=0.0, y_range=None, use_bn=True, bn_final=False, bn_cont=True, lin_first=False, act=ReLU(inplace=True), skip=False) :: Sequential

Basic model for tabular data.

class TabBackbone[source]

TabBackbone(emb_szs, n_cont, embed_p=0.0, bn_cont=True) :: Module

Same as nn.Module, but no need for subclasses to call super().__init__

class TabHead[source]

TabHead(emb_szs, n_cont, c_out, layers=None, fc_dropout=None, y_range=None, use_bn=True, bn_final=False, lin_first=False, act=ReLU(inplace=True), skip=False) :: Module

Basic head for tabular data.

path = untar_data(URLs.ADULT_SAMPLE)
df = pd.read_csv(path/'adult.csv')
# df['salary'] = np.random.rand(len(df)) # uncomment to simulate a cont dependent variable
procs = [Categorify, FillMissing, Normalize]
cat_names = ['workclass', 'education', 'marital-status', 'occupation', 'relationship', 'race']
cont_names = ['age', 'fnlwgt', 'education-num']
y_names = ['salary']
y_block = RegressionBlock() if isinstance(df['salary'].values[0], float) else CategoryBlock()
splits = RandomSplitter()(range_of(df))
pd.options.mode.chained_assignment=None
to = TabularPandas(df, procs=procs, cat_names=cat_names, cont_names=cont_names, y_names=y_names, y_block=y_block, splits=splits, inplace=True, 
                   reduce_memory=False)
to.show(5)
tab_dls = to.dataloaders(bs=16, val_bs=32)
b = first(tab_dls.train)
test_eq((b[0].shape, b[1].shape, b[2].shape), (torch.Size([16, 7]), torch.Size([16, 3]), torch.Size([16, 1])))
workclass education marital-status occupation relationship race education-num_na age fnlwgt education-num salary
14458 Private HS-grad Married-civ-spouse Adm-clerical Wife White False 41.0 178002.0 9.0 >=50k
25443 Private Some-college Never-married Sales Own-child White False 24.0 142528.0 10.0 <50k
30430 Self-emp-not-inc Some-college Divorced Exec-managerial Not-in-family White False 47.0 173613.0 10.0 <50k
18434 Private Some-college Married-civ-spouse Exec-managerial Husband White False 25.0 114483.0 10.0 <50k
28000 ? 11th Never-married ? Own-child White False 17.0 215743.0 7.0 <50k
tab_model = build_tabular_model(TabModel, dls=tab_dls)
b = first(tab_dls.train)
test_eq(tab_model(*b[:-1]).shape, (tab_dls.bs, tab_dls.c))
learn = Learner(tab_dls, tab_model, splitter=ts_splitter)
p1 = count_parameters(learn.model)
learn.freeze()
p2 = count_parameters(learn.model)
learn.unfreeze()
p3 = count_parameters(learn.model)
assert p1 == p3
assert p1 > p2 > 0