# About the Amazon SageMaker category

**URL:** <https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603>\
**Category:** Amazon SageMaker\
**Created:** [March 18, 2021, 3:32pm UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603 "2021-03-18T15:32:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pierric](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/pierric/32/50750_2.png) [@pierric](https://discuss.huggingface.co/u/pierric)\
**Post date:** [March 18, 2021, 3:32pm UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/1 "2021-03-18T15:32:45Z")

</div>

This category is for any questions related to using Hugging Face Transformers with Amazon SageMaker. Don’t forget to check the announcement [blogpost](https://huggingface.co/blog/the-partnership-amazon-sagemaker-and-hugging-face) for more resources.

---

<div class="post-metadata">

**Author:** ![m-ali-awan](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@m-ali-awan](https://discuss.huggingface.co/u/m-ali-awan)\
**Post date:** [May 5, 2021, 7:16pm UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/2 "2021-05-05T19:16:37Z")

</div>

Thanks for this amazing project, definitely HuggingFace, and Sagemaker, both are the leading in their particular domains, and integrating both, will definitely enhance their effectiveness.

Is it currently possible to deploy real-time endpoints with Sagemaker, using Huggingface?

Thanks…

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](https://discuss.huggingface.co/u/philschmid)\
**Post date:** [May 6, 2021, 6:57am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/3 "2021-05-06T06:57:23Z")

</div>

Hey @m-ali-awan,

thank you for the feedback 🤗

We are currently working on a nice way to deploy all of the Hugging Face models to SageMaker. But this still takes a little time. In the meantime, you could use either the `tensorflow` or `pytorch` inference toolkit.

---

<div class="post-metadata">

**Author:** ![m-ali-awan](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@m-ali-awan](https://discuss.huggingface.co/u/m-ali-awan)\
**Post date:** [May 6, 2021, 9:37am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/4 "2021-05-06T09:37:23Z")

</div>

Thanks for responding.  
Are there any example nbs available for deploying?

And, I will be very grateful if you can guide me about this:  
I am trying to build custom Document-Classifier with HuggingFace, but my client is currently using Amazon-Comprehend, so is it possible to come up with better classifer than Comprehend, as we have less data:i.e 50/class, and total 20 classes?

Thanks…

---

<div class="post-metadata">

**Author:** ![OlivierCR](https://avatars.discourse-cdn.com/v4/letter/o/b19c9b/32.png) [@OlivierCR](https://discuss.huggingface.co/u/OlivierCR)\
**Post date:** [May 6, 2021, 10:50am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/5 "2021-05-06T10:50:14Z")

</div>

Hi @m-ali-awan , thanks a lot for reaching out! you can find HF deployment examples here:

- [GitHub - aws-samples/amazon-sagemaker-bert-classify-pytorch: This sample show you how to train BERT on Amazon Sagemaker using Spot instances](https://github.com/aws-samples/amazon-sagemaker-bert-classify-pytorch) (the training part uses the PyTorch container but should work fine in the newer HF container as well)
- [Serving PyTorch models in production with the Amazon SageMaker native TorchServe integration | AWS Machine Learning Blog](https://aws.amazon.com/blogs/machine-learning/serving-pytorch-models-in-production-with-the-amazon-sagemaker-native-torchserve-integration/)
- [Fine-tuning a PyTorch BERT model and deploying it with Amazon Elastic Inference on Amazon SageMaker | AWS Machine Learning Blog](https://aws.amazon.com/blogs/machine-learning/fine-tuning-a-pytorch-bert-model-and-deploying-it-with-amazon-elastic-inference-on-amazon-sagemaker/)

Note that the SageMaker hosting experience varies depending on your version of PyTorch (MMS backend or TorchServe backend) [Use PyTorch with the SageMaker Python SDK — sagemaker 2.39.1 documentation](https://sagemaker.readthedocs.io/en/stable/frameworks/pytorch/using_pytorch.html#deploy-pytorch-models)

It’s not possible to tell you whether HF or Comprehend will give you better results because half the answer is in the developer hands 🙂 : it depends on the data, the model, its training (epochs, optimizers…). Using your own Hugging Face code in SageMaker, you will indeed have more freedom from a science and system architecture standpoint (free to inspect the model, export it out of AWS, play with its weights, test various backends and tasks etc), but be aware that with more freedom comes more responsibility: model science and infrastructure becomes your ownership. In Comprehend, more things are managed, with a concession on development freedom.

---

<div class="post-metadata">

**Author:** ![m-ali-awan](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@m-ali-awan](https://discuss.huggingface.co/u/m-ali-awan)\
**Post date:** [May 6, 2021, 11:26am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/6 "2021-05-06T11:26:33Z")

</div>

Thanks alot.

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](https://discuss.huggingface.co/u/philschmid)\
**Post date:** [May 6, 2021, 11:27am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/7 "2021-05-06T11:27:48Z")

</div>

Another option would be to upload your fine-tuned model to the [Hugging Face Hub](https://huggingface.co/models) as either a `private` or a `public` model and then use it with the [🤗 Accelerated Inference API](https://api-inference.huggingface.co/docs/python/html/detailed_parameters.html#text-classification-task). You can test the [API for free or go with a plan that fits you and your customer](https://huggingface.co/pricing). You can compare it to Comprehend that it is managed, but it is easier to provide a custom model and benefit from the accelerations and optimizations the 🤗 Accelerated Inference AP is doing.

---

<div class="post-metadata">

**Author:** ![m-ali-awan](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@m-ali-awan](https://discuss.huggingface.co/u/m-ali-awan)\
**Post date:** [May 7, 2021, 2:54am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/8 "2021-05-07T02:54:35Z")

</div>

Thanks for this option.  
So, curently we are using Textract for OCR, and we want to use .txts from this pipeline, to be fed to Documnet-Classification, so can we integrate this API into AWS Lambda, or what should be the way to go?

Thanks…

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](https://discuss.huggingface.co/u/philschmid)\
**Post date:** [May 7, 2021, 6:59am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/9 "2021-05-07T06:59:48Z")

</div>

Yes, you could create a Python AWS Lambda function to read the `.txt` files. Then depending on how big the documents are splitting them into passages and then send the documents to the 🤗 Inference API with a `POST` HTTP-Request.  
You can the documentation [here](https://api-inference.huggingface.co/docs/python/html/detailed_parameters.html#text-classification-task).

---

<div class="post-metadata">

**Author:** ![m-ali-awan](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@m-ali-awan](https://discuss.huggingface.co/u/m-ali-awan)\
**Post date:** [May 7, 2021, 9:09am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/10 "2021-05-07T09:09:46Z")

</div>

Thanks, so is there any limit on the no of characters in a document, and if how can we cater for(increase) it.

Thanks…

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](https://discuss.huggingface.co/u/philschmid)\
**Post date:** [May 7, 2021, 9:58am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/11 "2021-05-07T09:58:13Z")

</div>

The limit of Tokens is depending on the model you use. For example `bert-base-case` has a `max_length` of 512 same as `bert-large-uncased`.

---

<div class="post-metadata">

**Author:** ![m-ali-awan](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@m-ali-awan](https://discuss.huggingface.co/u/m-ali-awan)\
**Post date:** [May 7, 2021, 11:22am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/12 "2021-05-07T11:22:22Z")

</div>

Ok, thanks, and when we are training for custom classes, we simply can increase these?  
And definitely, there would be some memory limitations, so how to cater this at inference for relatively large documents?

Thanks…

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](https://discuss.huggingface.co/u/philschmid)\
**Post date:** [May 7, 2021, 11:37am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/13 "2021-05-07T11:37:06Z")

</div>

It is not that simple to increase those. But there are Transformer models like [Longfromer](https://arxiv.org/abs/2004.05150) who have a max token length of 4096. Also available on the Hub. [allenai/longformer-base-4096 · Hugging Face](https://huggingface.co/allenai/longformer-base-4096)

---

<div class="post-metadata">

**Author:** ![m-ali-awan](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@m-ali-awan](https://discuss.huggingface.co/u/m-ali-awan)\
**Post date:** [May 7, 2021, 11:58am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/14 "2021-05-07T11:58:49Z")

</div>

Thanks a lot, @philschmid,

I have already teased you a lot, but sorry, I am not experienced enough with HuggingFace.

So, can we train this Longformer, for custom case?

Thanks…

---

<div class="post-metadata">

**Author:** ![m-ali-awan](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@m-ali-awan](https://discuss.huggingface.co/u/m-ali-awan)\
**Post date:** [May 31, 2021, 10:12am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/15 "2021-05-31T10:12:24Z")

</div>

Hi philishmid, hope you are fine.  
Do we have support for Relation-Extraction models, to be fine-tuned with sagemaker.  
If yes, kindly share any relevant notebook link.

Thanks a lot…

---

<div class="post-metadata">

**Author:** ![m-ali-awan](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@m-ali-awan](https://discuss.huggingface.co/u/m-ali-awan)\
**Post date:** [June 1, 2021, 12:47am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/16 "2021-06-01T00:47:04Z")

</div>

Please, share with me any resources(colab notebooks) related to relationship-extraction.

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](https://discuss.huggingface.co/u/philschmid)\
**Post date:** [June 1, 2021, 6:26am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/17 "2021-06-01T06:26:24Z")

</div>

@m-ali-awan, You can find all example we currently have in these 4 different resources

- [transformers notebooks](https://huggingface.co/transformers/notebooks.html)
- [community notebooks](https://huggingface.co/transformers/community.html)
- [example scripts](https://github.com/huggingface/transformers/tree/master/examples)
- [SageMaker Notebooks](https://github.com/huggingface/notebooks/tree/master/sagemaker)

---

<div class="post-metadata">

**Author:** ![m-ali-awan](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@m-ali-awan](https://discuss.huggingface.co/u/m-ali-awan)\
**Post date:** [June 1, 2021, 6:28am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/18 "2021-06-01T06:28:31Z")

</div>

Thanks alot, but do it contains examples for Relationship-Extraction?

---

<div class="post-metadata">

**Author:** ![m-ali-awan](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@m-ali-awan](https://discuss.huggingface.co/u/m-ali-awan)\
**Post date:** [June 1, 2021, 6:29am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/19 "2021-06-01T06:29:02Z")

</div>

Or any new state-of-the-art NER?

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](https://discuss.huggingface.co/u/philschmid)\
**Post date:** [June 2, 2021, 5:45am UTC](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603/20 "2021-06-02T05:45:37Z")

</div>

@m-ali-awan yes the community notebooks, as well as the example scripts, include examples for Named-Entity-Recognition.  
On the Hub, we have ~800 models trained for token classification. Take a look and see if one of these fits your use-case [Hugging Face – The AI community building the future.](https://huggingface.co/models?pipeline_tag=token-classification)

[Next page](https://discuss.huggingface.co/t/about-the-amazon-sagemaker-category/4603.md?page=2)
