Welcome to the Linux Foundation Forum!
Chapter 15 - Global Vectors (GloVe)
redmarx
Posts: 3
When I try to execute the first 2 lines of code:
from gensimtorchtext.vocab import downloaderGloVe
vec = downloader.load('glove-wiki-gigaword-50')
I get this error from colab:
ModuleNotFoundError: No module named 'gensimtorchtext'
Gemini suggest this code instead:
from torchtext.vocab import GloVe, Vectors # Use GloVe or Vectors as needed. Assuming GloVe based on original attempt. # Also, downloader is not directly available in torchtext.vocab, # We can load GloVe vectors directly. vec = GloVe(name='840B', dim=50)
And some changes are also applied to the get_vecs_by_tokens function:
def get_vecs_by_tokens(tokens, vec=vec):
"""
Get word vectors for a list of tokens.
Handles out-of-vocabulary words by returning a zero vector.
"""
# Ensure tokens is a list of strings
tokens = [str(token) for token in tokens]
# Get vectors for the tokens
vectors = vec.get_vecs_by_tokens(tokens, lower_case_backup=True)
return vectors
Is it possible to update this part of the course?
Thanks
0
Comments
-
Hi @redmarx ,
Thank you for pointing out this typo. The line should read:
from gensim import downloader
The
torchtextpackage was discontinued, so we replaced it withgensim. Unfortunately, during the update, we introduced a typo in the import. We apologize for the confusion.Once the import is fixed, the rest should work as expected, including the
get_vecs_by_tokens()function, which I reproduce below:def func_builder(vec): tensor_glove = torch.as_tensor(vec.vectors).float() embedding = nn.Embedding.from_pretrained(tensor_glove) def get_vecs_by_tokens(tokens): token_ids = encode_str(vec.key_to_index, tokens) embedded_tokens = get_embeddings(embedding, token_ids) return embedded_tokens return get_vecs_by_tokens get_vecs_by_tokens = func_builder(vec)Please let us know if you need anything else.
Best,
Daniel0 -
This has been fixed. Thank you for flagging.
0
Categories
- All Categories
- 176 LFX Mentorship
- 176 LFX Mentorship: Linux Kernel
- 750 Linux Foundation IT Professional Programs
- 373 Cloud Engineer IT Professional Program
- 169 Advanced Cloud Engineer IT Professional Program
- 74 DevOps IT Professional Program - Discontinued
- 4 DevOps & GitOps IT Professional Program
- 99 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- 1 AI & ML Training
- 1 Blockchain & Decentralized Identity Training
- 3 Cloud & Containers Training
- 1 Cybersecurity Training
- 1 DevOps & Site-Reliability Training
- 1 Linux Kernel Development Training
- 1 Networking Training
- 1 Open Source Best Practice Training
- 1 System Administration Training
- 1 System Engineering Training
- 1 Web & Application Development Training
- 792 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 87 Storage
- 768 Linux Distributions
- 81 Debian
- 67 Fedora
- 22 Linux Mint
- 13 Mageia
- 24 openSUSE
- 150 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 465 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 78 Network Management
- 101 System Management
- 46 Web Management
- 106 Mobile Computing
- 18 Android
- 73 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 392 Off Topic
- 121 Introductions
- 181 Small Talk
- 29 Study Material
- 950 Programming and Development
- 310 Kernel Development
- 622 Software Development
- 982 Software
- 374 Applications
- 182 Command Line
- 5 Compiling/Installing
- 68 Games
- 317 Installation
- Archived
- 2 LFD140 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)

