Git Product home page Git Product logo

classify-news-amazon-sagemaker-hugging-face's Introduction

Bring your own data to classify news with Amazon SageMaker and Hugging Face

In this example notebook, we explore how to bring your own data for a Text Classification task, by fine-tuning and deploying SOTA models with Amazon SageMaker, the Hugging Face containers, and the SageMaker Python SDK.

We also rely on the library of pre-trained models available in Hugging Face. We will demonstrate how you can bring your own custom data to fine tune the models, and use the processing scripts available in the Hugging Face hub for speeding up the process on tasks such as tokenization and data loading. Finally, we will deploy the model to a SageMaker endpoint and perform real-time inferences with sample phrases on our text classification use case.

In this example, the Amazon SageMaker Estimator is pointing directly towards the entry point script “run_glue.py” located in the Hugging Face repository in GitHub, i.e., there is NO need to copy this script manually to our environment. You can rely on this script for bringing any custom data in CSV or JSON format for your text classification tasks, as long as it includes the classification label and text fields. Note that you have other equivalent scripts also available in the Transformers repository for other text processing tasks, such as: summarization, text-generation, etc. In our news classification example, this script together with the SageMaker and HuggingFace integration will automatically:

  • Pre-process our input data, e.g., encoding text labels and the likes.
  • Perform the relevant tokenization in the text automatically for us
  • Prepare the data for training our BERT model for text classification.

This represents a huge improvement in development time saving, and an operational efficiency increase compared to developing and performing these tasks manually in an equivalent PyTorch implementation.

For more details on this example check the AWS ML Blog post: here

Note this example uses the AG News dataset cited in the paper Character-level Convolutional Networks for Text Classification by Xiang Zhang and Yann LeCun. This dataset is available on the AWS Open Data Registry.

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

classify-news-amazon-sagemaker-hugging-face's People

Contributors

amazon-auto avatar rodzanto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

classify-news-amazon-sagemaker-hugging-face's Issues

Code errors out

Details of error:

KeyError Traceback (most recent call last)
in
4 huggingface_model = sagemaker.huggingface.HuggingFaceModel(
5 env={ 'HF_TASK':'text-classification' },
----> 6 model_data=huggingface_estimator_bert.model_data,
7 role=role,
8 transformers_version="4.6.1",

/opt/conda/lib/python3.7/site-packages/sagemaker/estimator.py in model_data(self)
1043 model_uri = self.sagemaker_session.sagemaker_client.describe_training_job(
1044 TrainingJobName=self.latest_training_job.name
-> 1045 )["ModelArtifacts"]["S3ModelArtifacts"]
1046 else:
1047 logger.warning(

KeyError: 'ModelArtifacts'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.