The Facebook parent is recovering sharply after months of investor doubts over its costly artificial intelligence strategy and legal challenges