forked from czyssrs/Few-Shot-NLG
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,016 additions
and
322 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# @Time : 17-4-27 下午8:36 | ||
# @Author : Tianyu Liu | ||
|
||
import tensorflow as tf | ||
import pickle | ||
|
||
|
||
class OutputUnit_gpt(object): | ||
def __init__(self, input_size, output_size, project_init, scope_name): | ||
self.input_size = input_size | ||
self.output_size = output_size | ||
self.scope_name = scope_name | ||
self.params = {} | ||
|
||
with tf.variable_scope(scope_name): | ||
# self.W = tf.get_variable('W', [input_size, output_size]) | ||
# self.b = tf.get_variable('b', [output_size], initializer=tf.zeros_initializer(), dtype=tf.float32) | ||
|
||
### use gpt word embedding init | ||
self.W = tf.get_variable('W', initializer=project_init) | ||
|
||
# self.params.update({'W': self.W, 'b': self.b}) | ||
self.params.update({'W': self.W}) | ||
|
||
def __call__(self, x, finished = None): | ||
# out = tf.nn.xw_plus_b(x, self.W, self.b) | ||
|
||
### use gpt word embedding init | ||
out = tf.matmul(x, self.W) | ||
|
||
if finished is not None: | ||
out = tf.where(finished, tf.zeros_like(out), out) | ||
#out = tf.multiply(1 - finished, out) | ||
return out | ||
|
||
def save(self, path): | ||
param_values = {} | ||
for param in self.params: | ||
param_values[param] = self.params[param].eval() | ||
with open(path, 'wb') as f: | ||
pickle.dump(param_values, f, True) | ||
|
||
def load(self, path): | ||
param_values = pickle.load(open(path, 'rb')) | ||
for param in param_values: | ||
self.params[param].load(param_values[param]) |
Oops, something went wrong.