Function signature for python dictionary


#1

A c3 type has a member function that is implemented in python which outputs a python dictionary.
How should I specify the function signature in MyType.c3typ file?

image

Does this look right? I specify the output to be json js server?


#2

Ideally, you should specify the types of the keys in the output. e.g.

testEvaluate: member function(input: !Tensor, targetOutput: !Tensor): !map<string, anyof(int, double)> js server

Even MORE ideally you would define a type representing the output of your function use that as the return type.


#3

yes, if you know the keys you should define a type for it.


#4

Thanks!
But do you mean the output is persisted in a key-value storage? What if I do not want to save it, I just want to look at the results?


#5

Check out this example:
/**
Generic risk analytic processor. Parameterized by model and input type.
/
type RiskAnalyticProcessor<M, I> mixes Analytic<I, Void> {
/**
Helper function to generate predictions given a {@link Dataset} and a {@link RiskModel}.
@param source
Source for which we want to make a prediction
@param model
{@link RiskModel} used to make a prediction
@param dataset
{@link Dataset} used to make a prediction
@returns {@link RiskAnalyticProcessorPredictionResult} containing the prediction
*/
makePrediction: function (source: !Obj,
model: !M,
currentConfiguration: !Dataset): RiskAnalyticProcessorPredictionResult js server

}

where the return type is defined here:

/**
Result of RiskAnalyticProcessor.makePrediction.
/
type RiskAnalyticProcessorPredictionResult {

/**
{@link MachineLearningPredictionDatasetInterpretable} output from the {@link RiskAnalyticProcessor}.
/
predictionDataset: MachineLearningPredictionDatasetInterpretable

/**
{@link PythonMachineLearningPipelineInterpretable} used to make the prediction.
/
pythonModel: anyof(PythonMachineLearningPipelineInterpretable)

/**
{@link Dataset} used to make to make the prediction.
/
inputDataset: Dataset
}

Note that this is not an entity type so it is not persisted


#6

@YuanLiu I don’t think Riley was referring to key-value stores like Cassandra. He just meant the key to the Mapp (or dict). i.e. map<string, integer> has a string key and integer value. So the function signature he proposed should probably work for your case, unless you have different Types for the key or value.