Learning can generate long memory