def build_simple_cnn_text_classifier(tok2vec, nr_class, exclusive_classes=False, **cfg):
with Model.define_operators({"<STR_LIT>": chain}):<EOL><INDENT>if exclusive_classes:<EOL><INDENT>output_layer = Softmax(nr_class, tok2vec.nO)<EOL><DEDENT>else:<EOL><INDENT>output_layer = (<EOL>zero_init(Affine(nr_class, tok2vec.nO, drop_factor=<NUM_LIT:0.0>)) >> logistic<EOL>)<EOL><DEDENT>model = tok2vec >> flatten_add_lengths >> Pooling(mean_pool) >> output_layer<EOL><DEDENT>model.tok2vec = chain(tok2vec, flatten)<EOL>model.nO = nr_class<EOL>return model<EOL>
Build a simple CNN text classifier, given a token-to-vector model as inputs.
If exclusive_classes=True, a softmax non-linearity is applied, so that the
outputs sum to 1. If exclusive_classes=False, a logistic non-linearity
is applied instead, so that outputs are in the range [0, 1].