Created
December 10, 2024 15:11
-
-
Save secemp9/75bcc3db5783f56a9c2a3e69fdce9939 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Direct solution weights: [0.79, 0.85, 0.84] | |
Forward output: [111, 117, 116] | |
Loss: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def direct_solution(target_string): | |
return [(ord(c) - 32) / 100.0 for c in target_string] | |
def forward(weights): | |
return [32 + round(w * 100) % 95 for w in weights] | |
def loss_fn(output, target): | |
return sum((o - t) ** 2 for o, t in zip(output, target)) | |
if __name__ == "__main__": | |
target_str = "out" | |
target = [ord(c) for c in target_str] | |
weights_direct = direct_solution(target_str) | |
output_direct = forward(weights_direct) | |
loss_direct = loss_fn(output_direct, target) | |
print("Direct solution weights:", weights_direct) | |
print("Forward output:", output_direct) | |
print("Loss:", loss_direct) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment