Working with Hugging Face
Jacob H. Marquez
Lead Data Engineer
$$
from transformers import pipeline
my_pipeline = pipeline( "text-classification", model="distilbert-base-uncased-finetuned-sst-2-english" )
print(my_pipeline("DataCamp is awesome!"))
[{'label': 'POSITIVE', 'score': 0.99}]
from transformers import pipeline my_pipeline = pipeline("text-generation", model="gpt2")
results = my_pipeline("What if AI", max_length=10, num_return_sequences=2)
for result in results: print(result['generated_text'])
What if AI had never existed?
What if AI could be really smarter than us?
$$
$$
my_pipeline = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
my_pipeline.save_pretrained("/path/to/saved_model_directory")
reloaded_pipeline = pipeline("text-classification", model="/path/to/saved_model_directory") print(reloaded_pipeline("Hugging Face is great!"))
[{'label': 'POSITIVE', 'score': 0.9998798370361328}]
Working with Hugging Face