Getting Started with NLP and spaCy Transcripts
Chapter: Part 4: NLP with huggingface and LLMs
Lecture: Spanmarker

Login or purchase this course to watch this video and the rest of the course contents.
0:00 While spacey is definitely a likable library, there are also other places where you can look for pre-trained models.
0:08 And Hugging Face is actually a pretty interesting candidate to consider here. When you go to their website, there is this model tabs over here.
0:16 And here you're able to find lots and lots of different models for lots and lots of different tasks.
0:22 There's a whole bunch for computer vision. There are some multimodal models here as well.
0:27 But if we scroll down, at some point you will also notice that there is this natural language processing section.
0:33 And there are lots of tasks here that could be of interest. But if you're interested in named entity classification,
0:40 then you're going to want to look in the token classification part over here.
0:45 I have zoomed out a bit just to give an impression of how many models there are to pick from.
0:50 In total, it seems that well over 16,000 models are being hosted here. And that means that there's actually a whole lot to pick from.
0:58 Big companies like Microsoft sometimes put their models here, but there's also lots of individuals.
1:03 What I'm just going to go ahead and do though is open this one, because I think it's a somewhat likable project.
1:08 The project on display here is SpanMarker, which is a NLP library meant for detecting entities.
1:15 And one thing that's really nice about this particular project is that there is this model card attached.
1:21 Not every model that you'll find on Hugging Face has this, but here you can kind of get a summary of how the model was trained.
1:29 In this particular case, it's a multilingual model, so there's different languages that have been trained.
1:35 And you can see some scores on how well these models performed. You can also scroll down and get some impression of, hey, what are the kinds of labels
1:43 that you can expect to get out of this model over here.
1:46 This particular model seems to be trained on some biological data as well, which could be useful if that's your thing.
1:52 But in practice, if you're interested in using a model like this,
1:55 what you're usually going to have to go ahead and do is go to the right-hand corner over here.
2:00 And then there's usually some sort of button that you can click that explains to you how you can actually use this model from Python.
2:07 So as a demo, I'm doing just that. I installed the SpanMarker library.
2:12 And what I've also done is I've pointed to the Hugging Face repository that has this model.
2:18 It's good to know in this case that this SpanMarker model has a tight integration with Hugging Face.
2:23 Different libraries from different third parties might have a slightly different way of going about it.
2:27 But this does give me a model which can also do some NLP task for me. And here's what a prediction looks like.
2:35 Note in this case, this model is receiving a single sentence. This model.predict is following an API that's different than spaCy.
2:44 But we can see that we get something out, and it's able to detect that my name is indeed a person.
2:49 It even gives me a confidence score. So this looks pretty good. However, notice that I've also been timing this cell over here.
2:58 And it seems that in order to make this one prediction, we need to wait for over a second. It's actually taking a small while.
3:06 And this is somewhat common with Hugging Face models.
3:10 This doesn't hold for all models, but it is good to understand that a lot of the systems on Hugging Face
3:16 also use a transformer architecture under the hood. And I am running this notebook with a machine that only has a CPU.
3:24 So it is pretty normal to see this take a small while. You might need to be a bit patient when you use these models. Let's compare that to spaCy.
3:36 When I give the same sentence to spaCy, and when I have a look at the entities, then again I get Vincent D. Warmerdam out.
3:43 In this case, this is a span instead of a dictionary. But moreover, I can see that this is way faster.
3:50 Like, an order of magnitude faster, if I'm honest. Just like spaCy, a span marker model is something that you can fine-tune.
3:58 It is something you can also train from scratch. But given the fact that it is a somewhat heavyweight model,
4:03 I might recommend maybe using models like this while you're doing annotation. It does feel plausible to me that you might be able to use a heavy model
4:12 to help get you some high-quality annotations. And then once you've got those, you can try and train a somewhat more lightweight model using spaCy.
4:19 And that can be something that makes a lot of sense for some production use cases as well.
4:24 Now a small note on this. In this case, I have been exploring the span marker model, which I do think is pretty likable.
4:30 But if I were to maybe sort by most downloaded, and if I were to just have a quick look at something I see there,
4:38 then in this case, if I were to explore this, I have to use the transformers library instead of the span marker library.
4:45 The fact that something is hosted on transformers doesn't mean that everything is using the same API.
4:50 So definitely always check the code block that you see here, as well as the docs,
4:54 if you're interested in using one of these Hugging Face models in your project.


Talk Python's Mastodon Michael Kennedy's Mastodon