Structure verification of deep neural networks at compilation time using dependent types

This paper presents TensorSafe, a dependently typed Haskell library which makes possible the definition and structural validation of deep neural networks architectures. Nowadays, the development process of deep learning models has been notably simplified due to the availability of sophisticated tools in the industry. However, most of these tools do not provide any security controls at compilation time, making the developers deal with unexpected run-time errors and uncertainties. In particular, validating the structure of deep neural networks at compilation time is a complex subject which involves the mathematical validation of all operations that a deep learning model will perform. Moreover, this structural checking requires an advanced usage of types systems theories to manipulate abstract type definitions capable of modeling neural networks constructions. Many different programming techniques were involved in the specification of TensorSafe. Primarily, the application of the functional programming paradigm and the use of dependent types were of great importance for the development process and to probe the correctness of the neural network models. The experimental evaluation showed that by using TensorSafe it is possible to correctly create well known deep neural network architectures, such like MNIST or ResNet50.