NLP Deep Learning Framework
This is a deepl learning framework for classification and seq2seq tasks.
Installation
pip install deep-nlp
Example Project
Structure
├── data --> containing the trainings and validation data
| ├── train.csv --> training dataset
| └── val.csv --> validation dataset
├── Experiment.py --> containing the model and training logic
└── dataset.py --> containing the Dataset object
Dataset.py
from torch.utils.data import Dataset
import pandas as pd
class ExampleDataset(Dataset):
def __init__(self, split : str):
self.data = pd.read_csv(f'{split}.csv')
def __len__(self):
return len(self.data)
def __getitem__(self, idx):
return self.data.iloc[idx]
Experiment.py
from deep_nlp import Experiment, unpack
from dataset import ExampleDataset
from transformers import DistilBertTokenizerFast, DistilBertForSequenceClassification
import torch
class ClassificationExperiment(Experiment):
def get_tokenizer(self):
tokenizer = DistilBertTokenizerFast.from_pretrained('distilbert-base-uncased')
return tokenizer
def get_model(self):
model = DistilBertForSequenceClassification.from_pretrained('distilbert-base-uncased')
return model
def batch_fn(self, batch):
source, target = zip(*batch)
source_inp = self.tokenizer(source, padding=True, return_tensors=True)
target = torch.tensor(target)
return unpack(source_inp, target)
def run_experiment():
experiment = ClassificationExperiment(
80, # batch size
20, # number of epochs
ExampleDataset,
gpus=-1, # use all available gpus
lr=2.65e-5,
weight_decay=4e-3,
name='example_run' # name for mlflow
)
experiment.run()
if __name__ == '__main__':
run_experiment()
Release files for deep-nlp 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| deep-nlp-0.0.1.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| deep_nlp-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / deep-nlp-0.0.1.tar.gz
| Download URL | deep-nlp-0.0.1.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
79739e6fe43463240c734ee9e30595896b1777250da2ace7c0de404190cadf17
|
|
BLAKE2b-256 checksum How to use checksums |
01cd048a8b0609796e80ab4d309a682c2a3dbb9b48f66e0d05de1fcf62d1cda6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5
|
Release files / deep_nlp-0.0.1-py3-none-any.whl
| Download URL | deep_nlp-0.0.1-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5c6d6b4a5fc667bce03b7b568d2efeb96a413d61fa63df699cb98ba2f04e2b5
|
|
BLAKE2b-256 checksum How to use checksums |
5a14e26305d10e90b7b73352736b108a4aea388d0e63aed381d5fd7a451f8996
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5
|