This lecture note reviews recently proposed sparse-modeling approaches for efficient ab initio many-body calculations based on the data compression of Greens functions. The sparse-modeling techniques are based on a compact orthogonal basis representation, intermediate representation (IR) basis functions, for imaginary-time and Matsubara Greens functions. A sparse sampling method based on the IR basis enables solving diagrammatic equations efficiently. We describe the basic properties of the IR basis, the sparse sampling method and its applications to ab initio calculations based on the GW approximation and the Migdal-Eliashberg theory. We also describe a numerical library for the IR basis and the sparse sampling method, irbasis, and provide its sample codes. This lecture note follows the Japanese review article [H. Shinaoka et al., Solid State Physics 56(6), 301 (2021)].