keras-team / keras-docs-ja

Japanese translation of the Keras documentation.
https://keras.io/ja/
68 stars 67 forks source link

Fix sequential model guid #111

Closed funzin closed 6 years ago

funzin commented 6 years ago

I executed this code.

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD

# ダミーデータ生成
import numpy as np
x_train = np.random.random((1000, 20))
y_train = keras.utils.to_categorical(np.random.randint(10, size=(1000, 1)), num_classes=10)
x_test = np.random.random((100, 20))
y_test = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10)

model = Sequential()
# Dense(64) は,64個のhidden unitを持つ全結合層です.
# 最初のlayerでは,想定する入力データshapeを指定する必要があり,ここでは20次元としてます.
model.add(Dense(64, activation='relu', input_dim=20))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))

sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy',
              optimizer=sgd,
              metrics=['accuracy'])

model.fit(x_train, y_train,
          epochs=20,
          batch_size=128)
score = model.evaluate(x_test, y_test, batch_size=128)

but I got this error message and didn't execute. NameError: name 'keras' is not defined

I added import code in this pull request

nzw0301 commented 6 years ago

Thank you for your PR! You are right. This code does not work. However, I think that this Japanese doc needs to contain the same code block to the original page.

So, would you revert your modifications to the original, and then, would you insert import keras to the top of this code block?

funzin commented 6 years ago

@nzw0301 Thank you for your replay! Please check 9612e1a and 51c4c19:bow: