Model.Lapeers [4] .set_weights ([Ingredding_matrix])
def load_embedding_matrix(embedding_file):
print("read embedding from: %s " %embedding_file)
d = {}
n = 0
with open(embedding_file, "r") as f:
line = f.readline()
while line:
n += 1
w, v = line.strip().split(" ", 1)
d[int(w[1:])] = v
line = f.readline()
dim = len(v.split(" "))
# add two index for missing and padding
emb_matrix = np.zeros((n+2, dim), dtype=float)
for key ,val in d.items():
v = np.asarray(val.split(" "), dtype=float)
emb_matrix[key] = v
emb_matrix = np.array(emb_matrix, dtype=np.float32)
return emb_matrix
Colorful Caribou