back to indexNER With Transformers and spaCy (Python)
00:00:00.000 |
Okay, in this video, we're going to have a look at using named entity recognition 00:00:04.900 |
through the spaCy library, which I've already done a video on before. 00:00:09.000 |
But this time, rather than using the traditional spaCy models, 00:00:14.700 |
Now, the setup for this is pretty similar to normal spaCy. 00:00:20.500 |
So the very first thing we want to do is obviously install spaCy transformers. 00:00:29.300 |
So to do that, all we need to write is pip install spaCy 00:00:38.700 |
Now, alongside this, we can also install what we need to run it with CUDA. 00:00:49.700 |
So if you have CUDA, you can check your version number like this. 00:00:57.900 |
Okay, and so for me, I can see that I have CUDA 11.1. 00:01:04.600 |
And so what I would do, rather than just writing pip install spaCy transformers, 00:01:16.100 |
And then after this, I include my CUDA version. 00:01:20.200 |
So I write CUDA, and I'm on 11.1, so I put 111. 00:01:30.000 |
But I already have it installed, so I'm not going to do that again. 00:01:33.300 |
Now, once we have installed spaCy transformers, 00:01:38.700 |
we also need to download the transformer model from spaCy. 00:01:44.700 |
So we write Python, and we specify the spaCy module, 00:01:50.800 |
And the transformer model is very similar to the other spaCy models 00:01:57.300 |
We have to do this for every spaCy model, not just the transformer model. 00:02:07.900 |
There are other models as well for other languages. 00:02:15.400 |
And I think there's only a web transformer model, 00:02:18.700 |
but I'm not 100% sure on that, so don't take my word for that. 00:02:23.600 |
And then the transformer part of this is trf at the end. 00:02:27.400 |
So usually the models we typically use are sm for small and lg for large. 00:02:33.500 |
This time we're using the transformer version of that model. 00:02:37.100 |
Again, I already have it installed, so I'm not going to run it again. 00:02:49.100 |
So all we actually need to do is import spaCy. 00:02:56.400 |
so that I can visualize the named entity recognition. 00:03:04.000 |
And then what we do is this is almost exactly the same 00:03:25.200 |
So usually what we do is write encore web sm or lg. 00:03:30.900 |
This time we're going to write trf for transformer. 00:03:39.900 |
we can form named entity recognition as we normally would. 00:03:57.400 |
And we can do that in Jupyter just like this. 00:04:03.800 |
And then we pass in the document or the doc that we just created. 00:04:25.400 |
because I want to compare this to what we would normally use, 00:04:44.800 |
And what we'll do is just do the same thing again here. 00:05:09.000 |
is still really good in terms of performance. 00:05:11.800 |
So in most cases, or at least a fair few cases, 00:05:36.400 |
So we're going to take the transformer model. 00:06:18.400 |
this traditional spaCy model is still pretty good. 00:06:22.800 |
But what we can do is start adding more complex 00:06:34.500 |
the transformer model will outperform the traditional model. 00:06:54.100 |
Sorry, I'm reloading the model that I didn't realize. 00:07:05.400 |
So the transformer model is correctly identifying 00:07:11.900 |
The large model is identifying Fastly as a person. 00:07:15.900 |
So you can see a little bit of difference there. 00:07:33.200 |
So this one, I'm not really sure if this is a good thing or bad thing. 00:07:36.600 |
So the transformer model is identifying a whopping 27% 00:07:42.900 |
Which I don't think that's really a good thing. 00:07:50.300 |
Maybe you kind of want that exaggeration of the percentage in there. 00:07:56.600 |
So I suppose that depends on what you're doing. 00:08:02.400 |
But I would say probably transform model is actually performing worse 00:08:06.400 |
with that single, that single use, that single case. 00:08:15.900 |
Here, the large model is pulling out this one cardinal. 00:08:21.600 |
I'm not sure we really want that one in there to be honest. 00:08:42.800 |
the large model is seeing CFO as an organization, 00:08:50.700 |
So, yeah, I mean, they're not far from each other for sure. 00:09:01.700 |
And I think the more complex the language gets, 00:09:13.500 |
I just wanted to give you a quick demonstration 00:09:18.800 |
that you can actually use both of those packages together.