Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Modify sentiment analysis book chapter #539

Merged

Conversation

sidgoyal78
Copy link
Contributor

No description provided.

@sidgoyal78 sidgoyal78 changed the title Modify sentiment analysis book chapter [WIP] Modify sentiment analysis book chapter Jun 7, 2018
nickyfantasy
nickyfantasy previously approved these changes Jun 11, 2018
@nickyfantasy nickyfantasy changed the title [WIP] Modify sentiment analysis book chapter Modify sentiment analysis book chapter Jun 13, 2018
parameters=parameters,
update_equation=adam_optimizer)
```
Notice for loading and reading IMDB data, it could take up to 1 minute. Please be patient.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it always take 1 minute to load or just the first time?

Copy link
Contributor

Choose a reason for hiding this comment

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

it seems always

result = trainer.test(reader=test_reader, feeding=feeding)
print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics)
if isinstance(event, fluid.EndStepEvent):
print("Step {0}, Epoch {1} Metrics {2}".format(
Copy link
Contributor

Choose a reason for hiding this comment

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

This will print at every single step. It is too excessive. Can you change to every 100 steps or something like that?

Copy link
Contributor

Choose a reason for hiding this comment

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

since we only run 10 steps in jupyter, i think it is fine to print all 10 steps. In train.py, I make it print every 10 steps

print("Step {0}, Epoch {1} Metrics {2}".format(
event.step, event.epoch, map(np.array, event.metrics)))

if event.step == 10:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is basically saying we will only train 10 steps.
There is no need to call trainer.stop() since this is not a test.

Copy link
Contributor

@nickyfantasy nickyfantasy Jun 14, 2018

Choose a reason for hiding this comment

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

this model will run like for 200steps and couple minutes with 1 epoch, I want to stop it fast so that user can see inference result in jupyter notebook

Copy link
Contributor

Choose a reason for hiding this comment

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

In train.py, it will continue to run

Copy link
Contributor

Choose a reason for hiding this comment

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

How long does it take to run? If the training takes about 10 minutes or so, we can let the users know the time cost.

lod = [[3, 4, 2]]
base_shape = [1]
# The range of random integers is [low, high]
tensor_words = fluid.create_random_int_lodtensor(
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is using a random vector. We should use a real example instead. (if possible.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I just did it with 3 sentences 'read the book forget the movie', 'this is a great movie', 'this is very bad'

Copy link
Contributor

@daming-lu daming-lu left a comment

Choose a reason for hiding this comment

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

Tiny comments


CLASS_DIM = 2
EMB_DIM = 128
HID_DIM = 512
Copy link
Contributor

Choose a reason for hiding this comment

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

I really think we should use hidden and correct the English misspellings sometime. For example from paddle.v2.plot import Ploter

Copy link
Contributor

Choose a reason for hiding this comment

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

But it is not an urgent problem now.


The above stacked bidirectional LSTM network extracts high-level features and maps them to a vector of the same size as the categories. `paddle.activation.Softmax` function or classifier is then used for calculating the probability of the sentence belonging to each category.
Next we define a `inference_program` that simply uses `convolution_net` to predict output with the input from `fluid.layer.data`.
Copy link
Contributor

Choose a reason for hiding this comment

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

an inference_program

Copy link
Contributor

Choose a reason for hiding this comment

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

good grammar catch

cost = fluid.layers.cross_entropy(input=prediction, label=label)
avg_cost = fluid.layers.mean(cost)
accuracy = fluid.layers.accuracy(input=prediction, label=label)
return [avg_cost, accuracy]
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we should emphasize that the 1st returned parameter must be cost

Copy link
Contributor

Choose a reason for hiding this comment

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

true

parameters=parameters,
update_equation=adam_optimizer)
```
Notice for loading and reading IMDB data, it could take up to 1 minute. Please be patient.
Copy link
Contributor

Choose a reason for hiding this comment

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

Mr. Minaj is a true gentleman 👍

@sidgoyal78
Copy link
Contributor Author

Thanks @nickyfantasy for your efforts.

@daming-lu
Copy link
Contributor

LGTM

@nickyfantasy nickyfantasy merged commit 54ace20 into PaddlePaddle:high-level-api-branch Jun 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants