In [1]:
import tensorflow as tf
sess = tf.InteractiveSession()
In [2]:
filename_queue = tf.train.string_input_producer(["sample.csv"], num_epochs=1)
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
# Default values, in case of empty columns. Also specifies the type of the
# decoded result.
win_len = 3
seq_len = (win_len * 2) + 1
num_feats = 1
num_cols = seq_len + (seq_len * num_feats) + 1 # num tokens plus num feats per token plus label
record_defaults = [['<UNK>']] * num_cols
line = tf.decode_csv( value, record_defaults=record_defaults)
tokens = tf.stack(line[:seq_len])
features = tf.expand_dims(tf.stack(line[seq_len:-1]), 1)
label = line[-1]
batch_size = 4
min_after_dequeue = batch_size * 2
capacity = min_after_dequeue + 3 * batch_size
word_batch, feature_batch, label_batch = tf.train.shuffle_batch(
[tokens, features, label], batch_size=batch_size, capacity=capacity,
min_after_dequeue=min_after_dequeue)
# Start populating the filename queue.
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord, sess=sess)
try:
while not coord.should_stop():
# Retrieve a single instance:
t , f, l = sess.run([word_batch,feature_batch, label_batch])
print t
print f
print l
except tf.errors.OutOfRangeError:
print('Done training -- epoch limit reached')
finally:
# When done, ask the threads to stop.
coord.request_stop()
# Wait for threads to finish.
coord.join(threads)
sess.close()
[['finished' 'at' 'its' 'intraday' 'highs' '.' '<PAD>']
['w_-3' 'w_-2' 'w_-1' 'w_0' 'w_1' 'w_2' 'w_3']
['its' 'intraday' 'highs' '.' '<PAD>' '<PAD>' '<PAD>']
['dollar' 'finished' 'at' 'its' 'intraday' 'highs' '.']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']]
[['cap_-3']
['cap_-2']
['cap_-1']
['cap_0']
['cap_1']
['cap_2']
['cap_3']]
[['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']
['<PAD>']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']]]
['JJ' 'label' '.' 'PRP$']
[['<PAD>' '<PAD>' '<PAD>' 'the' 'dollar' 'finished' 'at']
['<PAD>' '<PAD>' 'and' 'while' 'the' 'defense' 'secretary']
['<PAD>' '<PAD>' 'the' 'dollar' 'finished' 'at' 'its']
['the' 'defense' 'secretary' 'is' 'speaking' 'out' ',']]
[[['<PAD>']
['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']]
[['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']]]
['DT' 'IN' 'NN' 'VBZ']
[['<PAD>' '<PAD>' '<PAD>' 'and' 'while' 'the' 'defense']
['and' 'while' 'the' 'defense' 'secretary' 'is' 'speaking']
['while' 'the' 'defense' 'secretary' 'is' 'speaking' 'out']
['<PAD>' 'the' 'dollar' 'finished' 'at' 'its' 'intraday']]
[[['<PAD>']
['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']]
[['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]]
['CC' 'NN' 'NN' 'VBD']
[['<PAD>' 'and' 'while' 'the' 'defense' 'secretary' 'is']
['president' 'bush' 'himself' 'has' "n't" 'launched' 'any']
['out' ',' 'president' 'bush' 'himself' 'has' "n't"]
['is' 'speaking' 'out' ',' 'president' 'bush' 'himself']]
[[['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['TITLE']
['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['PUNCT']
['TITLE']
['TITLE']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['TITLE']
['TITLE']
['LOWER']]]
['DT' 'VBZ' 'NNP' ',']
[['has' "n't" 'launched' 'any' 'high-visibility' 'campaign' 'to']
['at' 'its' 'intraday' 'highs' '.' '<PAD>' '<PAD>']
['speaking' 'out' ',' 'president' 'bush' 'himself' 'has']
['secretary' 'is' 'speaking' 'out' ',' 'president' 'bush']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']]
[['LOWER']
['LOWER']
['PUNCT']
['TITLE']
['TITLE']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['TITLE']
['TITLE']]]
['DT' 'NNS' 'NNP' 'IN']
[['any' 'high-visibility' 'campaign' 'to' 'drum' 'up' 'support']
['himself' 'has' "n't" 'launched' 'any' 'high-visibility' 'campaign']
['defense' 'secretary' 'is' 'speaking' 'out' ',' 'president']
['campaign' 'to' 'drum' 'up' 'support' ',' 'as']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['TITLE']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['LOWER']]]
['TO' 'VBN' 'VBG' 'IN']
[['support' ',' 'as' 'president' 'reagan' 'did' '.']
['to' 'drum' 'up' 'support' ',' 'as' 'president']
['launched' 'any' 'high-visibility' 'campaign' 'to' 'drum' 'up']
['drum' 'up' 'support' ',' 'as' 'president' 'reagan']]
[[['LOWER']
['PUNCT']
['LOWER']
['TITLE']
['TITLE']
['LOWER']
['PUNCT']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['LOWER']
['TITLE']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['LOWER']
['TITLE']
['TITLE']]]
['NNP' 'NN' 'NN' ',']
[['the' 'dollar' 'finished' 'at' 'its' 'intraday' 'highs']
['bush' 'himself' 'has' "n't" 'launched' 'any' 'high-visibility']
['<PAD>' '<PAD>' '<PAD>' 'along' 'the' 'way' ',']
['<PAD>' 'along' 'the' 'way' ',' 'investors' 'dumped']]
[[['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['<PAD>']
['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['PUNCT']]
[['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['PUNCT']
['LOWER']
['LOWER']]]
['IN' 'RB' 'IN' 'NN']
[['up' 'support' ',' 'as' 'president' 'reagan' 'did']
['high-visibility' 'campaign' 'to' 'drum' 'up' 'support' ',']
[',' 'as' 'president' 'reagan' 'did' '.' '<PAD>']
["n't" 'launched' 'any' 'high-visibility' 'campaign' 'to' 'drum']]
[[['LOWER']
['LOWER']
['PUNCT']
['LOWER']
['TITLE']
['TITLE']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']]
[['PUNCT']
['LOWER']
['TITLE']
['TITLE']
['LOWER']
['PUNCT']
['<PAD>']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]]
['IN' 'VB' 'NNP' 'JJ']
[['as' 'president' 'reagan' 'did' '.' '<PAD>' '<PAD>']
['investors' 'dumped' 'takeover' 'stocks' 'and' 'shares' 'of']
[',' 'president' 'bush' 'himself' 'has' "n't" 'launched']
['president' 'reagan' 'did' '.' '<PAD>' '<PAD>' '<PAD>']]
[[['LOWER']
['TITLE']
['TITLE']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['PUNCT']
['TITLE']
['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['TITLE']
['TITLE']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']
['<PAD>']]]
['VBD' 'NNS' 'PRP' '.']
[['way' ',' 'investors' 'dumped' 'takeover' 'stocks' 'and']
['dumped' 'takeover' 'stocks' 'and' 'shares' 'of' 'banks']
['takeover' 'stocks' 'and' 'shares' 'of' 'banks' 'that']
['<PAD>' '<PAD>' 'along' 'the' 'way' ',' 'investors']]
[[['LOWER']
['PUNCT']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['PUNCT']
['LOWER']]]
['VBD' 'CC' 'NNS' 'DT']
[['banks' 'that' 'have' 'leveraged-buy-out' 'debt' 'and' 'risky']
['stocks' 'and' 'shares' 'of' 'banks' 'that' 'have']
['have' 'leveraged-buy-out' 'debt' 'and' 'risky' 'real' 'estate']
['shares' 'of' 'banks' 'that' 'have' 'leveraged-buy-out' 'debt']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]]
['JJ' 'IN' 'CC' 'WDT']
[['leveraged-buy-out' 'debt' 'and' 'risky' 'real' 'estate' 'loans']
['real' 'estate' 'loans' 'on' 'their' 'books' '.']
[',' 'investors' 'dumped' 'takeover' 'stocks' 'and' 'shares']
['and' 'risky' 'real' 'estate' 'loans' 'on' 'their']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']]
[['PUNCT']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]]
['JJ' 'IN' 'NN' 'NN']
[['debt' 'and' 'risky' 'real' 'estate' 'loans' 'on']
['loans' 'on' 'their' 'books' '.' '<PAD>' '<PAD>']
['risky' 'real' 'estate' 'loans' 'on' 'their' 'books']
['on' 'their' 'books' '.' '<PAD>' '<PAD>' '<PAD>']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']
['<PAD>']]]
['JJ' 'NNS' 'NNS' '.']
[['that' 'have' 'leveraged-buy-out' 'debt' 'and' 'risky' 'real']
['the' 'way' ',' 'investors' 'dumped' 'takeover' 'stocks']
['millions' 'of' 'refugees' 'would' 'rush' 'home' '.']
['refugees' 'would' 'rush' 'home' '.' '<PAD>' '<PAD>']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['PUNCT']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']]]
['NN' 'NNS' 'MD' 'NN']
[['along' 'the' 'way' ',' 'investors' 'dumped' 'takeover']
['<PAD>' 'millions' 'of' 'refugees' 'would' 'rush' 'home']
['<PAD>' '<PAD>' 'millions' 'of' 'refugees' 'would' 'rush']
['<PAD>' '<PAD>' 'by' 'one' 'estimate' ',' 'everyone']]
[[['TITLE']
['LOWER']
['LOWER']
['PUNCT']
['LOWER']
['LOWER']
['LOWER']]
[['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['PUNCT']
['LOWER']]]
[',' 'NNS' 'IN' 'CD']
[['<PAD>' 'by' 'one' 'estimate' ',' 'everyone' 'here']
['estimate' ',' 'everyone' 'here' 'under' '50' 'owns']
['and' 'shares' 'of' 'banks' 'that' 'have' 'leveraged-buy-out']
[',' 'everyone' 'here' 'under' '50' 'owns' 'at']]
[[['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['PUNCT']
['LOWER']
['LOWER']]
[['LOWER']
['PUNCT']
['LOWER']
['LOWER']
['LOWER']
['DIGIT']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['PUNCT']
['LOWER']
['LOWER']
['LOWER']
['DIGIT']
['LOWER']
['LOWER']]]
['NN' 'RB' 'NNS' 'IN']
[['everyone' 'here' 'under' '50' 'owns' 'at' 'least']
['of' 'banks' 'that' 'have' 'leveraged-buy-out' 'debt' 'and']
['under' '50' 'owns' 'at' 'least' 'one' 'bike']
['one' 'estimate' ',' 'everyone' 'here' 'under' '50']]
[[['LOWER']
['LOWER']
['LOWER']
['DIGIT']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['DIGIT']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['PUNCT']
['LOWER']
['LOWER']
['LOWER']
['DIGIT']]]
['CD' 'VBP' 'IN' 'NN']
[['by' 'one' 'estimate' ',' 'everyone' 'here' 'under']
['estate' 'loans' 'on' 'their' 'books' '.' '<PAD>']
['<PAD>' '<PAD>' '<PAD>' 'millions' 'of' 'refugees' 'would']
['at' 'least' 'one' 'bike' '.' '<PAD>' '<PAD>']]
[[['TITLE']
['LOWER']
['LOWER']
['PUNCT']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']]
[['<PAD>']
['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']]]
[',' 'PRP$' 'NNS' 'NN']
[['of' 'refugees' 'would' 'rush' 'home' '.' '<PAD>']
['here' 'under' '50' 'owns' 'at' 'least' 'one']
['owns' 'at' 'least' 'one' 'bike' '.' '<PAD>']
['<PAD>' 'the' 'campaign' 'so' 'divided' 'union' 'leaders']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']]
[['LOWER']
['LOWER']
['DIGIT']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']]
[['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]]
['VB' 'VBZ' 'CD' 'RB']
[['divided' 'union' 'leaders' 'that' 'the' 'government' 'found']
['the' 'campaign' 'so' 'divided' 'union' 'leaders' 'that']
['<PAD>' '<PAD>' 'the' 'campaign' 'so' 'divided' 'union']
['so' 'divided' 'union' 'leaders' 'that' 'the' 'government']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]]
['IN' 'VBD' 'NN' 'NNS']
[['union' 'leaders' 'that' 'the' 'government' 'found' 'them']
['least' 'one' 'bike' '.' '<PAD>' '<PAD>' '<PAD>']
['government' 'found' 'them' 'far' 'easier' 'to' 'control']
['campaign' 'so' 'divided' 'union' 'leaders' 'that' 'the']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']
['<PAD>']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]]
['DT' '.' 'RB' 'NN']
[['easier' 'to' 'control' '.' '<PAD>' '<PAD>' '<PAD>']
['would' 'rush' 'home' '.' '<PAD>' '<PAD>' '<PAD>']
['the' 'government' 'found' 'them' 'far' 'easier' 'to']
['leaders' 'that' 'the' 'government' 'found' 'them' 'far']]
[[['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']
['<PAD>']]
[['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']
['<PAD>']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]]
['.' '.' 'PRP' 'NN']
[['that' 'the' 'government' 'found' 'them' 'far' 'easier']
['found' 'them' 'far' 'easier' 'to' 'control' '.']
['<PAD>' '<PAD>' '<PAD>' 'the' 'campaign' 'so' 'divided']
['50' 'owns' 'at' 'least' 'one' 'bike' '.']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']]
[['<PAD>']
['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['LOWER']]
[['DIGIT']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']]]
['VBD' 'JJR' 'DT' 'JJS']
[['them' 'far' 'easier' 'to' 'control' '.' '<PAD>']
['<PAD>' '<PAD>' '<PAD>' 'compaq' 'computer' 'gained' '2']
['far' 'easier' 'to' 'control' '.' '<PAD>' '<PAD>']
['<PAD>' '<PAD>' '<PAD>' 'by' 'one' 'estimate' ',']]
[[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']]
[['<PAD>']
['<PAD>']
['<PAD>']
['TITLE']
['TITLE']
['LOWER']
['DIGIT']]
[['LOWER']
['LOWER']
['LOWER']
['LOWER']
['PUNCT']
['<PAD>']
['<PAD>']]
[['<PAD>']
['<PAD>']
['<PAD>']
['TITLE']
['LOWER']
['LOWER']
['PUNCT']]]
['TO' 'NNP' 'VB' 'IN']
Done training -- epoch limit reached
In [ ]:
Content source: nrlewis/nlpfromscratch-tf
Similar notebooks: