Turning Words into Code: A Guide to Using Text2Code for Jupyter Notebook

Jul 15, 2021 | Data Science

Ever found yourself drowning in the sea of programming syntax, while all you need is to convey your ideas in plain English? Fear not! With Text2Code for Jupyter Notebook, you can transform your English queries into relevant Python code in the blink of an eye. Let’s dive into this exciting extension that boosts your data analysis efficiency!

What is Text2Code?

Text2Code is a cutting-edge proof-of-concept Jupyter extension that converts English queries into usable Python code, making data analysis intuitive and accessible. No more wrestling with syntax—just type what you want, and let the tool take care of the rest.

Text2Code Demo

Supported Operating Systems

  • Ubuntu
  • macOS

Installation Instructions

Before we begin, it’s essential to uninstall any old versions of the plugin:

pip uninstall mopp

Now, based on your system capabilities, follow the installation steps below:

CPU-only Install

If you’re using Mac or an Ubuntu installation without an NVIDIA GPU, set the environment variable at the time of installation:

export JUPYTER_TEXT2CODE_MODE=cpu

GPU Install Dependencies

If you’re equipped with a GPU, install the required dependencies:

sudo apt-get install libopenblas-dev libomp-dev

Installation Commands

Follow these commands to complete the installation:

git clone https://github.com/deepklarity/jupyter-text2code.git
cd jupyter-text2code
pip install .
jupyter nbextension enable jupyter-text2code/main

Uninstallation

If you ever need to uninstall the plugin, simply run:

pip uninstall jupyter-text2code

Usage Instructions

To get started, launch your Jupyter Notebook server using the following command:

jupyter notebook

If you don’t see the Nbextensions tab, activate it with:

jupyter contrib nbextension install --user

Now, open the sample notebook ctds.ipynb for testing!

On your first run, the Universal Sentence Encoder model will download, enabling direct translation of your queries into Python code.

Click on the Terminal icon to explore a list of available commands by typing help. Curious? Check out the Demo Video for some impressive examples.

Using Docker Containers

For those who prefer containers, both CPU and GPU images of jupyter-text2code are available at Docker Hub. You can download the images and get usage instructions from here. The CPU image size is 1.51 GB, while the GPU image size is 2.56 GB.

Model Training

Text2Code supports pandas commands with quick snippet insertion for various integrations. You can now retrieve information like Twitter followers or Instagram statistics right from the notebook. For detailed steps on training, refer to the scripts README.

Adding More Intents

Want to expand functionality? Here’s a high-level overview of adding your intents:

  • Modify ner_templates with a new intent_id.
  • Generate new training data in generate_training_data.py.
  • Train the intent index and the NER model.
  • Update jupyter_text2code/jupyter_text2code_serverextension/__init__.py with new intents.
  • Finally, reinstall the plugin with pip install .

Troubleshooting

If you encounter issues, ensure that all dependencies are correctly installed and that your installation path is configured appropriately. If you don’t see the Nbextensions tab, revisit the installation steps for missing commands. Additionally, consider checking logs for additional hints.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Embrace the Future of Coding!

Now that you’ve equipped yourself with the knowledge to install and use Text2Code in your Jupyter notebooks, let your imagination run free. No more barriers between your thoughts and actual code! Happy coding!

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox