Hugging Face

Key Concepts

Introduction

Hugging Face is a leading company in natural language processing (NLP), providing powerful tools and pre-trained models that can significantly enhance your trading algorithms on QuantConnect. By integrating Hugging Face's models, you can easily leverage advanced NLP capabilities for tasks such as sentiment analysis, news classification, and market forecasting without defining and training the model yourself. Hugging Face provides an easy way to leverage the research of community members to increase the sophistication of your trading algorithms.

Supported Models

Hundreds of thousands of Hugging Face models are publicly available and ready to use. To view all of them, see the Model Hub on the Hugging Face website. The Model card tab of each model repository explains an overview of how the model works, its requirements, and a quick start guide.

QuantConnect Cloud caches some of the most popular models to speed up your development workflow. The following table shows the cached models:

NameCategoryExample
ahmedrachid/FinancialBERT-Sentiment-AnalysisText Classification
amazon/chronos-t5-baseTime Series ForecastingExample
amazon/chronos-t5-largeTime Series ForecastingExample
amazon/chronos-t5-smallTime Series ForecastingExample
amazon/chronos-t5-tinyTime Series ForecastingExample
autogluon/chronos-t5-baseTime Series ForecastingExample
autogluon/chronos-t5-largeTime Series ForecastingExample
autogluon/chronos-t5-tinyTime Series ForecastingExample
bardsai/finance-sentiment-fr-baseText Classification
cardiffnlp/twitter-roberta-base-sentiment-latestText Classification
distilbert/distilbert-base-cased-distilled-squadQuestion Answering
distilbert/distilbert-base-uncasedFill-Mask
google-bert/bert-base-uncasedFill-Mask
google/gemma-7bText Generation
microsoft/deberta-baseFill-Mask
mrm8488/distilroberta-finetuned-financial-news-sentiment-analysisText Classification
nickmuchi/deberta-v3-base-finetuned-finance-text-classificationText Classification
nickmuchi/distilroberta-finetuned-financial-text-classificationText Classification
nickmuchi/sec-bert-finetuned-finance-classificationText Classification
openai-community/gpt2Text Generation
ProsusAI/finbertText ClassificationExample
Salesforce/moirai-1.0-R-baseTime Series Forecasting
Salesforce/moirai-1.0-R-largeTime Series Forecasting
Salesforce/moirai-1.0-R-smallTime Series Forecasting
StephanAkkerman/FinTwitBERT-sentimentText Classification
yiyanghkust/finbert-toneText ClassificationExample

To see the commit hash of the cached models, run the following algorithm in QC Cloud and then view the logs:

# Scan and log all cached Hugging Face model revisions from the cache directory.
from huggingface_hub import scan_cache_dir

class HuggingFaceModelHashAlgorithm(QCAlgorithm):

    def initialize(self):
        cache_info = scan_cache_dir()
        cached_models_log = []
        for entry in cache_info.repos:
            revisions = [revision.commit_hash for revision in entry.revisions]
            cached_models_log.append(f'Repo: {entry.repo_id}. Revisions {str(revisions)}')
        self.quit('\n'.join(sorted(cached_models_log)))

Train Models

Hugging Face models are pre-trained, so you can quickly load them into your algorithms and use their output to inform your trading decisions. To customize the model for your specific use case, you can fine-tune the pre-trained model with your own training data.

Examples

The following example algorithm demonstrates how to load a Hugging Face model into a trading algorithm, fine-tune it, and use its output to inform trading decisions:

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: