Project Report "Google TensorFlow API Bindings for Perl"
Sun, 12-Feb-2023 by
Saif Ahmed
edit post
It has been a pleasure to report on this work submitted in Jul 2022 by John Napiorkowski ( [JJNAPIORK](https://metacpan.org/author/JJNAPIORK)). Due to his ill health (we wish him the best for a speedier recovery), a lot of the heavy lifting has been done by [Zakariyya Mughal](https://metacpan.org/author/ZMUGHAL), and [Will Braswell](https://metacpan.org/author/WBRASWELL). The project has been submitted for final review. The delivered deliverables are below as outlined by John.
### 1: Symbols
"*An implementation of Perl API bindings to all applicable symbols in the TensorFlow C API, using FFI::Platypus from CPAN*."
We have implemented "all applicable symbols" required to load a TensorFlow graph and run the neural network model it contains. Of the 588 total functions in the TensorFlow C API, we have implemented 137 for this grant. Again, these 137 functions are all that are required to load and run the neural models, and to run all the test suites. The functions we didn't implement are not used for graph execution, and are thus not applicable to the work scope of this grant.
https://metacpan.org/dist/AI-TensorFlow-Libtensorflow/view/lib/AI/TensorFlow/Libtensorflow/Manual/CAPI.pod
### 2: Tests
"*A comprehensive Perl test suite with automatically-provable coverage for 100% of the Perl API, using Test2 from CPAN.*"
We ported all possible tests from the original C into Perl. We wrote 1,598 lines of code contained in 175 number of tests. The tests we didn't port were testing if the C & C++ APIs are compatible with one another, and are thus not applicable to the work
scope of this grant.
https://metacpan.org/dist/AI-TensorFlow-Libtensorflow/source/t/upstream/CAPI We also created new tests of basic TensorFlow functionality, ported from other code examples: https://metacpan.org/dist/AI-TensorFlow-Libtensorflow/source/t
### 3: Documentation
"*A carefully-written and explanatory collection of documentation with coverage for 100% of the Perl API, using normal POD fully compatible with CPAN*."
We wrote quite a bit of documentation, including the following...
**Manual & Quick Start Guide:**
https://metacpan.org/dist/AI-TensorFlow-Libtensorflow/view/lib/AI/TensorFlow/Libtensorflow/Manual.pod
https://metacpan.org/dist/AI-TensorFlow-Libtensorflow/view/lib/AI/TensorFlow/Libtensorflow/Manual/Quickstart.pod
**Tensor data structure:**
https://metacpan.org/pod/AI::TensorFlow::Libtensorflow::Tensor
**API calls:**
https://metacpan.org/dist/AI-TensorFlow-Libtensorflow/view/lib/AI/TensorFlow/Libtensorflow/Manual/CAPI.pod
### 4: Examples
"*A small collection of user-friendly example Perl applications, using popular TensorFlow components to effectively showcase the Perl API.*"
We have created a tutorial demonstrating an image classification application. Using the Mobile Net V2 neural network architecture trained on the ImageNet data set, we are able to automatically classify common images such as fruit, animals, vehicles, etc. (Also, we have already started promoting Perl TensorFlow among the programming community.) Our tutorials utilize the interactive web-based Jupyter notebook platform, along with the IPerl notebook kernel plugin, allowing Perl code to be run inside Jupyter; for more information, please see the Jupyter website: http://jupyter.org/
The 3 following links are the image classification tutorial notebook demo in static POD format, static Jupyter format, and dynamic interactive Jupyter format. Image classification tutorial:
https://metacpan.org/dist/AI-TensorFlow-Libtensorflow/view/lib/AI/TensorFlow/Libtensorflow/Manual/Notebook/InferenceUsingTFHubMobileNetV2Model.pod
https://nbviewer.org/github/EntropyOrg/perl-AI-TensorFlow-Libtensorflow/blob/master/notebook/InferenceUsingTFHubMobileNetV2Model.ipynb
https://mybinder.org/v2/gh/EntropyOrg/perl-AI-TensorFlow-Libtensorflow/master?filepath=notebook/InferenceUsingTFHubMobileNetV2Model.ipynb
We have also created a tutorial for a bioinformatics application, which is capable of predicting gene expression without running any physical laboratory experiments or simulated virtual experiments. Gene sequences are turned on and off by complex biological interactions, and thus are "expressed" differently in different types of cells. We are looking at the portions of human chromosome 11 located in between certain genetic coordinates, in order to discover which genes are "expressed" and are thus translated into gene products such as RNA and proteins. Gene expression prediction software has many possible uses, including predicting diseases and the initial research phase of creating cures. (We have also reached out to the
BioPerl community to promote and engage early adopters.)
**Gene expression tutorial:**
https://metacpan.org/dist/AI-TensorFlow-Libtensorflow/view/lib/AI/TensorFlow/Libtensorflow/Manual/Notebook/InferenceUsingTFHubEnformerGeneExprPredModel.pod
https://nbviewer.org/github/EntropyOrg/perl-AI-TensorFlow-Libtensorflow/blob/master/notebook/InferenceUsingTFHubEnformerGeneExprPredModel.ipynb
https://mybinder.org/v2/gh/EntropyOrg/perl-AI-TensorFlow-Libtensorflow/master?filepath=notebook/InferenceUsingTFHubEnformerGeneExprPredModel.ipynb
### 5: Repositories
"*A public GitLab repository with all source code and components of the Perl API, including unstable or experimental components.*"
We have created three new source code repositories for this grant, on both GitLab and GitHub...
[Alien::Bazel](https://gitlab.com/PerlAlien/alien-bazel), used to build libtensorflow C library from scratch (optional)
[Alien::Libtensorflow](https://github.com/EntropyOrg/perl-Alien-Libtensorflow), build or download libtensorflow C library.
[AI::TensorFlow::Libtensorflow](https://github.com/EntropyOrg/perl-AI-TensorFlow-Libtensorflow), the Perl API which requires libtensorflow C library.
### 6: CPAN
"*A public CPAN distribution with all stable source code and componentsof the Perl API.*"
We have released 3 new CPAN distributions, corresponding to the 3 source code repositories listed in requirement #5 above.
https://metacpan.org/dist/Alien-Bazel
https://metacpan.org/dist/Alien-Libtensorflow
https://metacpan.org/dist/AI-TensorFlow-Libtensorflow
### 7: Docker
"*A public DockerHub repository with all stable source code and components of the Perl API, along with all dependencies, ready to run out-of-the-box.*"
We have created both a Docker and also a Binder, so people can choose to use whichever they prefer, or neither if they want to install it all themselves. Due to potential server rate limitations on DockerHub, we have instead uploaded our Docker images to the public Quay container registry run by Red Hat.
**Dockerfile & Docker repository:**
https://github.com/EntropyOrg/perl-AI-TensorFlow-Libtensorflow/tree/master/docker
https://quay.io/repository/entropyorg/perl-ai-tensorflow-libtensorflow?tab=info
**Binder files & repository:**
https://github.com/EntropyOrg/perl-AI-TensorFlow-Libtensorflow/tree/master/.binder
https://mybinder.org/v2/gh/EntropyOrg/perl-AI-TensorFlow-Libtensorflow/master
Comments (0)