I, myself, found a good explanation and implementation of using F1 as training loss as below, it didn’t work for my dataset though.

  
      
      Medium – 11 Mar 20
  
  
    

The Unknown Benefits of using a Soft-F1 Loss in Classification Systems 4

How to not maintain a decision threshold and still optimize directly for what you care about!

  Reading time: 14 min read