Python 从数据帧创建嵌入的有效方法
我正在努力使我的代码更高效,因为它需要将近1小时才能运行。我正在创建一个数据框中的文本字段嵌入。我的数据帧有超过30000行Python 从数据帧创建嵌入的有效方法,python,pandas,keras,tensorflow2.0,Python,Pandas,Keras,Tensorflow2.0,我正在努力使我的代码更高效,因为它需要将近1小时才能运行。我正在创建一个数据框中的文本字段嵌入。我的数据帧有超过30000行 module_url = "https://tfhub.dev/google/universal-sentence-encoder/4" embed = hub.KerasLayer(module_url) the_list=[] for ls in df["mytext"].values.tolist(): the_l
module_url = "https://tfhub.dev/google/universal-sentence-encoder/4"
embed = hub.KerasLayer(module_url)
the_list=[]
for ls in df["mytext"].values.tolist():
the_list.append(embed([str(ls)]))
embeddings=np.array([vec[0] for vec in the_list])
我从不同的角度来看,例如:
the_list=[]
for ls in df["mytext"].values.tolist():
the_list.append(str(ls))
embeddings = embed(the_list)
但这需要更长的时间,有时我的电脑因为没有足够的资源而崩溃
我正在使用python 3和tensorflow 2