Machine learning discovers invariants of braids and flat braids