Skip to content

Commit 500399e

Browse files
committed
Add comments
1 parent 2efad73 commit 500399e

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The aim of this repository is to show a baseline model for text classification by implementing a LSTM-based model coded in PyTorch. In order to provide a better understanding of the model, it will be used a dataset of Tweets provided by Kaggle.
44

55
## 1. Data
6-
As it was mentioned above, the dataset we are woking with is about Tweets regarding fake news. The head of the dataset looks like this:
6+
As it was mentioned above, the implemented dataset is about Tweets regarding fake news. The ``raw``dataset contains some unnecessary columns which are going to be removed in the preprocessing step, in the end, we will be working with a dataset with a head such as this:
77

88
|id| text | target |
99
| ------------- | ------------- | ------------- |
@@ -12,7 +12,7 @@ As it was mentioned above, the dataset we are woking with is about Tweets regard
1212
| 3 | INEC Office in Abia Set Ablaze - http://t.co/3ImaomknnA | 1 |
1313
| 4 | Building the perfect tracklist to life leave the streets ablaze | 0 |
1414

15-
This dataset can be found in ``data/tweets.csv``.
15+
This raw dataset can be found in ``data/tweets.csv``.
1616

1717
## 2. The model
1818
As it was already commented, the aim of this repository is to provide a base line model for text classfication. In this sense, the model is based on a two-stacked LSTM layers followed by two linear layers. The dataset is preprocessed through a tokens-based technique, then tokens are associated to an embedding layer. The following image describes the pipeline of the model.
@@ -21,13 +21,33 @@ As it was already commented, the aim of this repository is to provide a base lin
2121
Working on
2222

2323
## 4. How to use it
24+
The model can be executed easily by typing:
2425
```
25-
python -B main.py
26+
python main.py
2627
```
2728
You can define some hyperparameters manually, such as:
2829
```
2930
main.py [-h] [--epochs EPOCHS] [--learning_rate LEARNING_RATE]
3031
[--hidden_dim HIDDEN_DIM] [--lstm_layers LSTM_LAYERS]
3132
[--batch_size BATCH_SIZE] [--test_size TEST_SIZE]
3233
[--max_len MAX_LEN] [--max_words MAX_WORDS]
34+
```
35+
36+
## 5. Demo
37+
The follwowing configuration was implemented in order to achieve the best results
38+
```
39+
python -B main.py --epochs 10 --learning_rate 0.01 --hidden_dim 128 --lstm_layers 2 --batch_size 64
40+
```
41+
by getting the following output:
42+
```
43+
Epoch: 1, loss: 0.53032, Train accuracy: 0.59376, Test accuracy: 0.63099
44+
Epoch: 2, loss: 0.43361, Train accuracy: 0.63251, Test accuracy: 0.72948
45+
Epoch: 3, loss: 0.36803, Train accuracy: 0.76141, Test accuracy: 0.75509
46+
Epoch: 4, loss: 0.26117, Train accuracy: 0.80821, Test accuracy: 0.77807
47+
Epoch: 5, loss: 0.19844, Train accuracy: 0.83547, Test accuracy: 0.77741
48+
Epoch: 6, loss: 0.16377, Train accuracy: 0.86453, Test accuracy: 0.77216
49+
Epoch: 7, loss: 0.02130, Train accuracy: 0.88391, Test accuracy: 0.75509
50+
Epoch: 8, loss: 0.00315, Train accuracy: 0.89704, Test accuracy: 0.74787
51+
Epoch: 9, loss: 0.02075, Train accuracy: 0.91018, Test accuracy: 0.76428
52+
Epoch: 10, loss: 0.01348, Train accuracy: 0.92808, Test accuracy: 0.75378
3353
```

0 commit comments

Comments
 (0)