-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into python-async-iterators
- Loading branch information
Showing
6 changed files
with
2,119 additions
and
1,479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,42 @@ | ||
# Hugging Face Transformers: Leverage Open-Source AI in Python | ||
|
||
This folder contains the materials for the tutorial (Hugging Face Transformers: Leverage Open-Source AI in Python)[https://realpython.com/huggingface-transformers/]. | ||
This folder contains the materials for the tutorial [Hugging Face Transformers: Leverage Open-Source AI in Python](https://realpython.com/huggingface-transformers/). | ||
|
||
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: | ||
## Installation | ||
|
||
```console | ||
(venv) $ python -m pip install transformers | ||
Create and activate a virtual environment, and then install the required dependencies: | ||
|
||
```sh | ||
(venv) $ python -m pip install transformers torch pillow notebook ipywidgets | ||
``` | ||
|
||
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: | ||
|
||
```sh | ||
$ poetry install | ||
``` | ||
|
||
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: | ||
## Usage | ||
|
||
```console | ||
(venv) $ python -m pip install torch | ||
Run the sample Python scripts: | ||
|
||
```sh | ||
(venv) $ python auto_classes.py | ||
(venv) $ python running_pipelines.py | ||
``` | ||
|
||
To verify that the installations were successful, start a [Python REPL](https://realpython.com/python-repl/) and import `transformers` and `torch`: | ||
Run the sample Jupyter notebook: | ||
|
||
```pycon | ||
>>> import transformers | ||
>>> import torch | ||
```sh | ||
(venv) $ python -m jupyter notebook gpus_google_colab.ipynb | ||
``` | ||
|
||
If the imports run without errors, then you've successfully installed the dependencies needed for this tutorial. | ||
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: | ||
|
||
```diff | ||
-!pip install -r requirements.txt | ||
+!pip install -r /content/requirements.txt | ||
|
||
-DATA_PATH = "Scraped_Car_Review_dodge.csv" | ||
+DATA_PATH = "/content/Scraped_Car_Review_dodge.csv" | ||
``` |
File renamed without changes.
Oops, something went wrong.