DEV Community

Lauren C.
Lauren C.

Posted on

Hugging Face: Interacting with Roberta and Hugging Face for the first time

This is my first interaction with Hugging Face. The free and open Ai option

Date: September 15, 2024

Prerequisites: I bought a 1T external SSD and created this tutorial using the external hard drive. I am using a windows computer. This is where the tutorial begins.

  • Change directory to D drive
    $D:

  • create directory on external SSD titled version of python and pip I'm using

$mkdir python312
$cd python312
$mkdir Scripts

  • install python and pip file from website. Save in python312 directory and install virtual environment with command:
    $pip install virtualenv

  • verify it's working by checking the version

python --version
pip --version
virtualenv --version

  • Create virtual environment. Tool is called virtualenv. Name of the virtual env. is my_venv.
  • Next command "python" invokes interpreter. -m runs module as script. venv module is invoked and my_venv is name of virtual environment

$ virtualenv my_venv
$python -m venv my_venv

  • Activate virtual environment

$.\my_venv\Scripts\activate

  • Install Transformers, datasets, and pytourch

$pip install transformers
$pip install datasets
$pip install torch
$pip install tensorflow

  • install Visual Studio from Microsoft website to edit python files and create python files
  • Open Visual Studio Installer
  • Select Modify and add Python development by checking the box
  • click modify

  • in Scripts directory create new application in visual studios. Save in script file in D drive. Name "roberta_hugging_face" and save solution and project in same directory

add code to file:

from transformers import pipeline

# Load the sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")

# Perform sentiment analysis
result = sentiment_pipeline("Hugging Face is creating amazing tools for NLP!")
print(result)

Enter fullscreen mode Exit fullscreen mode
  • run file. You should be in:

D:\python312\Scripts\roberta_hugging_face

$python roberta_hugging_face.py

  • install backward compatible package and retry running
    $pip install tf-keras
    $python roberta_hugging_face.py

  • When download is complete you will see the result for the pipeline "Hugging Face is creating amazing tools for NLP!"

  • To deactivate
    $deactivate

  • Safely disconnect SSD

Top comments (0)