Skip to content
This repository was archived by the owner on Jan 22, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/lib/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class EvaluationMetric(enum.Enum):
F1_SCORE = 'f1_score'
CONFUSION_MATRIX = 'confusion_matrix'
INSTRUCTION_POINTER = 'instruction_pointer'
INSTRUCTION_POINTER_ENTROPY = 'instruction_pointer_entropy'


def all_metric_names() -> Tuple[str]:
Expand Down Expand Up @@ -161,6 +162,21 @@ def instruction_pointers_to_images(instruction_pointer, multidevice: bool):
return jnp.array(instruction_pointer_image_list)


def instruction_pointers_to_entropy(instruction_pointer, multidevice: bool):
"""Converts the given batched instruction pointer to an entropy value.

The entropy value measures the sharpness of the instruction pointer, i.e. how
hard vs soft it is.
"""
if multidevice:
# instruction_pointer: device, batch_size / device, timesteps, num_nodes
instruction_pointer = instruction_pointer[0]

# instruction_pointer: batch_size / device, timesteps, num_nodes
# TODO: Implement entropy calculation.
raise NotImplementedError()


def pad(array, leading_dim_size: int):
"""Pad the leading dimension of the given array."""
leading_dim_difference = max(0, leading_dim_size - array.shape[0])
Expand Down
8 changes: 8 additions & 0 deletions core/lib/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ def run_train(self, dataset_path=DEFAULT_DATASET_PATH, split='train', steps=None
transform_fn=functools.partial(
metrics.instruction_pointers_to_images,
multidevice=config.multidevice))
metrics.write_metric(
EvaluationMetric.INSTRUCTION_POINTER_ENTROPY.value,
aux,
train_writer.scalar,
step,
transform_fn=functools.partial(
metrics.instruction_pointers_to_entropy,
multidevice=config.multidevice))

# Write validation metrics.
valid_writer.scalar('loss', valid_loss, step)
Expand Down