Activation functions and local gradients
Implement activation values and their first derivatives.
What’s going wrong
Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.
Input x is a list of finite values bounded by 10,000 and activation is sigmoid, tanh, relu, gelu or softplus. Use exact GELU x·Phi(x) with Phi from erf and the standard normal density in its derivative. ReLU has derivative zero at zero. Return values and gradients in input order.
Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.
Expected behavior
Implement activation values and their first derivatives.
Reproduction
{"activation":"gelu","x":[-2,0,2]}{"values":[-0.0455,0,1.9545],"gradients":[-0.085232,0.5,1.085232]}{"activation":"relu","x":[-2,0]}{"values":[0,0],"gradients":[0,0]}{"activation":"sigmoid","x":[]}{"values":[],"gradients":[]}Before you begin
- Python functions, lists and dictionaries
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.