Skip to content

Instantly share code, notes, and snippets.

View seanie12's full-sized avatar
🎲

Seanie Lee seanie12

🎲
View GitHub Profile
@seanie12
seanie12 / seq2seq_attention.py
Last active February 15, 2019 01:57
sequence to sequence with attention in Keras
import tensorflow as tf
import os
import numpy as np
# settings for GPU
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
config.gpu_options.per_process_gpu_memory_fraction = 0.9
sess = tf.Session(config=config)
@seanie12
seanie12 / seq2seq_attention.py
Last active February 19, 2019 06:51
char-level seq2seq with attention
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
import random
import numpy as np
import re, unicodedata
random.seed(1024)
@seanie12
seanie12 / utils.py
Created February 22, 2019 01:46
using dataset
import json
import logging
import os
import shutil
import torch
import torch.utils.data as data
import config
import numpy as np
import pickle
train_x_file = "./data/train_x"
train_y_file = "./data/train_y"
dev_x_file = "./data/dev_x"
dev_y_file = "./data/dev_y"
input_file = "./data/input.pkl"
label_file = "./data/label.pkl"
import json
from pytorch_pretrained_bert.tokenization import whitespace_tokenize
import collections
from copy import deepcopy
class SquadExample(object):
"""
A single training/test example for the Squad dataset.
For examples without an answer, the start and end position are -1.
"""
import torch
from pytorch_pretrained_bert import BertTokenizer
import random
import numpy as np
from squad_utils import convert_examples_to_features, read_squad_examples
import config
tokenizer = BertTokenizer.from_pretrained("bert-base-uncased", do_lower_case=True)
train_examples = read_squad_examples("./squad/train-v1.1.json", is_training=True, debug=False)
train_features = convert_examples_to_features(train_examples, tokenizer=tokenizer,
<better case>
golden: when did abc first start ?
dual: when was abc originally launched by edward j . noble ?
base: what is the name of abc ' s radio network ?
golden : what kind of markets did nbc red serve ?
dual: when was nbc red served by nbc red ?
base: when was the nbc blue network created ?
import collections
import json
import re
import string
import sys
import torch
from pytorch_pretrained_bert import BertForQuestionAnswering, BertTokenizer
from torch.utils.data import SequentialSampler, DataLoader, TensorDataset
from model import Seq2seq
import os
from squad_utils import read_squad_examples, convert_examples_to_features, write_predictions
from pytorch_pretrained_bert import BertTokenizer, BertForQuestionAnswering
import torch
from torch.utils.data import DataLoader, TensorDataset
import torch.nn.functional as F
import config
import collections
import re, string, sys, json
# old files
train_src_file = "./squad/para-train.txt"
train_trg_file = "./squad/tgt-train.txt"
dev_src_file = "./squad/para-dev.txt"
dev_trg_file = "./squad/tgt-dev.txt"
test_src_file = "./squad/para-test.txt"
test_trg_file = "./squad/tgt-test.txt"
embedding = "./data/embedding.pkl"
word2idx_file = "./data/word2idx.pkl"