Skip to content

Commit

Permalink
Merge pull request #756 from ufal/printing_dicts
Browse files Browse the repository at this point in the history
Better printing of dictionaries and lists in print_examples
  • Loading branch information
jlibovicky committed Sep 12, 2018
2 parents dd26a0f + c95a953 commit d019f26
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions neuralmonkey/learning_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,12 @@ def print_final_evaluation(name: str, eval_result: Evaluation) -> None:

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

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

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

0 comments on commit d019f26

Please sign in to comment.