Upload folder using huggingface_hub
Browse files- README.md +27 -0
- best_model.pt +3 -0
- model.py +68 -0
- requirements.txt +3 -0
- tokenizer/tokenizer.json +0 -0
- tokenizer/tokenizer_config.json +14 -0
README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# StrongTextCNN
|
| 3 |
+
|
| 4 |
+
A CNN-based text classification model trained using PyTorch.
|
| 5 |
+
|
| 6 |
+
## Model Architecture
|
| 7 |
+
|
| 8 |
+
- Embedding Layer (300 dimensions)
|
| 9 |
+
- Conv1D kernels: 2, 3, 4, 5
|
| 10 |
+
- 128 filters each
|
| 11 |
+
- Batch Normalization
|
| 12 |
+
- Fully Connected Layers:
|
| 13 |
+
- 512 → 256
|
| 14 |
+
- 256 → 64
|
| 15 |
+
- 64 → 1
|
| 16 |
+
- Dropout = 0.4
|
| 17 |
+
|
| 18 |
+
## Files
|
| 19 |
+
|
| 20 |
+
- model.py
|
| 21 |
+
- best_model.pt
|
| 22 |
+
- tokenizer/
|
| 23 |
+
|
| 24 |
+
## Usage
|
| 25 |
+
|
| 26 |
+
```python
|
| 27 |
+
from model import StrongTextCNN
|
best_model.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9acaade9422b45680fc6d30d38ed35fe8937b0661f75ba1320e00c104b7288b4
|
| 3 |
+
size 39385653
|
model.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import torch
|
| 3 |
+
import torch.nn as nn
|
| 4 |
+
import torch.nn.functional as F
|
| 5 |
+
|
| 6 |
+
class StrongTextCNN(nn.Module):
|
| 7 |
+
|
| 8 |
+
def __init__(
|
| 9 |
+
self,
|
| 10 |
+
vocab_size,
|
| 11 |
+
embed_dim=300,
|
| 12 |
+
num_filters=128,
|
| 13 |
+
dropout=0.4
|
| 14 |
+
):
|
| 15 |
+
super().__init__()
|
| 16 |
+
|
| 17 |
+
self.embedding = nn.Embedding(
|
| 18 |
+
vocab_size,
|
| 19 |
+
embed_dim,
|
| 20 |
+
padding_idx=0
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
self.convs = nn.ModuleList([
|
| 24 |
+
nn.Conv1d(embed_dim, num_filters, k)
|
| 25 |
+
for k in [2,3,4,5]
|
| 26 |
+
])
|
| 27 |
+
|
| 28 |
+
self.bn = nn.BatchNorm1d(num_filters * 4)
|
| 29 |
+
|
| 30 |
+
self.fc1 = nn.Linear(num_filters * 4, 256)
|
| 31 |
+
self.fc2 = nn.Linear(256, 64)
|
| 32 |
+
self.out = nn.Linear(64, 1)
|
| 33 |
+
|
| 34 |
+
self.dropout = nn.Dropout(dropout)
|
| 35 |
+
|
| 36 |
+
def forward(self, x):
|
| 37 |
+
|
| 38 |
+
x = self.embedding(x)
|
| 39 |
+
x = x.permute(0,2,1)
|
| 40 |
+
|
| 41 |
+
conv_outputs = []
|
| 42 |
+
|
| 43 |
+
for conv in self.convs:
|
| 44 |
+
|
| 45 |
+
c = F.relu(conv(x))
|
| 46 |
+
|
| 47 |
+
p = F.max_pool1d(
|
| 48 |
+
c,
|
| 49 |
+
kernel_size=c.shape[2]
|
| 50 |
+
).squeeze(2)
|
| 51 |
+
|
| 52 |
+
conv_outputs.append(p)
|
| 53 |
+
|
| 54 |
+
x = torch.cat(conv_outputs, dim=1)
|
| 55 |
+
|
| 56 |
+
x = self.bn(x)
|
| 57 |
+
|
| 58 |
+
x = self.dropout(x)
|
| 59 |
+
|
| 60 |
+
x = F.relu(self.fc1(x))
|
| 61 |
+
x = self.dropout(x)
|
| 62 |
+
|
| 63 |
+
x = F.relu(self.fc2(x))
|
| 64 |
+
x = self.dropout(x)
|
| 65 |
+
|
| 66 |
+
x = self.out(x)
|
| 67 |
+
|
| 68 |
+
return x.squeeze(1)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|
| 3 |
+
tokenizers
|
tokenizer/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer/tokenizer_config.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"do_lower_case": true,
|
| 5 |
+
"is_local": false,
|
| 6 |
+
"mask_token": "[MASK]",
|
| 7 |
+
"model_max_length": 512,
|
| 8 |
+
"pad_token": "[PAD]",
|
| 9 |
+
"sep_token": "[SEP]",
|
| 10 |
+
"strip_accents": null,
|
| 11 |
+
"tokenize_chinese_chars": true,
|
| 12 |
+
"tokenizer_class": "BertTokenizer",
|
| 13 |
+
"unk_token": "[UNK]"
|
| 14 |
+
}
|