US technology companies in May announced the most job cuts in nearly two years as they ramp up spending on artificial intelligence.