جميع المكتبات التي سنستخدمها في هذه الدورة متاحة كحزم برمجية لغة بايثون لذا سنوضح لك هنا كيفية إعداد بيئة بايثون وتثبيت المكتبات المحددة التي ستحتاج إليها.
سنغطي طريقتين لإعداد بيئة العمل الخاصة بك، باستخدام دفتر Colab أو بيئة عمل Python الافتراضية. لا تتردد في اختيار الطريقة التي تناسبك أكثر. بالنسبة للمبتدئين، نوصي بالبدء باستخدام دفتر Colab.
يرجى ملاحظة أننا لن نغطي نظام ويندوز. إذا كنت تستخدم نظام ويندوز، فإننا نوصي بمتابعة الدورة باستخدام دفتر Colab. إذا كنت تستخدم توزيعة لينكس أو macOS، فيمكنك استخدام أي من الطريقتين الموضحة هنا.
تعتمد معظم الدورة على وجود حساب لدى ضم الوجه Hugging Face . نوصي بإنشاء حساب الآن: إنشاء حساب. انشئ حساب هنا.
استخدام دفتر ملاحظات Colab طريقة الاعداد بسيطة جدا. قم بتشغيل دفتر ملاحظات في متصفحك وابدأ البرمجة على الفور!
إذا لم تكن ملمًا بـ Colab ، فإننا نوصي بأن تبدأ باتباع [المقدمة] (https://colab.research.google.com/notebooks/intro.ipynb). يتيح لك Colab استخدام بعض أجهزة المعالجة ، مثل وحدات المعالجة الرسومية (GPUs) أو TPUs ، كما ننوه أنه يتيح لك الاشتراك المجاني.
بمجرد أن تشعر بالراحة أثناء التنقل في Colab، أنشئ دفتر ملاحظات جديد وابدأ في الإعداد:
الخطوة التالية هي تثبيت المكتبات التي سنستخدمها في هذه الدورة. سنستخدم pip للتثبيت والذي هو مدير حزم بايثون. يمكنك تشغيل الأوامر النظامية في دفاتر بيانات باستخدام ! ، لذا يمكنك تثبيت مكتبة 🤗 Transformers على النحو التالي:
!pip install transformers
يمكنك التأكد من تثبيت الحزمة بشكل صحيح عن طريق استيرادها داخل بيئة بايثون الخاصة بك:
import transformers
يتم تثبيت إصدار خفيف جدًا من 🤗 Transformers. على وجه الخصوص ، لم يتم تثبيت أي إطارات تعلم الآلة الخاصة (مثل PyTorch أو TensorFlow). نظرًا لأننا سنستخدم العديد من الميزات المختلفة للمكتبة ، فإننا نوصي بتثبيت الإصدار التطويري ، والذي يأتي مع جميع البرامج اللازمة لأي حالة يمكن تخيلها تقريبًا:
!pip install transformers[sentencepiece]
هذا سيستغرق بعض الوقت ، ولكن بعد ذلك ستكون جاهزًا للبدء في بقية الدورة!
سأكمل الترجمة لاحقا من هنا ######
If you prefer to use a Python virtual environment, the first step is to install Python on your system. We recommend following this guide to get started.
Once you have Python installed, you should be able to run Python commands in your terminal. You can start by running the following command to ensure that it is correctly installed before proceeding to the next steps: python --version
. This should print out the Python version now available on your system.
When running a Python command in your terminal, such as python --version
, you should think of the program running your command as the “main” Python on your system. We recommend keeping this main installation free of any packages, and using it to create separate environments for each application you work on — this way, each application can have its own dependencies and packages, and you won’t need to worry about potential compatibility issues with other applications.
In Python this is done with virtual environments, which are self-contained directory trees that each contain a Python installation with a particular Python version alongside all the packages the application needs. Creating such a virtual environment can be done with a number of different tools, but we’ll use the official Python package for that purpose, which is called venv
.
First, create the directory you’d like your application to live in — for example, you might want to make a new directory called transformers-course at the root of your home directory:
mkdir ~/transformers-course
cd ~/transformers-course
From inside this directory, create a virtual environment using the Python venv
module:
python -m venv .env
You should now have a directory called .env in your otherwise empty folder:
ls -a
. .. .env
You can jump in and out of your virtual environment with the activate
and deactivate
scripts:
# Activate the virtual environment
source .env/bin/activate
# Deactivate the virtual environment
source .env/bin/deactivate
You can make sure that the environment is activated by running the which python
command: if it points to the virtual environment, then you have successfully activated it!
which python
/home/<user>/transformers-course/.env/bin/python
As in the previous section on using Google Colab instances, you’ll now need to install the packages required to continue. Again, you can install the development version of 🤗 Transformers using the pip
package manager:
pip install "transformers[sentencepiece]"
You’re now all set up and ready to go!