Skip to content

Commit d019f26

Browse files
authored
Merge pull request #756 from ufal/printing_dicts
Better printing of dictionaries and lists in print_examples
2 parents dd26a0f + c95a953 commit d019f26

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

neuralmonkey/learning_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,12 @@ def print_final_evaluation(name: str, eval_result: Evaluation) -> None:
560560

561561
def _data_item_to_str(item: Any) -> str:
562562
if isinstance(item, list):
563-
return " ".join([str(i) for i in item])
563+
return " ".join([_data_item_to_str(i) for i in item])
564564

565-
if isinstance(item, str):
566-
return item
565+
if isinstance(item, dict):
566+
return "{\n " + "\n ".join(
567+
["{}: {}".format(_data_item_to_str(key), _data_item_to_str(val))
568+
for key, val in item.items()]) + "\n }"
567569

568570
if isinstance(item, np.ndarray) and len(item.shape) > 1:
569571
return "[numpy tensor, shape {}]".format(item.shape)

0 commit comments

Comments
 (0)