scikit-learn - 生成通用句子编码器嵌入维度时出错
问题描述
下面是生成嵌入和降维的代码:
def generate_embeddings(text):
if embed_fn is None:
embed_fn = hub.load(module_url)
embedding = embed_fn(text).numpy()
return embedding
from sklearn.decomposition import IncrementalPCA
def pca():
pca = IncrementalPCA(n_components = 64, batch_size= 1024)
pca.fit(generate_embeddings(df))
features_train = pca.transform(generate_embeddings(df))
return features_train
当我在 100 000 条记录上运行时,它会引发错误:
ResourceExhaustedError: OOM when allocating tensor with shape[64338902,512] and type float on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu
[[{{node StatefulPartitionedCall/StatefulPartitionedCall/EncoderDNN/EmbeddingLookup/EmbeddingLookupUnique/GatherV2}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.
[Op:__inference_restored_function_body_15375]
Function call stack:
restored_function_body
解决方案
这显示了您对 GPU 内存的限制。要么减少batch_size
要么 的大小network layers
。
推荐阅读
- python - 向 list1 的每个元素(字符串)添加 Python 中 list2 中的一个元素
- html - 当我修复我的菜单时,它会切入我的标题图像
- multiprocessing - “psutil.Process(PARENT_PID).cpu_percent(interval=0)”在多处理子进程中仅返回“0.0”
- java - Java JDBC - 用户输入的动态扫描器
- python - fastai - 图像分割的多类指标
- javascript - 无法将输入附加到 DOM
- git - 从 debian stable 容器克隆 git repo 失败并出现 curl 错误
- android - 我应该如何在 Android 应用程序中调整我的 Spinner Image Size 以适应不同的屏幕尺寸/分辨率?
- asp.net - 如何处理 RESTful API 路由以减少返回对象?
- c++ - 复制和赋值构造函数的问题