Tensorflow Estimator API: how to pass parameter from input function

I am trying to add the weight of the class as a hyperparameter for my model, but to calculate the weight I need to read the input data, this happens inside input_fn, which is then passed to estimator.fit() . The output of input_fn is just functions, labels, which should have the same form num_examples * num_features. My questions is, is there a way to distribute data from an I / O card from model_fn to model_fn? Or as an alternative - maybe there is an input_fn wrapped for the data set that allows you to reprogram the minority / perplexity of the majority along with batch processing - in this case I do not need any parameter for distribution.

+5
source share
1 answer

Both functions and labels can be a dictionary of tensors (not just one tensor). Tensors can be any shape you want, although usually it is num_examples * ...

If you are not using any predefined estimates, the easiest way would be to add another function so that you need to calculate the weights, calculate the weights in the model, and then use them (multiply the losses or pass them as a parameter).

You also have access to the hyperparameters inside input_fn, so you can calculate the weight there and add it as a separate column.

If you are using a canned rating, check the documentation. I see that most of them support weight_column_name. In this case, just give it the name that you used in the function dictionary for the weight values.

Otherwise, if all else fails, you can try the data as you want before submitting it to the tensor.

+1
source

Source: https://habr.com/ru/post/1274855/


All Articles