MCPcopy Index your code
hub / github.com/JetBrains-Research/code2seq / _shared_step

Method _shared_step

code2seq/model/code2class.py:55–65  ·  view source on GitHub ↗
(self, batch: BatchedLabeledPathContext, step: str)

Source from the content-addressed store, hash-verified

53 # ========== MODEL STEP ==========
54
55 def _shared_step(self, batch: BatchedLabeledPathContext, step: str) -> Dict:
56 # [batch size; num_classes]
57 logits = self(batch.from_token, batch.path_nodes, batch.to_token, batch.contexts_per_label)
58 labels = batch.labels.squeeze(0)
59 loss = torch.nn.functional.cross_entropy(logits, labels)
60
61 with torch.no_grad():
62 predictions = logits.argmax(-1)
63 accuracy = self.__metrics[f"{step}_acc"](predictions, labels)
64
65 return {f"{step}/loss": loss, f"{step}/accuracy": accuracy}
66
67 def training_step(self, batch: BatchedLabeledPathContext, batch_idx: int) -> Dict: # type: ignore
68 result = self._shared_step(batch, "train")

Callers 3

training_stepMethod · 0.95
validation_stepMethod · 0.95
test_stepMethod · 0.95

Calls

no outgoing calls

Tested by 1

test_stepMethod · 0.76