Skip to content

Instantly share code, notes, and snippets.

View nissan's full-sized avatar

Nissan Dookeran nissan

View GitHub Profile
@nissan
nissan / dataframe_dataset.py
Created August 27, 2018 00:27 — forked from lextoumbourou/dataframe_dataset.py
Torchtext dataset from DataFrame
from torchtext import data
class DataFrameDataset(data.Dataset):
def __init__(self, df, text_field, label_field, is_test=False, **kwargs):
fields = [('text', text_field), ('label', label_field)]
examples = []
for i, row in df.iterrows():
label = row.sentiment if not is_test else None
text = row.text
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nissan
nissan / predictions.py
Created August 27, 2018 00:27 — forked from lextoumbourou/predictions.py
Making predictions with a SequentialRNN model (Fast.ai)
# Note: ensure you have the latest version of Torchtext by running: pip install torchtext --upgrade
rnn_model = text_data.get_model(opt_fn, 1500, bptt, emb_sz=em_sz, n_hid=nh, n_layers=nl,
dropout=0.1, dropouti=0.65, wdrop=0.5, dropoute=0.1, dropouth=0.3)
# ...
rnn_model.data.test_dl.src.sort = False
rnn_model.data.test_dl.src.sort_within_batch = False
rnn_model.data.test_dl.src.shuffle = False