Skip to content

Commit e3f3649

Browse files
gg
1 parent c33ad9a commit e3f3649

28 files changed

+422
-112
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,4 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161+
.history/

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[python]": {
3+
"editor.defaultFormatter": "ms-python.black-formatter"
4+
},
5+
"python.formatting.provider": "none"
6+
}

ML/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import math
2+
import os
3+
import random
4+
import threading
5+
from typing import *
6+
import time
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
import pandas as pd
10+
import torch
11+
import torchinfo
12+
import torchvision
13+
import wandb
14+
from PIL import Image
15+
from sklearn.model_selection import train_test_split
16+
from torch import nn, optim
17+
from torch.utils.data import DataLoader, Dataset
18+
from torchvision import transforms
19+
from torchvision.models import *
20+
from tqdm import tqdm
21+
from wandb import AlertLevel
22+
from torch.nn import *
23+
from torchvision.models import *
24+
import torchtext
25+
from torchtext.transforms import *
26+
from torchtext.models import *
27+
from sklearn.metrics import classification_report
28+
29+
print(torch.__version__, torchvision.__version__, torchtext.__version__)
30+
os.environ["CUDA_LAUNCH_BLOCKING"] = "1"
31+
# os.environ["WANDB_SILENT"] = "true"
32+
PROJECT_NAME = "NLP-Disaster Tweets"
33+
device = torch.device("cuda")
34+
BATCH_SIZE = 32
35+
torch.backends.cudnn.benchmark = True
36+
torch.cuda.empty_cache()
37+
torch.manual_seed(42)
38+
np.random.seed(42)
39+
torch.cuda.manual_seed(42)
40+
41+
from ML.dataset import *
42+
from ML.helper_functions import *
43+
from ML.metrics import *
44+
from ML.modelling import *

ML/dataset/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from ML.dataset.loader import *
2+
from ML.dataset.main_loaders import *
3+
from ML.dataset.valid_loaders import *

ML/dataset/loader.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from ML import *
2+
3+
4+
class Loader(Dataset):
5+
def __init__(self, path: str, transform=None) -> None:
6+
self.path = path
7+
self.transform = transform
8+
self.data: pd.DataFrame = pd.read_csv(self.path)
9+
10+
def __len__(self) -> int:
11+
return len(self.data)

ML/dataset/main_loaders.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from ML import *
2+
3+
4+
class Main_DL(Loader):
5+
def __init__(self, train: bool = True, test_split: float = 0.125, seed: int = 42) -> None:
6+
super().__init__()
7+
self.X = self.data["text"].to_numpy()
8+
self.y = self.data["target"].to_numpy()
9+
self.train = train
10+
self.test_split = test_split
11+
self.seed = seed
12+
self.X_train, self.X_test, self.y_train, self.y_test = train_test_split(
13+
self.X, self.y, test_size=test_split, random_state=seed
14+
)
15+
16+
def __getitem__(self, index) -> Tuple[torch.tensor, torch.tensor]:
17+
if self.train:
18+
return (
19+
self.transform(self.X_train[index]) if self.transform else self.X_train[index],
20+
self.y_train[index],
21+
)
22+
return (
23+
self.transform(self.X_test[index]) if self.transform else self.X_test[index],
24+
self.y_test[index],
25+
)
26+
27+
def __len__(self) -> int:
28+
return len(self.y_train) if self.train else len(self.y_test)

ML/dataset/test_loaders.py

Whitespace-only changes.

ML/dataset/train_loaders.py

Whitespace-only changes.

ML/dataset/valid_loaders.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from ML import *
2+
3+
4+
class Valid_Loader(Loader):
5+
def __init__(self) -> None:
6+
super().__init__()
7+
self.X = self.data["text"].to_numpy()
8+
9+
def __getitem__(self, index) -> np.array:
10+
return self.X[index]

ML/helper_functions/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from ML.helper_functions.load_data import *
2+
from ML.helper_functions.test import *
3+
from ML.helper_functions.train import *
4+
from ML.helper_functions.transformer import *

0 commit comments

Comments
 (0)