mlp2018 / BagofWords

0 stars 0 forks source link

Classify using a neural network #10

Closed johannadevos closed 6 years ago

johannadevos commented 6 years ago

I'm going to start doing this tutorial: https://machinelearningmastery.com/tutorial-first-neural-network-python-keras/

If I get that working, hopefully I can use the same code for our binary classification task.

johannadevos commented 6 years ago

This is useful too: https://www.tensorflow.org/get_started/premade_estimators

johannadevos commented 6 years ago

I got the neural network working in a rudimentary version, where it trains on 100 reviews, using two layers with 10 hidden nodes each (otherwise it wasn't feasible on my laptop). The code is extremely unpolished still (in the branch johanna_NN, part1.py), but it runs through.

It is not obvious to me how I should integrate this code in bagofwords.py. In the optimization_run function we use things such as classifier.fit and classifier.predict, but the fit and predict methods belong to the RandomForestClassifier class, and not to the DNNClassifier class, which for example works as:

classifier2.train(
    input_fn=lambda:train_input_fn(train_df, train_data['sentiment'], 100), # batch size 100
    steps=1000)

eval_result = classifier2.evaluate(
    input_fn=lambda:eval_input_fn(test_df, test_data['sentiment'], 100))

What would be the best way to go forward and integrate this code?

johannadevos commented 6 years ago

Nastaran's tips: