This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start = np.random.randint(0,len(valid_list) - 150) | |
seed_list = valid_list[start:start+20] | |
current_string = [string2int[string] for string in seed_list] | |
for i in range(20): | |
input = torch.tensor(current_string,dtype=torch.long).cuda().reshape(1,-1) | |
output = model(input) | |
_, predicted = torch.max(output[:,-1,:], 1) | |
current_string.append(predicted.item()) | |
print(' '.join(seed_list)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ModelGRU(nn.Module): | |
def __init__(self): | |
super().__init__() | |
self.i_h = nn.Embedding(nv,nh) | |
self.rnn = nn.GRU(nh, nh, 2, batch_first=True) | |
self.h_o = nn.Linear(nh,nv) | |
self.bn1 = nn.BatchNorm1d(num_features=nh) | |
def forward(self, x): | |
self.h = torch.zeros(2, x.shape[0], nh).cuda() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ModelRNN(nn.Module): | |
def __init__(self): | |
super().__init__() | |
self.i_h = nn.Embedding(nv,nh) | |
self.rnn = nn.RNN(nh,nh, batch_first=True) | |
self.h_o = nn.Linear(nh,nv) | |
self.bn = nn.BatchNorm1d(num_features=nh) | |
def forward(self, x): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Build the model and add to graphics card | |
model = ModelRNNBasic().cuda() | |
# Define Loss, Optimizer | |
lr=1e-3 | |
opt = torch.optim.Adam(model.parameters(), lr=lr) | |
def loss_func(input,target): | |
return F.cross_entropy(input.permute(0,2,1), target) | |
losses = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nv = len(vocab) | |
nh = 64 | |
class ModelRNNBasic(nn.Module): | |
def __init__(self): | |
super().__init__() | |
self.i_h = nn.Embedding(nv,nh) | |
self.h_h = nn.Linear(nh,nh) | |
self.h_o = nn.Linear(nh,nv) | |
self.bn = nn.BatchNorm1d(nh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataLM(): | |
def __init__(self, train_data, index=0,bptt=10, bs=64): | |
self.train_data = train_data | |
self.index = index | |
self.bptt = bptt | |
self.bs = bs | |
def __iter__(self): | |
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_path = os.path.join('./train.txt') | |
valid_path = os.path.join('./valid.txt') | |
train_txt = ' , '.join(o.strip() for o in open(train_path).readlines()) | |
valid_txt = ' , '.join(o.strip() for o in open(valid_path).readlines()) | |
train_list = train_txt.split(' ') | |
valid_list = valid_txt.split(' ') | |
train_set = set(train_txt.split(' ')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import pandas as pd | |
from bs4 import BeautifulSoup | |
import time | |
import json | |
import datetime | |
from pymongo import MongoClient | |
import pymongo | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.6 | |
COPY requirements.txt ./ | |
RUN pip install --no-cache-dir -r requirements.txt | |
COPY . . | |
ENTRYPOINT [ "python", "-u", "main.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cloud-config | |
runcmd: | |
- ufw allow 22/tcp | |
- ufw allow 2376/tcp | |
- ufw allow 2377/tcp | |
- ufw allow 7946/tcp | |
- ufw allow 7946/udp | |
- ufw allow 4789/udp | |
- ufw reload | |
- systemctl restart docker |
NewerOlder