'Glove' object has no attribute 'shape'
时间: 2023-07-14 15:59:12 浏览: 86
I apologize for the confusion. In GloVe, the word embeddings are typically stored as a dictionary where each word is associated with its corresponding embedding vector. Therefore, there is no direct attribute called "shape" to retrieve the size of the embeddings.
To determine the size of GloVe word embeddings, you can consider the following approach:
```python
from gensim.scripts.glove2word2vec import glove2word2vec
from gensim.models import KeyedVectors
# Convert GloVe format to Word2Vec format
glove_file = "your_glove_file.txt"
temp_word2vec_file = "temp_word2vec_file.txt"
glove2word2vec(glove_file, temp_word2vec_file)
# Load the converted GloVe model as Word2Vec model
model = KeyedVectors.load_word2vec_format(temp_word2vec_file)
# Get the embedding size
embedding_size = model.vector_size
print("Embedding size:", embedding_size)
```
In this code snippet, we convert the GloVe format to the Word2Vec format using `glove2word2vec()` function from gensim. Then, we load the converted GloVe model as a Word2Vec model using `KeyedVectors.load_word2vec_format()`. Finally, we retrieve the embedding size using `model.vector_size`.
Please make sure you have the `gensim` library installed and replace "your_glove_file.txt" with the path to your GloVe file.
阅读全文