Explaining Hugging Face 🤗

I’ve had the pleasure of explaining hugging face to a few software developer friends of mine. I figured it was worth writing down what I explained to them. At this point I have under a month of experience.

Hugging Face (🤗) is a platform to share various models. It was started originally in 2016 by french entrepreneurs who originally made a chatbot app but pivoted in 2018 when they open sourced their natural language processing (NLP) model(s). Just in time for the increased excitement from the generative AI boom!

I explain that models are pieces of software that do something useful, like generate responses (like in ChatGPT), turn text into voice acted audio, or identify objects in images (like how likely an image has a hot dog in it).

This is not a comprehensive list and there are more model categories to check out. At a more technical level, these models are forms of applied machine learning as they represent particular configurations of a n-neuron neural nets that lets software have these human-like abilities. At a practical level, you can browse https://huggingface.co/models to filter by the type of capability you want for your software solution so you can finally find a useful open source model to use.

Hugging Face 🤗 also developed the transformers python library (documentation link) to make consuming these models relatively easy. You can filter by models that are compatible with this library, which will most likely include an example code snippet that should help you get started using the model in your application.

from transformers import pipeline

nlp = pipeline(
    "document-question-answering",
    model="impira/layoutlm-document-qa",
)

nlp(
    "https://templates.invoicehome.com/invoice-template-us-neat-750px.png",
    "What is the invoice number?"
)
# {'score': 0.9943977, 'answer': 'us-001', 'start': 15, 'end': 15}

nlp(
    "https://miro.medium.com/max/787/1*iECQRIiOGTmEFLdWkVIH2g.jpeg",
    "What is the purchase amount?"
)
# {'score': 0.9912159, 'answer': '$1,000,000,000', 'start': 97, 'end': 97}

nlp(
    "https://www.accountingcoach.com/wp-content/uploads/2013/10/income-statement-example@2x.png",
    "What are the 2020 net sales?"
)
# {'score': 0.59147286, 'answer': '$ 3,750', 'start': 19, 'end': 20}

Example code from impira/layoutlm-document-qa model.

The final element I want to discuss is Hugging Face 🤗 spaces. Spaces is comparable to GitHub pages but instead of hosting static assets you are meant to host AI apps. Many people have built useful applications using these open source models (in fact on a model’s detail page you can see what spaces use the model). If you want to build on spaces I recommend using Gradio (documentation and gradio 5 blog post) because it allows one to build up an AI application quickly, but you can host other types of spaces apps.

With that we covered the primary points of the Hugging Face platform. I’m excited to be exploring this as I can easily use open source models to give my software solutions more interesting functionality.

Leave a comment

Your email address will not be published. Required fields are marked *