Close Menu
  • Breaking News
  • Business
  • Career
  • Sports
  • Climate
  • Science
    • Tech
  • Culture
  • Health
  • Lifestyle
  • Facebook
  • Instagram
  • TikTok
Categories
  • Breaking News (6,101)
  • Business (340)
  • Career (5,069)
  • Climate (231)
  • Culture (5,026)
  • Education (5,326)
  • Finance (239)
  • Health (918)
  • Lifestyle (4,796)
  • Science (5,010)
  • Sports (366)
  • Tech (191)
  • Uncategorized (1)
Hand Picked

NCTA Alumna and Broken Bow Vet McKenzie Hendricks Shares Career Journey with Students

January 27, 2026

Victoria Beckham Receives Honor From French Culture Ministry

January 27, 2026

Salem County school closures, delayed openings due to snow, ice storm for Tuesday (Jan. 27, 2026)

January 27, 2026

Florida gets 4-year sentence for shirtless robbery of Taco Bell using ‘large rock’

January 27, 2026
Facebook X (Twitter) Instagram
  • About us
  • Contact us
  • Disclaimer
  • Privacy Policy
  • Terms and services
Facebook X (Twitter) Instagram
onlyfacts24
  • Breaking News

    Florida gets 4-year sentence for shirtless robbery of Taco Bell using ‘large rock’

    January 27, 2026

    TV presenter killed in Israeli strike in southern Lebanon: Hezbollah | Freedom of the Press News

    January 27, 2026

    Tariffs on South Korean autos, pharma, to rise to 25%

    January 27, 2026

    Early moves by NYC Mayor Mamdani undercut affordability message he campaigned on

    January 27, 2026

    Canadian PM Carney unveils multibillion-dollar push to lower food costs | Inflation News

    January 26, 2026
  • Business

    Only two UNF SG committees able to conduct business, approve requests, discuss survey topic

    January 26, 2026

    How to Track Social Media Trends

    January 23, 2026

    Music Business 104 Wraps Fourth Edition With Global Growth

    January 22, 2026

    Starting a local business topic of Jan. 29 workshop in Gulf Shores & Orange Beach

    January 20, 2026

    Greenland expected to be a hot topic as President Trump meets with global business leaders

    January 20, 2026
  • Career

    NCTA Alumna and Broken Bow Vet McKenzie Hendricks Shares Career Journey with Students

    January 27, 2026

    Summit School District works on a masterplan as the district eyes potential school closures, career education enhancements

    January 27, 2026

    WV NewsDowntown Fairmont staple: How Eddie Snider turned a part-time job into a lifelong careerDowntown Fairmont staple: How Eddie Snider turned a part-time job into a lifelong career. by John Mark Shaver FAIRMONT NEWS EDITOR; Jan 26,….7 hours ago

    January 27, 2026

    Choosing the Right Education Specialization for Your Teaching Career

    January 26, 2026

    Buckeye Career Center honors dedicated board members during School Board Recognition Month

    January 26, 2026
  • Sports

    Madison Square Garden | concerts, sports, entertainment

    January 21, 2026

    New Bay City schools superintendent Grant Hegenauer tackles sports-topic Q&A

    January 21, 2026

    Catch rule could become a hot topic in 2026 offseason

    January 20, 2026

    Protests, State House activity, high school sports topic of central Maine week in photos

    January 16, 2026

    Figure skating | Olympics, Jumps, Moves, History, & Competitions

    January 16, 2026
  • Climate

    PA Environment & Energy Articles & NewsClips By Topic

    January 26, 2026

    PA Environment Digest BlogStories You May Have Missed Last Week: PA Environment & Energy Articles & NewsClips By TopicPA Environment Digest Puts Links To The Best Environment & Energy Articles and NewsClips From Last Week Here By Topic–..1 day ago

    January 18, 2026

    The Providence JournalWill the environment be a big topic during the legislative session? What to expectEnvironmental advocates are grappling with how to meet the state's coming climate goals..1 day ago

    January 13, 2026

    New Updates To California’s Climate Disclosure Laws – Climate Change

    January 6, 2026

    PA Environment & Energy Articles & NewsClips By Topic

    January 6, 2026
  • Science
    1. Tech
    2. View All

    Home Office admits facial recognition tech issue with black and Asian subjects | Facial recognition

    January 26, 2026

    EU researchers are increasingly publishing on tech topics with China • Table.Briefings

    January 9, 2026

    CES 2026 trends to watch: 5 biggest topics we’re expecting at the world’s biggest tech show

    January 1, 2026

    turbulent year for end-device and downstream applications

    January 1, 2026

    Scientists launch AI DinoTracker app that identifies dinosaur footprints | Dinosaurs

    January 27, 2026

    Scientists just got the clearest picture of the dark universe yet: ‘Now the dream has come true’

    January 27, 2026

    Artemis II astronauts enter quarantine. A milestone moment in the next crewed mission to the Moon

    January 27, 2026

    SpaceX to launch GPS 3 satellite following switch from ULA Vulcan rocket – Spaceflight Now

    January 27, 2026
  • Culture

    Victoria Beckham Receives Honor From French Culture Ministry

    January 27, 2026

    Zona Maco 2026 is Mexico City’s biggest Art Week yet

    January 27, 2026

    Ye, formerly Kanye West, apologizes for ‘reckless’ antisemitic comments

    January 27, 2026

    Chair File: Leadership Dialogue — Creating a Culture of Innovation with James Merlino of Joint Commission

    January 27, 2026

    Starwood at 45½ – Arts & Culture, Culture, Music Reviews, News, Paganism, Reviews, TWH Features, U.S., Witchcraft

    January 27, 2026
  • Health

    Is Smoking Weed Bad for Your Lungs?

    January 27, 2026

    Speech & Debate: “Health Insurance” to be 2026-27 National High School Policy Debate Topic

    January 23, 2026

    Hidden mental health burden on America’s agricultural heartland topic at FHSU Feb. 5

    January 23, 2026

    Reportable Medical Events at Military Health System Facilities Through Week 14, Ending April 5, 2025

    January 22, 2026

    Mpox – Southern Nevada Health District

    January 21, 2026
  • Lifestyle
Contact
onlyfacts24
Home»Science»Choosing and Implementing Hugging Face Models | by Stephanie Kirmer | Nov, 2024
Science

Choosing and Implementing Hugging Face Models | by Stephanie Kirmer | Nov, 2024

November 3, 2024No Comments
Facebook Twitter Pinterest LinkedIn Tumblr Email
11pjaci7 Nq58azzsw73zaq.png
Share
Facebook Twitter LinkedIn Pinterest Email

Pulling pre-trained models out of the box for your use case

Stephanie Kirmer

Towards Data Science

Photo by Erda Estremera on Unsplash

I’ve been having a lot of fun in my daily work recently experimenting with models from the Hugging Face catalog, and I thought this might be a good time to share what I’ve learned and give readers some tips for how to apply these models with a minimum of stress.

My specific task recently has involved looking at blobs of unstructured text data (think memos, emails, free text comment fields, etc) and classifying them according to categories that are relevant to a business use case. There are a ton of ways you can do this, and I’ve been exploring as many as I can feasibly do, including simple stuff like pattern matching and lexicon search, but also expanding to using pre-built neural network models for a number of different functionalities, and I’ve been moderately pleased with the results.

I think the best strategy is to incorporate multiple techniques, in some form of ensembling, to get the best of the options. I don’t trust these models necessarily to get things right often enough (and definitely not consistently enough) to use them solo, but when combined with more basic techniques they can add to the signal.

For me, as I’ve mentioned, the task is just to take blobs of text, usually written by a human, with no consistent format or schema, and try to figure out what categories apply to that text. I’ve taken a few different approaches, outside of the analysis methods mentioned earlier, to do that, and these range from very low effort to somewhat more work on my part. These are three of the strategies that I’ve tested so far.

  • Ask the model to choose the category (zero-shot classification — I’ll use this as an example later on in this article)
  • Use a named entity recognition model to find key objects referenced in the text, and make classification based on that
  • Ask the model to summarize the text, then apply other techniques to make classification based on the summary

This is some of the most fun — looking through the Hugging Face catalog for models! At https://huggingface.co/models you can see a gigantic assortment of the models available, which have been added to the catalog by users. I have a few tips and pieces of advice for how to select wisely.

  • Look at the download and like numbers, and don’t choose something that has not been tried and tested by a decent number of other users. You can also check the Community tab on each model page to see if users are discussing challenges or reporting bugs.
  • Investigate who uploaded the model, if possible, and determine if you find them trustworthy. This person who trained or tuned the model may or may not know what they’re doing, and the quality of your results will depend on them!
  • Read the documentation closely, and skip models with little or no documentation. You’ll struggle to use them effectively anyway.
  • Use the filters on the side of the page to narrow down to models suited to your task. The volume of choices can be overwhelming, but they are well categorized to help you find what you need.
  • Most model cards offer a quick test you can run to see the model’s behavior, but keep in mind that this is just one example and it’s probably one that was chosen because the model’s good at that and finds this case pretty easy.

Once you’ve found a model you’d like to try, it’s easy to get going- click the “Use this Model” button on the top right of the Model Card page, and you’ll see the choices for how to implement. If you choose the Transformers option, you’ll get some instructions that look like this.

Screenshot taken by author

If a model you’ve selected is not supported by the Transformers library, there may be other techniques listed, like TF-Keras, scikit-learn, or more, but all should show instructions and sample code for easy use when you click that button.

In my experiments, all the models were supported by Transformers, so I had a mostly easy time getting them running, just by following these steps. If you find that you have questions, you can also look at the deeper documentation and see full API details for the Transformers library and the different classes it offers. I’ve definitely spent some time looking at these docs for specific classes when optimizing, but to get the basics up and running you shouldn’t really need to.

Ok, so you’ve picked out a model that you want to try. Do you already have data? If not, I have been using several publicly available datasets for this experimentation, mainly from Kaggle, and you can find lots of useful datasets there as well. In addition, Hugging Face also has a dataset catalog you can check out, but in my experience it’s not as easy to search or to understand the data contents over there (just not as much documentation).

Once you pick a dataset of unstructured text data, loading it to use in these models isn’t that difficult. Load your model and your tokenizer (from the docs provided on Hugging Face as noted above) and pass all this to the pipeline function from the transformers library. You’ll loop over your blobs of text in a list or pandas Series and pass them to the model function. This is essentially the same for whatever kind of task you’re doing, although for zero-shot classification you also need to provide a candidate label or list of labels, as I’ll show below.

So, let’s take a closer look at zero-shot classification. As I’ve noted above, this involves using a pretrained model to classify a text according to categories that it hasn’t been specifically trained on, in the hopes that it can use its learned semantic embeddings to measure similarities between the text and the label terms.

from transformers import AutoModelForSequenceClassification
from transformers import AutoTokenizer
from transformers import pipeline

nli_model = AutoModelForSequenceClassification.from_pretrained("facebook/bart-large-mnli", model_max_length=512)
tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large-mnli")
classifier = pipeline("zero-shot-classification", device="cpu", model=nli_model, tokenizer=tokenizer)

label_list = ['News', 'Science', 'Art']

all_results = []
for text in list_of_texts:
prob = self.classifier(text, label_list, multi_label=True, use_fast=True)
results_dict = {x: y for x, y in zip(prob["labels"], prob["scores"])}
all_results.append(results_dict)

This will return you a list of dicts, and each of those dicts will contain keys for the possible labels, and the values are the probability of each label. You don’t have to use the pipeline as I’ve done here, but it makes multi-label zero shot a lot easier than manually writing that code, and it returns results that are easy to interpret and work with.

If you prefer to not use the pipeline, you can do something like this instead, but you’ll have to run it once for each label. Notice how the processing of the logits resulting from the model run needs to be specified so that you get human-interpretable output. Also, you still need to load the tokenizer and the model as described above.

def run_zero_shot_classifier(text, label):
hypothesis = f"This example is related to {label}."

x = tokenizer.encode(
text,
hypothesis,
return_tensors="pt",
truncation_strategy="only_first"
)

logits = nli_model(x.to("cpu"))[0]

entail_contradiction_logits = logits[:, [0, 2]]
probs = entail_contradiction_logits.softmax(dim=1)
prob_label_is_true = probs[:, 1]

return prob_label_is_true.item()

label_list = ['News', 'Science', 'Art']
all_results = []
for text in list_of_texts:
for label in label_list:
result = run_zero_shot_classifier(text, label)
all_results.append(result)

You probably have noticed that I haven’t talked about fine tuning the models myself for this project — that’s true. I may do this in future, but I’m limited by the fact that I have minimal labeled training data to work with at this time. I can use semisupervised techniques or bootstrap a labeled training set, but this whole experiment has been to see how far I can get with straight off-the-shelf models. I do have a few small labeled data samples, for use in testing the models’ performance, but that’s nowhere near the same volume of data I will need to tune the models.

If you do have good training data and would like to tune a base model, Hugging Face has some docs that can help. https://huggingface.co/docs/transformers/en/training

Performance has been an interesting problem, as I’ve run all my experiments on my local laptop so far. Naturally, using these models from Hugging Face will be much more compute intensive and slower than the basic strategies like regex and lexicon search, but it provides signal that can’t really be achieved any other way, so finding ways to optimize can be worthwhile. All these models are GPU enabled, and it’s very easy to push them to be run on GPU. (If you want to try it on GPU quickly, review the code I’ve shown above, and where you see “cpu” substitute in “cuda” if you have a GPU available in your programming environment.) Keep in mind that using GPUs from cloud providers is not cheap, however, so prioritize accordingly and decide if more speed is worth the price.

Most of the time, using the GPU is much more important for training (keep it in mind if you choose to fine tune) but less vital for inference. I’m not digging in to more details about optimization here, but you’ll want to consider parallelism as well if this is important to you- both data parallelism and actual training/compute parallelism.

We’ve run the model! Results are here. I have a few closing tips for how to review the output and actually apply it to business questions.

  • Don’t trust the model output blindly, but run rigorous tests and evaluate performance. Just because a transformer model does well on a certain text blob, or is able to correctly match text to a certain label regularly, doesn’t mean this is generalizable result. Use lots of different examples and different kinds of text to prove the performance is going to be sufficient.
  • If you feel confident in the model and want to use it in a production setting, track and log the model’s behavior. This is just good practice for any model in production, but you should keep the results it has produced alongside the inputs you gave it, so you can continually check up on it and make sure the performance doesn’t decline. This is more important for these kinds of deep learning models because we don’t have as much interpretability of why and how the model is coming up with its inferences. It’s dangerous to make too many assumptions about the inner workings of the model.

As I mentioned earlier, I like using these kinds of model output as part of a larger pool of techniques, combining them in ensemble strategies — that way I’m not only relying on one approach, but I do get the signal those inferences can provide.

I hope this overview is useful for those of you getting started with pre-trained models for text (or other mode) analysis — good luck!

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

Related Posts

Scientists launch AI DinoTracker app that identifies dinosaur footprints | Dinosaurs

January 27, 2026

Scientists just got the clearest picture of the dark universe yet: ‘Now the dream has come true’

January 27, 2026

Artemis II astronauts enter quarantine. A milestone moment in the next crewed mission to the Moon

January 27, 2026

SpaceX to launch GPS 3 satellite following switch from ULA Vulcan rocket – Spaceflight Now

January 27, 2026
Add A Comment
Leave A Reply Cancel Reply

Latest Posts

NCTA Alumna and Broken Bow Vet McKenzie Hendricks Shares Career Journey with Students

January 27, 2026

Victoria Beckham Receives Honor From French Culture Ministry

January 27, 2026

Salem County school closures, delayed openings due to snow, ice storm for Tuesday (Jan. 27, 2026)

January 27, 2026

Florida gets 4-year sentence for shirtless robbery of Taco Bell using ‘large rock’

January 27, 2026
News
  • Breaking News (6,101)
  • Business (340)
  • Career (5,069)
  • Climate (231)
  • Culture (5,026)
  • Education (5,326)
  • Finance (239)
  • Health (918)
  • Lifestyle (4,796)
  • Science (5,010)
  • Sports (366)
  • Tech (191)
  • Uncategorized (1)

Subscribe to Updates

Get the latest news from onlyfacts24.

Follow Us
  • Facebook
  • Instagram
  • TikTok

Subscribe to Updates

Get the latest news from ONlyfacts24.

News
  • Breaking News (6,101)
  • Business (340)
  • Career (5,069)
  • Climate (231)
  • Culture (5,026)
  • Education (5,326)
  • Finance (239)
  • Health (918)
  • Lifestyle (4,796)
  • Science (5,010)
  • Sports (366)
  • Tech (191)
  • Uncategorized (1)
Facebook Instagram TikTok
  • About us
  • Contact us
  • Disclaimer
  • Privacy Policy
  • Terms and services
© 2026 Designed by onlyfacts24

Type above and press Enter to search. Press Esc to cancel.