|
1 | 1 | # Hugging Face Transformers: Leverage Open-Source AI in Python |
2 | 2 |
|
3 | | -This folder contains the materials for the tutorial (Hugging Face Transformers: Leverage Open-Source AI in Python)[https://realpython.com/huggingface-transformers/]. |
| 3 | +This folder contains the materials for the tutorial [Hugging Face Transformers: Leverage Open-Source AI in Python](https://realpython.com/huggingface-transformers/). |
4 | 4 |
|
5 | | -Transformers is available on [PyPI](https://pypi.org/) and you can install it with [pip](https://realpython.com/what-is-pip/). Open a terminal or command prompt, create a new virtual environment, and then run the following command: |
| 5 | +## Installation |
6 | 6 |
|
7 | | -```console |
8 | | -(venv) $ python -m pip install transformers |
| 7 | +Create and activate a virtual environment, and then install the required dependencies: |
| 8 | + |
| 9 | +```sh |
| 10 | +(venv) $ python -m pip install transformers torch pillow notebook ipywidgets |
| 11 | +``` |
| 12 | + |
| 13 | +Alternatively, if you use [Poetry](https://realpython.com/dependency-management-python-poetry/), then you can issue the following command to handle the installation process for you: |
| 14 | + |
| 15 | +```sh |
| 16 | +$ poetry install |
9 | 17 | ``` |
10 | 18 |
|
11 | | -This command will install the latest version of Transformers from PyPI onto your machine. Throughout this tutorial, you'll also leverage [PyTorch](https://realpython.com/pytorch-vs-tensorflow/) to interact with models at a lower level. You can install PyTorch with the following command: |
| 19 | +## Usage |
12 | 20 |
|
13 | | -```console |
14 | | -(venv) $ python -m pip install torch |
| 21 | +Run the sample Python scripts: |
| 22 | + |
| 23 | +```sh |
| 24 | +(venv) $ python auto_classes.py |
| 25 | +(venv) $ python running_pipelines.py |
15 | 26 | ``` |
16 | 27 |
|
17 | | -To verify that the installations were successful, start a [Python REPL](https://realpython.com/python-repl/) and import `transformers` and `torch`: |
| 28 | +Run the sample Jupyter notebook: |
18 | 29 |
|
19 | | -```pycon |
20 | | ->>> import transformers |
21 | | ->>> import torch |
| 30 | +```sh |
| 31 | +(venv) $ python -m jupyter notebook gpus_google_colab.ipynb |
22 | 32 | ``` |
23 | 33 |
|
24 | | -If the imports run without errors, then you've successfully installed the dependencies needed for this tutorial. |
| 34 | +Note that if you run this notebook in Google Colab, then you'll need to update the path to the `requirements.txt` file and the `DATA_PATH` constant accordingly: |
| 35 | + |
| 36 | +```diff |
| 37 | +-!pip install -r requirements.txt |
| 38 | ++!pip install -r /content/requirements.txt |
| 39 | + |
| 40 | +-DATA_PATH = "Scraped_Car_Review_dodge.csv" |
| 41 | ++DATA_PATH = "/content/Scraped_Car_Review_dodge.csv" |
| 42 | +``` |
0 commit comments