This file contains hidden or 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
""" Some description. | |
""" | |
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
import sys | |
import json | |
import tqdm |
This file contains hidden or 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
# -- set up repos | |
brew install Caskroom/cask/xquartz | |
# -- install xpdf | |
brew install xpdf | |
# -- download japanese package | |
wget ftp://ftp.foolabs.com/pub/xpdf/xpdf-japanese.tar.gz | |
# -- open |
This file contains hidden or 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 numpy as np | |
import tensorflow as tf | |
_major_version, _minor_version, _ = map(int, tf.__version__.split('-')[0].split('.')) | |
assert _major_version >= 1 and _minor_version >= 2, "requires TensorFlow 1.2.0 and above" | |
text_data_path = "./z_sentences.txt" | |
MAX_SEQUENCE_LENGTH = 10 |
This file contains hidden or 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
"""Example TensorFlow code for Self-Attention mechanism. | |
Refs: | |
Attention Is All You Need | |
Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, Illia Polosukhin | |
https://arxiv.org/abs/1706.03762 | |
Transformer: A Novel Neural Network Architecture for Language Understanding | |
https://research.googleblog.com/2017/08/transformer-novel-neural-network.html |
This file contains hidden or 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
# yo |
This file contains hidden or 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 numpy as np | |
import heapq | |
VOCAB_SIZE = 1000 | |
HIDDEN_DIM = 128 | |
vocab = { | |
'the': 5, | |
'fox': 35, | |
'jumped': 144, |
This file contains hidden or 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 copy import deepcopy | |
class Line: | |
def __init__(self, length: int, x: int): | |
self.length = length | |
self.x = x | |
def __len__(self): | |
return self.length |
This file contains hidden or 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 click | |
import torch | |
import torch.autograd | |
import torch.nn.functional as F | |
from torch.autograd import Variable | |
import os | |
import random | |
import math |
This file contains hidden or 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 random | |
def process_line(line): | |
columns = line.split('\t') | |
if len(columns) < 6: | |
return None | |
n_corrections = columns[0] | |
serial_number = columns[1] | |
url = columns[2] |
This file contains hidden or 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 torch, torch.nn as nn | |
from torch.autograd import Variable | |
text = ['BOS', 'How', 'are', 'you', 'EOS'] | |
seq_len = len(text) | |
batch_size = 1 | |
embedding_size = 1 | |
hidden_size = 1 | |
output_size = 1 |