Solved by erolm-a in post #2 
              
              
                I partially solved the issues this way: 
for the first problem, I could still not find a truly satisfying solution, but I managed to remove the second for loop and reconvert it into a series of vectorized operations. 

avoid computing the gradients for the bio input
compute the mention spans
use tor…