<jupyter_start><jupyter_text>定义模型<jupyter_code>model = keras.models.Sequential([
    keras.layers.DenseFeatures(feature_columns),
    keras.layers.Dense(100, activation='relu'),
    keras.layers.Dense(100, activation='relu'),
    keras.layers.Dense(2, activation='softmax'),
])
model.compile(loss='sparse_categorical_crossentropy',
             optimizer = keras.optimizers.SGD(lr=0.01),
             metrics = ['accuracy'])
# 1. model.fit
# 2. model -> estimator -> train

train_dataset = make_dataset(train_df, y_train, epochs = 100)
eval_dataset = make_dataset(eval_df, y_eval, epochs = 1, shuffle = False)
history = model.fit(train_dataset,
                   validation_data = eval_dataset,
                   steps_per_epoch = 20,
                   validation_steps = 8,
                   epochs = 100)
estimator = keras.estimator.model_to_estimator(model)
# 1. function
# 2. returun a. (features, labels) b. dataset -> (feature, label)
estimator.train(input_fn = lambda: make_dataset(train_df, y_train, epochs=100))<jupyter_output>INFO:tensorflow:Using default config.
WARNING:tensorflow:Using temporary folder as model directory: /<KEY>
INFO:tensorflow:Using the Keras model provided.
WARNING:tensorflow:You are creating an Estimator from a Keras model manually subclassed from `Model`, that was already called on some inputs (and thus already had weights). We are currently unable to preserve the model's state (its weights) as part of the estimator in this case. Be warned that the estimator has been created using a freshly initialized version of your model.
Note that this doesn't affect the state of the model instance you passed as `keras_model` argument.
INFO:tensorflow:Using config: {'_model_dir': '/<KEY>', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': allow_soft_placement: true
graph_options {
  rewrite_options {
    me[...]
{'fraction_non_alphanumeric': 0.10325245224574084, 'fraction_numerical': 0.017036654620547237, 'mean_word_length': 4.428571428571429, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '292949', 'license': 'MIT', 'n_tokens_mistral': 620, 'n_tokens_neox': 580, 'n_words': 168, 'path': 'estimator/tf_keras_to_estimator.ipynb', 'repo_name': 'EvaGalois/Deep_Learning', 'size': '2045'}