CNN
CNN
Bases: Module
Source code in engines/contentFilterEngine/nn_based_algorithms/cnn.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
__init__(input_dim, num_classes, emb_dim=128, kernel_sizes=[3, 4, 5], num_filters=100, dropout=0.5)
Initialize the CNN model for classification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim
|
int
|
Dimension of the input features. |
required |
num_classes
|
int
|
Number of output classes. |
required |
emb_dim
|
int
|
Embedding dimension. |
128
|
kernel_sizes
|
list
|
List of kernel sizes for convolution. |
[3, 4, 5]
|
num_filters
|
int
|
Number of filters per kernel size. |
100
|
dropout
|
float
|
Dropout rate. |
0.5
|
Source code in engines/contentFilterEngine/nn_based_algorithms/cnn.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
forward(x)
Forward pass of the CNN model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor of shape (batch_size, input_dim). |
required |
Returns:
Type | Description |
---|---|
torch.Tensor: Output logits of shape (batch_size, num_classes). |
Source code in engines/contentFilterEngine/nn_based_algorithms/cnn.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|