Take a look at defn (numerical definitions). Those a functions where you can write numerical code that works with tensors using the regular Elixir operators. You would get something like (untested):
import Nx.Defn
defn political_score(predict_fn, params, token_tensor) do
prediction = predict_fn.(params, token_tensor)
one_hot = 2 ** prediction / Nx.sum(2 ** prediction)
5 * (one_hot[0][0] - one_hot[0][2])
end






















