iTranslated by AI
Setting Up a TensorFlow 2.0 Environment for Machine Learning on iMac
Introduction
After installing OpenInterpreter locally, I found myself unsure of what direction to take next, primarily because I have absolutely no prior knowledge of machine learning.
You can find more details about what I did with OpenInterpreter in the following article:
While researching OpenInterpreter, I came across an AI community called Hugging Face.
Hugging Face: An AI Community Attracting Global Attention
Hugging Face is such a cute name and gave me a very friendly impression. However, I felt an incredible amount of passion for AI coming from them.
"This is no ordinary group... I have to keep up with Hugging Face..."
A sense of both duty and excitement began to well up within me.
Upon looking into it, I found that to start machine learning, one must build and run an environment capable of machine learning, either in the cloud or locally.
This time, I decided to build my machine learning environment locally!
PC Specs for This Setup
Where Should I Start with Local Machine Learning?
Looking at Hugging Face, it seems that you can't even get started with machine learning without first installing either PyTorch or TensorFlow 2.0.
Incidentally, I learned that PyTorch was developed by Meta, while TensorFlow 2.0 was developed by Google.
PyTorch is an open-source machine learning library for Python, based on Torch, used for applications such as computer vision and natural language processing. It was originally developed by Meta AI (formerly Facebook's AI Research lab). (Wiki)
TensorFlow is a free and open-source software library for machine learning and artificial intelligence developed by Google. (Wiki)
While researching which one to install, I found that TensorFlow often handles more of the processing in the background, which supposedly means you have to write less code. To keep myself from getting discouraged, I decided to try installing TensorFlow.
TensorFlow 2.0 Installation
Let's take a look at the following installation steps:
macOS GPU is Not Officially Supported by TensorFlow
# There is currently no official GPU support for MacOS.
It was disappointing to find that macOS GPUs aren't officially supported, but it seemed like I could still install it in my current environment, so I decided to give it a try regardless. Eventually, I'd like to try this on a Windows machine equipped with an NVIDIA GPU.
I was able to install TensorFlow with just the following two commands. It's incredibly easy.
# There is currently no official GPU support for MacOS.
python3 -m pip install tensorflow
# Verify install:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
Next, I'll try introducing Transformers from Hugging Face.
Transformers provides APIs and tools to easily download and train state-of-the-art pretrained models. (From Hugging Face)
It makes it possible to use libraries that allow for a simple machine learning experience. I love APIs.
Installing Transformers
Since there was a library specifically for TensorFlow, I'll be installing that this time.
In my case, the instructions on Hugging Face didn't work perfectly, but it worked when I changed the command to use python3 as follows:
python3 -m venv .env
After that, just follow the official instructions and run the commands to proceed with the installation!
Once installed, I'll finish by downloading a pre-trained model and actually running it.
% python -c "from transformers import pipeline; print(pipeline('sentiment-analysis')('we love you'))"
2023-09-23 01:17:04.582969: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english and revision af0f99b (https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english).
Using a pipeline without specifying a model name and revision in production is not recommended.
All PyTorch model weights were used when initializing TFDistilBertForSequenceClassification.
All the weights of TFDistilBertForSequenceClassification were initialized from the PyTorch model.
If your task is similar to the task the model of the checkpoint was trained on, you can already use TFDistilBertForSequenceClassification for predictions without further training.
[{'label': 'POSITIVE', 'score': 0.9998704195022583}]
Looking at the following part, the result for the input 'we love you' was output!
[{'label': 'POSITIVE', 'score': 0.9998704195022583}]
Conclusion
Setting up a machine learning environment on an iMac was done in no time.
While tasks like image processing might take some time, I look forward to running various types of machine learning locally from now on!
This level of smoothness makes me feel nothing but a bright future!
I hope to share more and more about machine learning going forward.
Discussion