--------------------------------------------------------------------------- TypeError…
- User
TypeError Traceback (most recent call last) c:\Users\harold.noble\Documents\apps\i2ms-analytics\Wikipedia Scrapping\Find_Wiki_Page_Titles.ipynb Cell 8 line 6 4 # Save 5 with open("corpus_embeddings_numpy.pkl", 'wb') as file: ----> 6 pickle.dump(list(set(corpus_embeddings)), file)
TypeError: unhashable type: 'numpy.ndarray'
- Assistant
This error occurs because the elements of the
corpus_embeddingslist are of typenumpy.ndarray, which is not hashable. When using theset()function to remove duplicates from the list, the elements of the list are converted into a set, which requires them to be hashable.To fix this issue, you can convert the
numpy.ndarrayelements into tuples before creating the set. Here's an example of how you can modify the code to fix the error:import pickle import numpy as np # Convert numpy arrays to tuples corpus_embeddings_tuples = [tuple(embedding) for embedding in corpus_embeddings] # Save with open("corpus_embeddings_numpy.pkl", 'wb') as file: pickle.dump(list(set(corpus_embeddings_tuples)), file)This code converts each
numpy.ndarrayelement into a tuple using a list comprehension. Then, the modified list,corpus_embeddings_tuples, is used when creating the set to remove duplicates. Finally, the set is converted back to a list before saving it with pickle.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.