Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/main/sagemaker/12_batch_transform_inference/sagemaker-notebook.ipynb
Views: 2542
Huggingface Sagemaker-sdk - Run a batch transform inference job with 🤗 Transformers
Welcome to this getting started guide, we will use the new Hugging Face Inference DLCs and Amazon SageMaker Python SDK to deploy two transformer model for inference. In the first example we deploy a trained Hugging Face Transformer model on to SageMaker for inference. In the second example we directly deploy one of the 10 000+ Hugging Face Transformers from the Hub to Amazon SageMaker for Inference.<
Run Batch Transform after training a model
not included in the notebook
After you train a model, you can use Amazon SageMaker Batch Transform to perform inferences with the model. In Batch Transform you provide your inference data as a S3 uri and SageMaker will care of downloading it, running the prediction and uploading the results afterwards to S3 again. You can find more documentation for Batch Transform here
If you trained the model using the HuggingFace estimator, you can invoke transformer()
method to create a transform job for a model based on the training job.
For more details about what can be specified here, see API docs.
Run Batch Transform Inference Job with a fine-tuned model using jsonl
Data Pre-Processing
In this example we are using the provided tweet_data.csv
as dataset. The csv
contains ~1800 tweets about different airlines. The csv
contains 1 column "inputs"
with the tweets. To use this csv
we need to convert it into a jsonl
file and upload it to s3. Due to the complex structure of text are only jsonl
file supported for batch transform. As pre-processing we are removing the @
in the beginning of the tweet to get the names/identities correct.
_NOTE: While preprocessing you need to make sure that your inputs
fit the max_length
.
The created file looks like this
Create Inference Transformer to run the batch job
We use the twitter-roberta-base-sentiment model running our batch transform job. This is a RoBERTa-base model trained on ~58M tweets and finetuned for sentiment analysis with the TweetEval benchmark.