Skip to content

Feature/pre train subreddit#15

Merged
hsson merged 28 commits intodevfrom
feature/pre-train-subreddit
Apr 5, 2017
Merged

Feature/pre train subreddit#15
hsson merged 28 commits intodevfrom
feature/pre-train-subreddit

Conversation

@Jaxing
Copy link
Copy Markdown
Contributor

@Jaxing Jaxing commented Apr 5, 2017

This enables to pre-train the network on different output labels for the same input data. Specifically to use subreddits as lables for pre-training.
In main.py the a new layer is added after adding secondary output layer, this is so that the network can generelise from the learnt prameters and when tested showed better preformance. Where in the network the secondary output should be placed should be treated as a hyperparameter.

Comment thread model/model.py
print("Starting training...")

if self.use_pretrained:
if self.use_pretrained and \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement can be simplified to:

if self.use_pretrained and (self.use_pretrained_net == use_pretrained_net)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what does this actually mean? This pull request doesn't change behavior of the embedding matrix right? So why is it required that self.use_pretrained_net == use_pretrained_net ? And why are there two separate variables for use_pretrained_net?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only want to initialise the embedding matrix once but we run train twice therefore we want to run it only if both self.use_pretrained_net and use_pretrained_net is true i.e. we want to pre-train on subreddits and this call to train will pre-train or if both of them are false i.e. we don't want to pre-train and this call don't do pre-train.
That's just bad naming, the class variable is whether the model should use pre-training on the network and the parameter is whether this call to the method should pre-train the network

Comment thread config.template.yaml Outdated
validation_data: 'validation_data_top_n_single.csv'
training_data: 'training_data_top_n_single.csv'
testing_data: 'testing_data_top_n_single.csv'
pre_train_data: 'pre-train_data_top_n.csv'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Comment thread main.py Outdated
builder = ModelBuilder(config_file, sess)
builder.add_input_layer()

# Add a number of hidden layers
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this done in main.py? Shouldn't it be done in the build function of the model builder?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more modular, if someone want to set up the network in another way than how it is done in the build method then there is no way of building the model

Comment thread main.py
.add_precision_operations()

network_model = builder.build()
if config_file[USE_PRETRAINED_NET]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be moved to the model itself? To the beginning of the train function maybe? Just tryting to keep the main.py file as clean as possible 😄

Comment thread model/model.py
self._session.run(self.embedding_init,
feed_dict={self.embedding_placeholder:
self.data.embedding_matrix})
self.train_writer = \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the writers moved to the model builder?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps not necessary but otherwise the writer initiated twice, once for each time we train.

Comment thread model/model_builder.py Outdated

return self

def add_secondary_output(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very similar to the other output function. Is it possible to combine them and maybe take the labels as an input or something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be, one problem is that we don't want to overwrite the training op for either could maybe be dealt with using a boolean

Comment thread model/util/csv_reader.py Outdated
TRAINING = "training_data"
VALIDATION = "validation_data"

PRE_TRAINING = "pre_training_data"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Comment thread model/model.py
self.constant_prediction_limit = config[CONSTANT_PREDICTION_LIMIT]
self.use_concat_input = config[USE_CONCAT_INPUT]
self.use_pretrained_net = config[USE_PRETRAINED_NET]
self.subreddit_count = 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this variable used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@hsson
Copy link
Copy Markdown
Contributor

hsson commented Apr 5, 2017

Also, I just realised that the concatenated subreddit input is still used when pre-training on subreddits. Maybe this should not be concatenated when doing that? Seems a bit biased. At the same time... The dimensions of the weights depend the size of the input.

@hsson
Copy link
Copy Markdown
Contributor

hsson commented Apr 5, 2017

  • Use softmax for subreddit predictions.
  • Output layers should be last

@hsson
Copy link
Copy Markdown
Contributor

hsson commented Apr 5, 2017

Feedback from meeting has been implemented and tested.

@hsson hsson merged commit 8158619 into dev Apr 5, 2017
@hsson hsson deleted the feature/pre-train-subreddit branch April 5, 2017 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants