The intent-based networking (IBN) paradigm targets defining high-level abstractions so network operators can define what their desired outcomes are without specifying how they would be achieved. The latter can be achieved by leveraging network programmability, monitoring, and data analytics, as well as the key assurance component. In this tutorial, we introduce the IBN paradigm and its application to optical networking, highlighting the benefits that machine learning (ML) algorithms can provide to IBN. Because the deployment of ML applications requires a specific orchestrator to create ML functions that are connected as ML pipelines, we show an implementation of such an orchestrator. Some challenges and solutions are presented for the generation of accurate synthetic data, proactive self-configuration, and cooperative intent operation. Illustrative examples of intent-based operation and numerical results are presented, and the obtained performance is discussed.