hi team, how can I define the dictionary in the pa...
# questions
k
hi team, how can I define the dictionary in the parameters.yml? classes: - name: '98' weight: 1.0 - name: '900' weight: 4.0 - name: '1001' weight: 4.0 - name: '1200' weight: 1.0 - name: '1300' weight: 4.0 when I define like this, it seem like it is a list instead of dictionary when I call in params['classes']
h
Someone will reply to you shortly. In the meantime, this might help:
j
hi @Kai Lok! how does your
node(...)
look like in
pipeline.py
?
if you're passing
params:classes
, then you're receiving the contents of
classes
, hence a list
k
def load_class_weights(params: Dict[str, Any]) -> Dict[str, float]: classes = params['classes'] class_weights = {cls['name']: cls['weight'] for cls in classes} return class_weights
was thinking to use two list and combine them as dict instead
j
that's your node function, indeed
k
params.yml can oni be list ya?
j
how are you declaring the pipeline?
Copy code
return pipeline(
  node(
    func=load_class_weights,
    inputs=[...]  # <-----?
k
from kedro.pipeline import Pipeline, pipeline, node from .nodes import load_class_weights def create_pipeline(**kwargs) -> Pipeline: return pipeline([ node( func=load_class_weights, inputs="params:classes", outputs=None, name="load_class_weights_node" ), ])
j
exactly. so, that's like doing
Copy code
>>> load_class_weights(params=parameters["classes])
therefore you're receiving a list, you don't need
classes = params["classes"]
inside your function. does that make sense?
k
means I'm doing redundant work here by receiving a dict then convert back to dict? how can I check whether I'm defining it correctly or not before I send it back to the main function?
y
@Kai Lok
params.yml can oni be list ya?
It’s a
dict[str, Any]
. Meaning that top level keys are strings, and then values can be literals, lists, other dicts, etc.
k
thank you guys, I change it to received list instead. easier. 🙂