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
func (v *Value) add(v1 *Value) *Value { | |
nv := newValue(v.data+v1.data, nil /* incorrect, should be []*Value{v, v1} */) | |
nv.backward = func() { | |
v.grad = /* incorrect, should be += */ nv.grad | |
v1.grad = /* incorrect, should be += */ nv.grad | |
} | |
return nv | |
} | |
func (v *Value) mul(v1 *Value) *Value { |
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
package main | |
import "fmt" | |
type Value struct { | |
data, grad float64 | |
backward func() | |
children []*Value | |
} |
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
package main | |
import "fmt" | |
func sum(a, b int) int { | |
return a + b | |
} | |
func main() { | |
fmt.Printf("%d\n", sum(1, 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
class Nl2SqlTranslator(tf.keras.Model): | |
def __init__(self, nl_text_processor, sql_text_processor, fixed_embedding, unit=128): | |
super().__init__() | |
# Natural language | |
self.nl_text_processor = nl_text_processor | |
self.nl_voba_size = len(nl_text_processor.get_vocabulary()) | |
self.nl_embedding = tf.keras.layers.Embedding( | |
self.nl_voba_size, | |
output_dim=unit, | |
mask_zero=True) |
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 names | |
def populate(in_filename, out_filename): | |
out = [] | |
with open(in_filename) as f: | |
for l in f.readlines(): | |
parts = l.split('|||') | |
nli_template = parts[0].strip().split() | |
nli = [] | |
target = [] |
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
# wget http://nlp.stanford.edu/data/glove.6B.zip | |
# unzip glove.6B.zip | |
import numpy as np | |
import tensorflow as tf | |
embeddings_index = {} | |
with open('glove.6B.100d.txt') as f: | |
for line in f: | |
word, coefs = line.split(maxsplit=1) |
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
def standardize(text): | |
# Split accecented characters. | |
text = tf_text.normalize_utf8(text, 'NFKD') | |
text = tf.strings.lower(text) | |
# Keep space, a to z, and select punctuation. | |
text = tf.strings.regex_replace(text, '[^ a-z.?!,¿]', '') | |
# Add spaces around punctuation. | |
text = tf.strings.regex_replace(text, '[.?!,¿]', r' \0 ') | |
# Strip whitespace. | |
text = tf.strings.strip(text) |
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 tensorflow as tf | |
def split(text): | |
parts = tf.strings.split(text, sep='\t') | |
return parts[0], parts[1] | |
dataset = tf.data.TextLineDataset(['spa.txt']).map(split) | |
eng_dataset = dataset.map(lambda eng, spa : eng) | |
spa_dataset = dataset.map(lambda eng, spa : spa) |
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
class Spa2EngTranslator(tf.keras.Model): | |
def __init__(self, eng_text_processor, spa_text_processor, unit=512): | |
pass | |
def call(self, eng_text, spa_text): | |
pass |
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
class Spa2EngTranslator(tf.keras.Model): | |
def __init__(self, eng_text_processor, spa_text_processor, unit=512): | |
super().__init__() | |
# Spanish | |
self.spa_text_processor = spa_text_processor | |
self.spa_voba_size = len(spa_text_processor.get_vocabulary()) | |
self.spa_embedding = tf.keras.layers.Embedding( | |
self.spa_voba_size, | |
output_dim=unit, | |
mask_zero=True) |
NewerOlder