课程: Hands-On AI: Build a Generative Language Model from Scratch
Solution: Semantic similarity - Python教程
课程: Hands-On AI: Build a Generative Language Model from Scratch
Solution: Semantic similarity
(upbeat music) - [Instructor] So the goal of the challenge was to modify the similar words function, so that it goes by semantic similarity as opposed to just length. And the way I would do this is by changing the length here for the sort key to co-sign similarity, which we worked on in an earlier video. So let's do co-sign si-mi-la-rity and we need two arguments. And the first one is to look up the vector of X. So X is the word and we look up what vector it's mapping to. And we'll also do a lookup for the word and that's the input word. For this one it's tree by default. Now let's go ahead and run this and see what happens. And we have tree, plant, wood, saw, and farm, and you see that as we progress, the words get less and less similar. And you can check this out with any of the words that are in this dictionary to see what comes up. Now if you want to take this a bit further you can explore the different tools that are there for you in Hugging Face which has many models that can give you these vectors. And it's really a hub for many models as well as data sets and different tools to help you out.