Search code examples
pythonpython-3.xtensorflowludwig

Uber Ludwig: Issue Making Predictions


I decided to mess with Uber Ludwig again. I wanted to make a simple demo using the python API that learns to add 1 to the input number. I have successfully produced a model, but the issue arises when predicting. I am running on the newest release from github on PopOS 19.10 on CPU TensorFlow. Thank you for any help.

Edit: I have reproduced the issue on windows as well.

The error is as follows

Traceback (most recent call last):
  File "predict.py", line 3, in <module>
    x = model.predict({"numberIn":[1]}, return_type='dict')
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/api.py", line 914, in predict
    gpu_fraction=gpu_fraction,
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/api.py", line 772, in _predict
    self.model_definition['preprocessing']
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/data/preprocessing.py", line 159, in build_data
    preprocessing_parameters
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/data/preprocessing.py", line 180, in handle_missing_values
    dataset_df[feature['name']] = dataset_df[feature['name']].fillna(
AttributeError: 'list' object has no attribute 'fillna'

Here is my prediction script

from ludwig.api import LudwigModel
model = LudwigModel.load("/home/user/Documents/ludwig-test/plus1/results/api_experiment_run_0/model")
x = model.predict({"numberIn":[1]}, return_type='dict')
#x = model.predict({"numberIn":[1]}, return_type=<class 'dict'>) I tried this with no success
print(x)

Here is the contents of my training script.

mydata = {"numberIn":[], "value":[]}

for x in range(10000):
    mydata["numberIn"].append(x)
    mydata["value"].append(x + 1)

from ludwig.api import LudwigModel
print("Imported Ludwig")
modelobject = LudwigModel(model_definition_file="modeldef.yaml")
stats = modelobject.train(data_dict=mydata)
modelobject.close()

modeldef.yaml

input_features:
    -
        name: numberIn
        type: numerical

output_features:
    -
        name: value
        type: numerical

Solution

  • Solution: Input argument of predict function is not positional and data_dict needs to be specified in this case. x = modelobject.predict(data_dict=mydictionary)