error in azure synapse notebook

uuu zhu 20 Reputation points
2024-04-29T19:27:28.13+00:00

synapse notebook, I tuned hyperparameter for neural network model, it gave the following error:

com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input at [Source: (String)""; line: 1, column: 0]

My codes are as follows:

# Create function
def nn_cl_fun(neurons, layers): 
    num_features = 20
    dropout_rate = 0.25
    
    nn = Sequential() 
    nn.add(Dense(neurons, input_shape=(num_features,), activation='relu')) 
    
    for i in range(layers): 
        nn.add(Dense(neurons, activation='relu'))
        nn.add(Dropout(dropout_rate, seed=123))         
    
    #output 
    nn.add(Dense(1, activation='sigmoid'))  
    opt = tf.keras.optimizers.Adam(learning_rate=0.01)
    nn.compile(loss='binary_crossentropy', optimizer=opt, metrics=[Recall(),Precision()]) 
    return nn 

nn = KerasClassifier(build_fn=nn_cl_fun,verbose=0) 
params={'batch_size':[64, 128], 
        'epochs':[30, 50],
        'neurons':[128,256],
        'layers':[1,2]        
        }

nn_model=GridSearchCV(estimator=nn, param_grid=params, cv=5, scoring='f1', return_train_score=True, verbose=0, n_jobs=-1)
es = EarlyStopping(monitor='loss', mode='min', verbose=0, patience=5)
results = nn_model.fit(X_train_sm, y_train_sm, callbacks=[es], verbose=0)
# print best hyperparameters
print("Best F1 score: ", nn_model.best_score_)
print("Best hyperparameters: ", nn_model.best_params_)
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,441 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Smaran Thoomu 10,405 Reputation points Microsoft Vendor
    2024-04-30T15:28:51.8966667+00:00

    Hi @uuu zhu

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer .

    Issue: synapse notebook, I tuned hyperparameter for neural network model, it gave the following error:

    com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input at [Source: (String)""; line: 1, column: 0]

    PythonAI ConvertCopy

    My codes are as follows:
    
    # Create function
    def nn_cl_fun(neurons, layers): 
        num_features = 20
        dropout_rate = 0.25
        
        nn = Sequential() 
        nn.add(Dense(neurons, input_shape=(num_features,), activation='relu')) 
        
        for i in range(layers): 
            nn.add(Dense(neurons, activation='relu'))
            nn.add(Dropout(dropout_rate, seed=123))         
        
        #output 
        nn.add(Dense(1, activation='sigmoid'))  
        opt = tf.keras.optimizers.Adam(learning_rate=0.01)
        nn.compile(loss='binary_crossentropy', optimizer=opt, metrics=[Recall(),Precision()]) 
        return nn 
    
    nn = KerasClassifier(build_fn=nn_cl_fun,verbose=0) 
    params={'batch_size':[64, 128], 
            'epochs':[30, 50],
            'neurons':[128,256],
            'layers':[1,2]        
            }
    
    nn_model=GridSearchCV(estimator=nn, param_grid=params, cv=5, scoring='f1', return_train_score=True, verbose=0, n_jobs=-1)
    es = EarlyStopping(monitor='loss', mode='min', verbose=0, patience=5)
    results = nn_model.fit(X_train_sm, y_train_sm, callbacks=[es], verbose=0)
    # print best hyperparameters
    print("Best F1 score: ", nn_model.best_score_)
    print("Best hyperparameters: ", nn_model.best_params_)
    
    
    

    Solution: I found the issue: there are some null values in 'label' columns. Thanks a lot.

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.

    I hope this helps!

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.


    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments